This repository contains workflows for training Neural Machine Translation (NMT) models using Fairseq. It covers data preparation, preprocessing, model training, evaluation, and backtranslation to improve translation quality.
- Clone and install Fairseq
- Ensure your environment has GPU support
- Install dependencies (PyTorch, SacreBLEU, etc.)
- Configure Google Drive mounting if working in Colab
-
Parallel Corpora
- Use official WMT parallel datasets (e.g., WMT18 English–German).
- Preprocess with
fairseq-preprocessusing a shared dictionary. - Save artifacts into
data-bin/.
-
Scripts Management
- Custom scripts (e.g.,
prepare-wmt18en2de.sh,sacrebleu.sh) are copied between Google Drive and the working directory to ensure persistence.
- Custom scripts (e.g.,
-
Train Transformer-based models (
transformer_wmt_en_de) using parallel corpora. -
Key hyperparameters:
- Label smoothing: 0.1
- Adam optimizer (
betas=(0.9, 0.98)) - Inverse square root learning rate scheduler
- Max tokens: 3584
- Gradient accumulation (
--update-freq 16)
-
Mixed precision training (
--fp16) for efficiency. -
Training progress and checkpoints are stored in
checkpoints_*directories.
- Translation quality is evaluated with SacreBLEU.
- Example evaluation datasets: WMT17, WMT08/Europarl.
- BLEU scores are logged for model comparison.
Backtranslation is used to leverage monolingual data to improve translation quality.
- Preprocess WMT18 En–De dataset.
- Train an intermediate De→En model on the parallel corpus.
- Evaluate the intermediate model with SacreBLEU.
- Collect large-scale German-only monolingual data.
- Preprocess the data in shards for efficiency (
shard00–shard24). - Align dictionaries with the parallel dataset.
-
Use the trained De→En model to backtranslate German monolingual data into English.
-
Two strategies:
- Beam search (
--beam 5) → high-quality translations. - Top-k sampling (
--sampling-topk 10) → diverse translations.
- Beam search (
-
Save results in
backtranslation_output/.
-
Use
extract_bt_data.pyto filter synthetic sentence pairs. -
Combine synthetic parallel data with original WMT18 parallel corpus:
wmt18_en_de_para_plus_bt_beamwmt18_en_de_para_plus_bt_top10
-
Train En→De models on the combined dataset.
-
Two training settings:
- Beam backtranslation model (
checkpoints_en_de_parallel_bt_beam) - Top-10 sampling backtranslation model (
checkpoints_en_de_parallel_bt_top10)
- Beam backtranslation model (
-
Upsampling ensures the parallel dataset is not overwhelmed by synthetic data (
--upsample-primary 1).
- Evaluate trained models with SacreBLEU.
- Compare parallel-only vs parallel+BT models.
- Expect improved BLEU scores due to the additional synthetic training data.
checkpoints_de_en_parallel→ Intermediate De→En modelbacktranslation_output_beam/backtranslation_output_top10→ Synthetic translationscheckpoints_en_de_parallel_bt_*→ Final En→De models trained with backtranslation
- Fairseq Documentation
- SacreBLEU
- Edunov et al. (2018). Understanding Back-Translation at Scale.