forked from OpenNMT/OpenNMT-py
-
Notifications
You must be signed in to change notification settings - Fork 0
378 lines (373 loc) · 12.6 KB
/
push.yml
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: Lint & Tests
on: [push, pull_request]
jobs:
lint-and-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6] # build only for 3.6 for now
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools
pip install -e .
pip install -r requirements.opt.txt
pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --statistics
- name: Unit tests
run: |
python -m unittest discover
- name: Test vocabulary build
run: |
python onmt/bin/build_vocab.py \
-config data/data.yaml \
-save_data /tmp/onmt \
-n_sample 5000 \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
&& rm -rf /tmp/sample
- name: Test field/transform dump
run: |
# The dumped fields are used later when testing tools
python train.py \
-config data/data.yaml \
-save_data /tmp/onmt.train.check \
-dump_fields \
-dump_transforms \
-n_sample 30 \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000
- name: Test RNN training
run: |
python train.py \
-config data/data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-rnn_size 2 \
-batch_size 10 \
-word_vec_size 5 \
-report_every 5\
-rnn_size 10 \
-train_steps 10
- name: Test RNN training with copy
run: |
python train.py \
-config data/data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-rnn_size 2 \
-batch_size 10 \
-word_vec_size 5 \
-report_every 5 \
-rnn_size 10 \
-train_steps 10 \
-copy_attn
- name: Test RNN training with coverage
run: |
python train.py \
-config data/data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-rnn_size 2 -batch_size 10 \
-word_vec_size 5 -report_every 5 \
-coverage_attn true -lambda_coverage 0.1 \
-rnn_size 10 -train_steps 10
- name: Test Transformer training with align
run: |
python train.py \
-config data/align_data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-max_generator_batches 0 \
-encoder_type transformer \
-decoder_type transformer \
-layers 4 \
-word_vec_size 16 \
-rnn_size 16 \
-heads 2 \
-transformer_ff 64 \
-lambda_align 0.05 \
-alignment_layer 2 \
-alignment_heads 0 \
-report_every 5 \
-train_steps 10
- name: Test LM training
run: |
python train.py \
-config data/lm_data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.src \
-model_task lm \
-encoder_type transformer_lm \
-decoder_type transformer_lm \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-dec_layers 2 -batch_size 10 \
-heads 4 -transformer_ff 64 \
-word_vec_size 16 -report_every 5 \
-rnn_size 16 -train_steps 10
- name: Test LM training with copy
run: |
python train.py \
-config data/lm_data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.src \
-model_task lm \
-encoder_type transformer_lm \
-decoder_type transformer_lm \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-dec_layers 2 -batch_size 10 \
-heads 4 -transformer_ff 64 \
-word_vec_size 16 -report_every 5 \
-rnn_size 16 -train_steps 10 \
-copy_attn
- name: Test Graph neural network training
run: |
python train.py \
-config data/ggnn_data.yaml \
-src_seq_length 1000 \
-tgt_seq_length 30 \
-encoder_type ggnn \
-layers 2 \
-decoder_type rnn \
-rnn_size 256 \
-learning_rate 0.1 \
-learning_rate_decay 0.8 \
-global_attention general \
-batch_size 32 \
-word_vec_size 256 \
-bridge \
-train_steps 10 \
-n_edge_types 9 \
-state_dim 256 \
-n_steps 10 \
-n_node 64
- name: Test RNN translation
run: |
head data/src-test.txt > /tmp/src-test.txt
python translate.py \
-model onmt/tests/test_model.pt \
-src /tmp/src-test.txt \
-verbose
- name: Test RNN ensemble translation
run: |
head data/src-test.txt > /tmp/src-test.txt
python translate.py \
-model onmt/tests/test_model.pt \
onmt/tests/test_model.pt \
-src /tmp/src-test.txt \
-verbose
- name: Test RNN translation with beam search
run: |
python translate.py \
-model onmt/tests/test_model2.pt \
-src data/morph/src.valid \
-verbose \
-batch_size 10 \
-beam_size 10 \
-tgt data/morph/tgt.valid \
-out /tmp/trans
diff data/morph/tgt.valid /tmp/trans && rm /tmp/trans
- name: Test RNN translation with random sampling
run: |
python translate.py \
-model onmt/tests/test_model2.pt \
-src data/morph/src.valid \
-verbose \
-batch_size 10 \
-beam_size 1 \
-seed 1 \
-random_sampling_topk "-1" \
-random_sampling_temp 0.0001 \
-tgt data/morph/tgt.valid \
-out /tmp/trans
diff data/morph/tgt.valid /tmp/trans && rm /tmp/trans
- name: Test LM generation
run: |
head data/src-test.txt > /tmp/src-test.txt
python translate.py \
-model onmt/tests/test_model_lm.pt \
-src data/src-test.txt \
-verbose
- name: Test LM generation with beam search
run: |
python translate.py \
-model onmt/tests/test_model_lm.pt \
-src data/data_lm/src-gen.txt \
-verbose -batch_size 10 \
-beam_size 10 \
-ban_unk_token \
-out /tmp/gen
diff data/data_lm/gen-beam-sol.txt /tmp/gen && rm /tmp/gen
- name: Test LM generation with random sampling
run: |
python translate.py -model onmt/tests/test_model_lm.pt \
-src data/data_lm/src-gen.txt \
-verbose -batch_size 10 \
-beam_size 1 \
-seed 1 \
-random_sampling_topk -1 \
-random_sampling_temp 0.0001 \
-ban_unk_token \
-out /tmp/gen
diff data/data_lm/gen-sampling-sol.txt /tmp/gen && rm /tmp/gen
- name: Test LM generation with random top-k/nucleus sampling
run: |
python translate.py -model onmt/tests/test_model_lm.pt \
-src data/data_lm/src-gen.txt \
-verbose -batch_size 10 \
-beam_size 1 \
-seed 3 \
-random_sampling_topk -1 \
-random_sampling_topp 0.95 \
-random_sampling_temp 1 \
-ban_unk_token \
-out /tmp/gen
diff data/data_lm/gen-nucleus-sampling-sol.txt /tmp/gen && rm /tmp/gen
- name: Test LM generation with random sampling multi-beams
run: |
python translate.py -model onmt/tests/test_model_lm.pt \
-src data/data_lm/src-gen.txt \
-verbose -batch_size 10 \
-beam_size 10 \
-seed 1 \
-random_sampling_topk 50 \
-random_sampling_topp 0.95 \
-random_sampling_temp 1 \
-length_penalty avg \
-ban_unk_token \
-min_length 5 \
-out /tmp/gen
diff data/data_lm/gen-sampling-beams-sol.txt /tmp/gen && rm /tmp/gen
- name: Test extract_vocabulary tool
run: |
python tools/extract_vocabulary.py \
-file /tmp/onmt.train.check.vocab.pt \
-file_type field \
-side src \
-out_file /tmp/onmt.vocab.txt
if ! wc -l /tmp/onmt.vocab.txt | grep -qF "1002"
then echo "wrong word count" && exit 1
else
echo "create vocabulary pass"
fi
- name: Test embeddings_to_torch tool
run: |
python tools/embeddings_to_torch.py \
-emb_file_enc onmt/tests/sample_glove.txt \
-emb_file_dec onmt/tests/sample_glove.txt \
-dict_file /tmp/onmt.train.check.vocab.pt \
-output_file /tmp/q_gloveembeddings \
&& rm /tmp/q_gloveembeddings*
rm /tmp/onmt.train.check.*.pt
- name: Test extract_embeddings tool
run: |
python tools/extract_embeddings.py \
-model onmt/tests/test_model.pt
- name: Test checkpoint vocabulary update
run: |
python train.py \
-config data/data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-rnn_size 2 \
-batch_size 10 \
-word_vec_size 5 \
-report_every 5\
-rnn_size 10 \
-train_steps 10 \
-save_model /tmp/onmt.model \
-save_checkpoint_steps 10
sed -i '1s/^/new_tok\t100000000\n/' /tmp/onmt.vocab.src
python train.py \
-config data/data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-rnn_size 2 \
-batch_size 10 \
-word_vec_size 5 \
-report_every 5\
-rnn_size 10 \
-train_steps 20 \
-update_vocab \
-reset_optim "states" \
-train_from /tmp/onmt.model_step_10.pt
- name: Test checkpoint vocabulary update with LM
run: |
python train.py \
-config data/lm_data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-model_task lm \
-encoder_type transformer_lm \
-decoder_type transformer_lm \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-dec_layers 2 -batch_size 10 \
-heads 4 -transformer_ff 64 \
-word_vec_size 16 -report_every 5 \
-save_model /tmp/lm.onmt.model \
-save_checkpoint_steps 10 \
-rnn_size 16 -train_steps 10
sed -i '1s/^/new_tok\t100000000\n/' /tmp/onmt.vocab.src
python train.py \
-config data/lm_data.yaml \
-src_vocab /tmp/onmt.vocab.src \
-tgt_vocab /tmp/onmt.vocab.tgt \
-model_task lm \
-encoder_type transformer_lm \
-decoder_type transformer_lm \
-src_vocab_size 1000 \
-tgt_vocab_size 1000 \
-dec_layers 2 -batch_size 10 \
-heads 4 -transformer_ff 64 \
-word_vec_size 16 -report_every 5 \
-rnn_size 16 -train_steps 20 \
-update_vocab -reset_optim "states" \
-train_from /tmp/lm.onmt.model_step_10.pt
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools
pip install -e .
pip install -r docs/requirements.txt
- name: Build docs
run: |
set -e
# Check that docs are built without errors
cd docs/ && make html && cd ..