forked from nytimes/ingredient-phrase-tagger
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathdocker_train_prod_model
executable file
·46 lines (34 loc) · 1.04 KB
/
docker_train_prod_model
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Builds a new model within a docker container using production settings.
#
# Example
# $ mkdir ~/models
# $ ./docker_train_prod_model ~/models
# Exit build script on first failure
set -e
# Echo commands to stdout.
set -x
if [ -z "$1" ];
then echo "Usage: ./docker_train_prod_model output_dir" && exit 1;
fi
OUTPUT_DIR="$1"
IMAGE_NAME="ingredient-phrase-tagger-image"
CONTAINER_NAME="ingredient-phrase-tagger-model-builder"
docker version
docker rm -f "$CONTAINER_NAME" || true
docker build \
--tag "$IMAGE_NAME" \
.
docker run \
--tty \
--detach \
--name "$CONTAINER_NAME" \
"$IMAGE_NAME"
DOCKER_MODEL_DIR=/models
docker exec "$CONTAINER_NAME" mkdir "${DOCKER_MODEL_DIR}"
docker exec "$CONTAINER_NAME" bin/train-prod-model "${DOCKER_MODEL_DIR}"
FIND_MODEL_CMD="ls ${DOCKER_MODEL_DIR}/*.crfmodel"
DOCKER_MODEL_PATH=$(docker exec "$CONTAINER_NAME" sh -c "$FIND_MODEL_CMD")
docker cp "${CONTAINER_NAME}:${DOCKER_MODEL_PATH}" "${OUTPUT_DIR}/"
MODEL_FILE="$(ls ${OUTPUT_DIR}/*.crfmodel)"
echo "Trained new model: $MODEL_FILE"