該存儲庫包括針對我們論文中提出的神經機器翻譯的稀有單詞的數據擴展的代碼和腳本。
如果您使用此代碼,請引用:
@InProceedings{fadaee-bisazza-monz:2017:Short2,
author = {Fadaee, Marzieh and Bisazza, Arianna and Monz, Christof},
title = {Data Augmentation for Low-Resource Neural Machine Translation},
booktitle = {Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers)},
month = {July},
year = {2017},
address = {Vancouver, Canada},
publisher = {Association for Computational Linguistics},
pages = {567--573},
url = {http://aclweb.org/anthology/P17-2090}
}
在訓練[SRC/TRG]中的單語言模型之前,您需要使用preprocess.no_preset_v.py來預處理數據。
python src/preprocess.no_preset_v.py --train_txt ./wiki.train.txt
--val_txt ./wiki.val.txt --test_txt ./wiki.test.txt
--output_h5 ./data.h5 --output_json ./data.json
這將產生文件data.h5和data.json ,將傳遞給培訓腳本。
預處理數據後,您需要在向前和向後訓練兩種語言模型。
th src/train.lua -input_h5 data.h5 -input_json data.json
-checkpoint_name models_rnn/cv -vocabfreq vocab_freq.trg.txt
th src/train.lua -input_h5 data.rev.h5 -input_json data.rev.json
-checkpoint_name models_rnn_rev/cv -vocabfreq vocab_freq.trg.txt
您可以使用更多的標誌來配置培訓。
vocabfreq輸入是低資源設置中單詞的頻率列表,以後需要增加這些語言模型。格式是:
...
change 3028
taken 3007
large 2999
again 2994
...
訓練語言模型後,您可以在bitext中生成新句子的[src trg]。您可以運行此:
th src/substitution.lua -checkpoint models_rnn/cv_xxx.t7 -start_text train.en
-vocabfreq vocab_freq.trg.txt -sample 0 -topk 1000 -bwd 0 > train.en.subs
th src/substitution.lua -checkpoint models_rev.rnn/cv_xxx.t7 -start_text train.en.rev
-vocabfreq vocab_freq.trg.txt -sample 0 -topk 1000 -bwd 1 > train.en.rev.subs
start_text是您針對稀有單詞的bitext的一面。 vocabfreq是用於檢測稀有單詞的頻率列表。 topk表示您想對句子中每個位置擁有的最大替換次數。
運行這兩個代碼將為您提供增強的Corpora,並在一側提供替換列表: train.en.subs and train.en.rev.subs 。為了查找最適合上下文的變更,您需要找到這兩個列表的交集:
perl ./scripts/generate_intersect.pl train.en.subs train.en.rev.subs subs.intersect
subs.intersect包含可用於增強bitext的替換。這是輸出的示例:
information where we are successful will be published in this unk .
information{}
where{}
we{doctors:136 humans:135}
are{became:764 remained:245}
successful{}
will{}
be{}
published{interested:728 introduced:604 kept:456 performed:289 placed:615 played:535 released:477 written:790}
in{behind:932 beyond:836}
this{henry:58}
unk{}
.{}
第一行是原始句子,其後的每一行都是句子中的一個單詞,並以各自的頻率進行了替換。
使用替代輸出,bitext的[trg/src]端,對齊方式和詞彙概率文件,您可以生成增強庫。
您可以使用fast_align來獲得bitext的對齊。對齊輸入的格式是:
...
0-0 1-10 2-3 2-4 2-5 3-13 4-14 5-8 5-9 6-16 7-14 8-11 10-6 11-7 12-17
0-0 1-0 2-0 2-2 3-1 3-3 4-5 5-5 6-6 8-8 9-9 10-10 11-11
...
詞彙概率輸入可以從字典或對齊中獲得。格式是:
...
safely sicher 0.0051237409068
safemode safemode 1
safeness antikollisionssystem 0.3333333
safer sicherer 0.09545972221228
...
為了生成可以運行的增強bitext:
perl ./scripts/data_augmentation.pl subs.intersect train.de alignment.txt lex.txt augmentedOutput
這將生成兩個文件:在[src/trg]和augmentedOutput.augmented中以[trg/src]語言augmentedOutput.fillout 。第一個文件是bitext的側面增強針對稀有單詞的側面。第二個文件是增強句子的各個翻譯。
如果您想對每個句子進行多次更改,也可以運行:
perl ./scripts/data_augmentation_multiplechanges.pl subs.intersect train.de alignment.txt lex.txt augmentedOutput
這是[src/trg]中的增強文件中的句子:
at the same time , the rights of consumers began:604~need to be maintained .
和[trg/src]中的filleout文件的各個句子:
gleichzeitig begann~müssen die rechte der verbraucher geschützt werden .
在增強文件中,該單詞以frequncy 604的形式替換為單詞的需求。在摘錄文件中,單詞的翻譯開始,替換為原始單詞穆森。
要刪除所有標記並具有可用於翻譯培訓的干淨bitext:您可以運行:
perl ./scripts/filter_out_augmentations.pl augmentedOutput.en augmentedOutput.de 1000
您可以對要在此處增加的稀有詞施加更多的frequncy限制。
在這項工作中,該代碼被利用: