-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
163 lines (119 loc) · 4.21 KB
/
Makefile
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
.DEFAULT_GOAL := all
# Determine OS (from https://gist.github.com/sighingnow/deee806603ec9274fd47)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSFLAG := linux
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG := macosx
endif
#
# Set file and version for embeddings and model, plus local paths
#
NAME := deep_reference_parser
EMBEDDING_PATH := embeddings
WORD_EMBEDDING := 2020.1.1-wellcome-embeddings-300
WORD_EMBEDDING_TEST := 2020.1.1-wellcome-embeddings-10-test
MODEL_PATH := models
MODEL_VERSION := multitask/2020.4.5_multitask
#
# S3 Bucket
#
S3_BUCKET := s3://datalabs-public/deep_reference_parser
S3_BUCKET_HTTP := https://datalabs-public.s3.eu-west-2.amazonaws.com/deep_reference_parser
#
# Create a virtualenv for local dev
#
VIRTUALENV := build/virtualenv
$(VIRTUALENV)/.installed: requirements.txt
@if [ -d $(VIRTUALENV) ]; then rm -rf $(VIRTUALENV); fi
@mkdir -p $(VIRTUALENV)
virtualenv --python python3 $(VIRTUALENV)
$(VIRTUALENV)/bin/pip3 install -r requirements.txt
$(VIRTUALENV)/bin/pip3 install -r requirements_test.txt
$(VIRTUALENV)/bin/pip3 install -e .
touch $@
$(VIRTUALENV)/.en_core_web_sm:
$(VIRTUALENV)/bin/python -m spacy download en_core_web_sm
touch $@
.PHONY: virtualenv
virtualenv: $(VIRTUALENV)/.installed $(VIRTUALENV)/.en_core_web_sm
#
# Get the word embedding
#
# Set the tar.gz as intermediate so it will be removed automatically
.INTERMEDIATE: $(EMBEDDINGS_PATH)/$(WORD_EMBEDDING).tar.gz
$(EMBEDDING_PATH)/$(WORD_EMBEDDING).tar.gz:
@mkdir -p $(@D)
curl $(S3_BUCKET_HTTP)/embeddings/$(@F) --output $@
$(EMBEDDING_PATH)/$(WORD_EMBEDDING).txt: $(EMBEDDING_PATH)/$(WORD_EMBEDDING).tar.gz
tar -zxvf $< vectors.txt
tail -n +2 vectors.txt > $@
rm vectors.txt
embeddings: $(EMBEDDING_PATH)/$(WORD_EMBEDDING).txt
#
# Get the model artefacts and weights
#
artefact_targets = char2ind.pickle ind2label.pickle ind2word.pickle \
label2ind.pickle maxes.pickle word2ind.pickle \
weights.h5
artefacts = $(addprefix $(MODEL_PATH)/$(MODEL_VERSION)/, $(artefact_targets))
$(artefacts):
@mkdir -p $(@D)
aws s3 cp $(S3_BUCKET)/models/$(MODEL_VERSION)/$(@F) $@
models: $(artefacts)
datasets = data/splitting/2019.12.0_splitting_train.tsv \
data/splitting/2019.12.0_splitting_test.tsv \
data/splitting/2019.12.0_splitting_valid.tsv \
data/parsing/2020.3.2_parsing_train.tsv \
data/parsing/2020.3.2_parsing_test.tsv \
data/parsing/2020.3.2_parsing_valid.tsv \
data/multitask/2020.3.18_multitask_train.tsv \
data/multitask/2020.3.18_multitask_test.tsv \
data/multitask/2020.3.18_multitask_valid.tsv
rodrigues_datasets = data/rodrigues/clean_train.txt \
data/rodrigues/clean_test.txt \
data/rodrigues/clean_valid.txt
RODRIGUES_DATA_URL = https://github.com/dhlab-epfl/LinkedBooksDeepReferenceParsing/raw/master/dataset/
$(datasets):
@ mkdir -p $(@D)
curl -s $(S3_BUCKET_HTTP)/$@ --output $@
$(rodrigues_datasets):
@ mkdir -p data/rodrigues
curl -sL $(RODRIGUES_DATA_URL)/$(@F) --output $@
data: $(datasets) $(rodrigues_datasets)
#
# Add model artefacts to s3
#
sync_model_to_s3:
aws s3 sync --acl public-read $(MODEL_PATH)/$(MODEL_VERSION) \
$(S3_BUCKET)/models/$(MODEL_VERSION)
#
# Ship a new wheel to public s3 bucket, containing model weights
#
# Ship the wheel to the datalabs-public s3 bucket. Need to remove these build
# artefacts otherwise they can make a mess of your build! Public access to
# the wheel is granted with the --acl public-read flag.
.PHONY: dist
dist:
-rm build/lib build/bin build/bdist.$(OSFLAG)* -r
-rm deep_reference_parser-20* -r
-rm deep_reference_parser.egg-info -r
-rm dist/*
$(VIRTUALENV)/bin/python3 setup.py sdist bdist_wheel
aws s3 cp --recursive --exclude "*" --include "*.whl" --acl public-read dist/ $(S3_BUCKET)
#
# Tests
#
$(EMBEDDING_PATH)/$(WORD_EMBEDDING_TEST).txt:
@mkdir -p $(@D)
curl $(S3_BUCKET_HTTP)/embeddings/$(@F) --output $@
test_embedding: $(EMBEDDING_PATH)/$(WORD_EMBEDDING_TEST).txt
test_artefacts = $(addprefix $(MODEL_PATH)/test/, $(artefact_targets))
$(test_artefacts):
@mkdir -p $(@D)
curl $(S3_BUCKET_HTTP)/models/test/$(@F) --output $@
.PHONY: test
test: $(test_artefacts) test_embedding
$(VIRTUALENV)/bin/tox
all: virtualenv model embedding test