fairseq icon indicating copy to clipboard operation
fairseq copied to clipboard

Example of multilingual translation

Open xu3kev opened this issue 7 years ago • 2 comments

There is the multilingual_translation task support. It would be very helpful if there is an simple example of multilingual translation script includes how to do data preprocessing and evaluation so we can try it. Thanks!

xu3kev avatar Feb 11 '19 15:02 xu3kev

For the preprocessing, you can use the same commands in the documentation for each language pair, for example:

fairseq-preprocess --source-lang de --target-lang en
--trainpref $TEXT/train --validpref $TEXT/valid --testpref $TEXT/test
--destdir data-bin/ then you execute the same command for the second language pair:

fairseq-preprocess --source-lang it --target-lang en
--trainpref $TEXT/train --validpref $TEXT/valid --testpref $TEXT/test
--destdir data-bin/

As for the training, here is a sample command that I used: python train.py \raw-data\data-bin --task multilingual_translation --criterion label_smoothed_cross_entropy --arch multilingual_transformer --max-epoch 26 --lr 1.0 --wd 0.5 --lang-pairs de-en,it-en --encoder-layers 2 --decoder-layers 2 --save-dir data\checkpoints --optimizer sgd

Inference: fairseq-interactive \raw-data\data-bin --task multilingual_translation --source-lang it --target-lang en --path \checkpoints\checkpoint20.pt --input \raw-data\test.it --beam 5

For the inference however, I am stuck at this error: Traceback (most recent call last):

File "c:...\lib\site-packages\fairseq_cli\interactive.py", line 82, in main args.path.split(':'), task, model_arg_overrides=eval(args.model_overrides), File "c:...\lib\site-packages\fairseq\utils.py", line 164, in load_ensemble_for_inference model = task.build_model(args) File "c:...\lib\site-packages\fairseq\tasks\multilingual_translation.py", line 180, in build_model model = models.build_model(args, self) File "c:...\lib\site-packages\fairseq\models_init_.py", line 33, in build_model return ARCH_MODEL_REGISTRY[args.arch].build_model(args, task) File "c:....\lib\site-packages\fairseq\models\multilingual_transformer.py", line 162, in build_model encoders[lang_pair] = shared_encoder if shared_encoder is not None else get_encoder(src) File "c:.....\lib\site-packages\fairseq\models\multilingual_transformer.py", line 137, in get_encoder task.dicts[lang], args.encoder_embed_dim, args.encoder_embed_path KeyError: 'de'

It seems like it requires the second source language (de), but I really don't know why, and how to solve this. I hope someone tells me what I am missing.

AyaNsar avatar Feb 12 '19 00:02 AyaNsar

I've added an example here: https://github.com/pytorch/fairseq/pull/527. We've also removed the requirement for putting the second source language.

myleott avatar Feb 26 '19 00:02 myleott