Backtranslation for Domain Adaptation in Neural Machine Translation
Jupyter Notebook
0
63 commits
updated Jun 1, 2025
This repository contains a comprehensive pipeline for neural machine translation research, specifically focusing on Russian-English translation using various backtranslation techniques, data augmentation methods, and quality assessment tools. The pipeline supports both traditional machine translation models and large language models (LLMs) for backtranslation generation.
The research pipeline is designed to:
📝 Note: Each script in this repository contains detailed documentation and instructions within the file itself. Please refer to the docstrings and comments in each script for additional implementation details, parameter explanations, and usage examples.
pip install -r requirements.txt
Set your Hugging Face token in each script or as an environment variable:
export HF_TOKEN='your_huggingface_token_here'
File: dataset_size.py
Calculate the number of examples in various datasets to understand data availability.
python dataset_size.py
Purpose:
Outputs: Console display of dataset sizes in tabular format
This section lists all the datasets available in the pipeline, organized by category. These datasets can be used for training, evaluation, and analysis across all pipeline components.
Original Human-Translated Datasets:
sethjsa/medline_en_ru_parallel - Medical parallel corpus (Medline)sethjsa/scipar_en_ru_parallel - Scientific paper abstracts parallel corpusBasic Backtranslation Datasets:
giannhskp/scipar_ru_en_backtranslation - SciPar RU→EN backtranslationgiannhskp/medline-parallel_ru_en_backtranslation - Medline parallel RU→EN backtranslationgiannhskp/medline_ru_en_backtranslation - Medline RU→EN backtranslationCore LLM Backtranslations:
giannhskp/medline_ru_en_llm-backtranslation - LLM-generated Medline backtranslationgiannhskp/medline-parallel_ru_en_llm-backtranslation - LLM-generated Medline parallel backtranslationgiannhskp/scipar_ru_en_llm-backtranslation - LLM-generated SciPar backtranslationLLM Backtranslation Variants (Different Decoding Strategies):
giannhskp/medline_ru_en_llm-backtranslation_beam5 - Beam search (5 beams)giannhskp/medline-parallel_ru_en_llm-backtranslation_beam5 - Beam search (5 beams)giannhskp/scipar_ru_en_llm-backtranslation_beam5 - Beam search (5 beams)giannhskp/medline_ru_en_llm-backtranslation_sampling - Sampling (top_p=0.9, temp=0.9)giannhskp/medline-parallel_ru_en_llm-backtranslation_sampling - Sampling strategygiannhskp/scipar_ru_en_llm-backtranslation_sampling - Sampling strategyScore-Based Filtering (40.0 threshold):
giannhskp/medline_en_ru_parallel_filtered_40.0giannhskp/medline_ru_en_backtranslation_filtered_40.0giannhskp/medline-parallel_ru_en_backtranslation_filtered_40.0giannhskp/scipar_ru_en_backtranslation_filtered_40.0giannhskp/scipar_en_ru_parallel_filtered_40.0CometKiwi-Based Filtering (60.0 threshold):
giannhskp/medline_en_ru_parallel_filtered_60.0_wmt22-cometkiwi-dagiannhskp/medline-parallel_ru_en_backtranslation_filtered_60.0_wmt22-cometkiwi-dagiannhskp/medline_ru_en_backtranslation_filtered_60.0_wmt22-cometkiwi-dagiannhskp/scipar_ru_en_backtranslation_filtered_60.0_wmt22-cometkiwi-dagiannhskp/scipar_en_ru_parallel_filtered_60.0_wmt22-cometkiwi-daLLM Backtranslation + CometKiwi Filtering (40.0 threshold):
giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-dagiannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-dagiannhskp/scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-daMedical Domain Classification Filtering:
giannhskp/classifier-filtered-medline_en_ru_parallelgiannhskp/classifier-filtered-medline-parallel_ru_en_backtranslationgiannhskp/classifier-filtered-scipar_en_ru_parallelgiannhskp/classifier-filtered-scipar_ru_en_backtranslationgiannhskp/classifier-filtered-medline_ru_en_backtranslationgiannhskp/classifier-filtered-scipar_ru_en_llm-backtranslationgiannhskp/classifier-filtered-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-daMinimum Length Filtering (>5 words):
giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_gt5giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_gt5giannhskp/medline_en_ru_parallel_gt5giannhskp/classifier-filtered-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_gt5Word Deletion Augmentation (various rates):
giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_word_deletion_0.33_0.15giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.5_0.15giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.33giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15giannhskp/classifier-scipar_ru_en_llm-backtranslation_fi_40.0_wmt22-cometkiwi-da_word_deletion_0.33_0.15giannhskp/classifier-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.5_0.15giannhskp/classifier-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.33giannhskp/classifier-filtered-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.15giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.5_0.15giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.33giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15The pipeline provides three advanced filtering techniques to improve dataset quality by removing low-quality translations and out-of-domain content.
File: custom_utils/filter.py
Neural-based translation quality filtering using COMET (Crosslingual Optimized Metric for Evaluation of Translation) models.
python custom_utils/filter.py \
--input_dataset "giannhskp/medline-parallel_ru_en_llm-backtranslation" \
--src_field "en" \
--mt_field "ru" \
--hf_username "your_username" \
--threshold 0.4 \
--use_gpu
Key Features:
Supported COMET Models:
Unbabel/wmt22-cometkiwi-da (default) - CometKiwi reference-free modelUnbabel/wmt20-comet-qe-da - Quality estimation modelCommand Line Options:
--input_dataset: HuggingFace dataset name to filter--threshold: COMET score threshold (default: 0.6)--src_field/--mt_field: Column names for source and translation text--comet_model: Specific COMET model to use--hf_username: Username for uploading filtered dataset--use_gpu: Enable GPU accelerationOutput Format:
Filtered datasets are uploaded to Hub with naming convention:
{username}/{dataset_name}_filtered_{threshold*100}_{model_name}
Example: myuser/translation-data_filtered_40_wmt22-cometkiwi-da
File: custom_utils/filter_with_classifier.py
Filters datasets using pre-trained text classification models to keep only domain-relevant content (e.g., medical vs. non-medical text).
python custom_utils/filter_with_classifier.py \
--dataset_names giannhskp/scipar_ru_en_llm-backtranslation \
--model_name_or_path "giannhskp/xlm-roberta-base_domain_classifier" \
--text_column "en" \
--label_to_keep 1 \
--push_to_hub \
--hub_repo_prefix "giannhskp/classifier-filtered-"
Key Features:
Typical Workflow:
domain_classifier_train.pyCommand Line Options:
--dataset_names: One or more datasets to filter--model_name_or_path: Pre-trained classifier model path/name--text_column: Column containing text to classify--label_to_keep: Target label to retain (1=medical, 0=non-medical)--batch_size: Inference batch size (default: 32)--push_to_hub: Upload filtered datasets to Hub--hub_repo_prefix: Repository naming prefixIntegration with Domain Classifier:
# 1. Train multilingual domain classifier
python domain_classifier_train.py --num_epochs 3
# 2. Filter datasets using trained classifier
python custom_utils/filter_with_classifier.py \
--dataset_names your_datasets \
--model_name_or_path "username/xlm-roberta-base_domain_classifier" \
--label_to_keep 1
File: dataset_notebooks/filter_by_length.ipynb
Interactive notebook for filtering translation datasets by minimum text length to remove low-quality or incomplete examples.
jupyter notebook dataset_notebooks/filter_by_length.ipynb
Purpose:
Key Features:
Workflow:
len(example['ru']) < 5){original_name}_gt5Available Dataset Categories:
medline_en_ru_parallel)Filter Criteria:
# Keeps only examples where Russian text has ≥ 5 characters
dataset.filter(lambda example: len(example['ru']) >= 5)
Output Naming: Filtered datasets are uploaded with "_gt5" suffix:
giannhskp/medline_ru_en_llm-backtranslationgiannhskp/medline_ru_en_llm-backtranslation_gt5Integration with Other Filters: Length filtering is often applied as a final step after quality and domain filtering to ensure minimum content requirements.
Multi-Stage Filtering Pipeline:
Example Multi-Stage Workflow:
# Stage 1: COMET quality filtering
python custom_utils/filter.py \
--input_dataset "original_backtranslation_dataset" \
--threshold 0.4 \
--hf_username "username"
# Stage 2: Domain classification filtering
python custom_utils/filter_with_classifier.py \
--dataset_names "username/dataset_filtered_40_wmt22-cometkiwi-da" \
--model_name_or_path "username/domain_classifier" \
--label_to_keep 1 \
--push_to_hub \
--hub_repo_prefix "username/classifier-filtered-"
# Stage 3: Length filtering (using notebook interactively)
# jupyter notebook dataset_notebooks/filter_by_length.ipynb
# Select: username/classifier-filtered-dataset_filtered_40_wmt22-cometkiwi-da
# Result: username/classifier-filtered-dataset_filtered_40_wmt22-cometkiwi-da_gt5
Dataset Naming Conventions:
{dataset}_filtered_{threshold}_{comet_model}classifier-filtered-{dataset}{dataset}_gt5classifier-filtered-{dataset}_filtered_{threshold}_{comet_model}_gt5The pipeline includes data augmentation techniques to improve model robustness and create noisy training data for testing purposes.
File: dataset_notebooks/corrupt_data.ipynb
Interactive tool for creating corrupted versions of translation datasets by randomly deleting words from English text.
jupyter notebook dataset_notebooks/corrupt_data.ipynb
Purpose:
Core Functionality:
Key Parameters:
SENTENCE_CORRUPTION_PROBABILITY = 1.0 # Probability a sentence gets corrupted
WORD_DELETION_PROBABILITY = 0.15 # Probability each word gets deleted
Workflow:
Core Function - delete_linguistic_words_mapper(example):
word_tokenizeWORD_DELETION_PROBABILITYTreebankWordDetokenizerTarget Datasets: Focuses on 6 LLM-backtranslation datasets:
giannhskp/medline_ru_en_llm-backtranslationgiannhskp/scipar_ru_en_llm-backtranslationgiannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da)Example Usage:
# Configure corruption parameters
SENTENCE_CORRUPTION_PROBABILITY = 1.0
WORD_DELETION_PROBABILITY = 0.15
# Load and corrupt dataset
dataset = dataset_selector() # Interactive selection
hf_dataset = load_hf_dataset(dataset)
corrupted_dataset = hf_dataset.map(delete_linguistic_words_mapper)
# Upload with automatic naming
repo_id = dataset + f"_wd_{SENTENCE_CORRUPTION_PROBABILITY}_{WORD_DELETION_PROBABILITY}"
corrupted_dataset.push_to_hub(repo_id, private=True)
Output Naming Convention:
{original_name}_wd_{sentence_prob}_{word_prob}
Examples:
giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-dagiannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15Research Applications:
🔧 Note: See the notebook's documentation for detailed parameter tuning guidelines.
The pipeline supports three main backtranslation approaches:
File: llm-backtranslation-Tower.py
Uses the TowerInstruct-13B model for high-quality backtranslation from Russian to English.
python llm-backtranslation-Tower.py
Configuration Options:
SOURCE_LANG: Source language (default: 'ru')TARGET_LANG: Target language (default: 'en')MODEL_NAME: LLM model to use (default: "Unbabel/TowerInstruct-13B-v0.1")DATASET_NAME: Input dataset containing Russian textBATCH_SIZE: Processing batch size (default: 1 for LLMs)PUSH_TO_HUB: Whether to upload results to Hugging Face HubKey Features:
Example Usage:
# Modify these variables in the script:
DATASET_NAME = "sethjsa/medline_en_ru_parallel"
OUTPUT_DATASET = "data/medline-parallel_ru_en_llm-backtranslation"
MODEL_NAME = "Unbabel/TowerInstruct-13B-v0.1"
File: pivot.py
Implements pivot translation using French as an intermediate language to generate English-Russian parallel data.
python pivot.py
Two Translation Pipelines:
Pivot-to-Source Translation:
Target-to-Source via Pivot:
Configuration:
MODEL_SRC_PIVOT: French→English model (default: Helsinki-NLP OPUS)MODEL_PIVOT_TGT: Russian→French model (default: Helsinki-NLP OPUS)DATASET_SRC_PIVOT: Source datasets for FR-EN pairsDATASET_PIVOT_TGT: Source datasets for FR-RU pairsOutputs:
data/pivot_en-fr-ru_pivot_to_source_finetunedata/pivot_en-fr-ru_target_to_source_finetuneFile: original_backtranslation.ipynb
Comprehensive notebook for creating traditional backtranslation datasets using neural machine translation models.
jupyter notebook original_backtranslation.ipynb
Two Main Workflows:
Monolingual-to-Backtranslation:
data/medline_ru_en_backtranslationParallel Dataset Expansion:
data/medline-parallel_ru_en_expanded-3)Configuration Options:
cfg.SOURCE_LANG = "ru" # Source language
cfg.TARGET_LANG = "en" # Target language
cfg.MODEL_NAME_OR_PATH = "Helsinki-NLP/opus-mt-ru-en"
cfg.PER_DEVICE_EVAL_BATCH_SIZE = 256 # Translation batch size
Translation Quality Control:
Available Source Datasets:
sethjsa/medline_ru_mono - Russian medical abstracts (monolingual)sethjsa/medline_en_ru_parallel - Medical parallel data (for expansion)sethjsa/scipar_ru_mono - Russian scientific papers (monolingual)Output Integration:
Generated datasets can be loaded and used in training pipelines using load_from_disk() function.
📚 Note: For comprehensive step-by-step instructions, detailed configuration options, and complete code examples, refer to the extensive documentation within the
original_backtranslation.ipynbnotebook itself.
File: evaluate-bt-quality.py
Comprehensive evaluation of LLM-generated backtranslations using multiple metrics.
python evaluate-bt-quality.py
Metrics Computed:
Key Features:
Expected Results: The script includes commented results showing performance comparisons between different generation strategies (greedy, beam search, sampling).
File: evaluate-llm.py
Evaluates LLM translation performance on standard test sets.
python evaluate-llm.py
Test Datasets:
Features:
File: evaluation.ipynb
Comprehensive evaluation framework for assessing fine-tuned translation models on multiple test datasets.
jupyter notebook evaluation.ipynb
Purpose:
re-train.py or train.ipynbKey Features:
Typical Workflow:
File: re-train.py
Comprehensive training pipeline for sequence-to-sequence translation models.
# Single experiment
python re-train.py --experiment_dir ./experiments-1 --experiments 36
# Multiple experiments
python re-train.py --experiment_dir ./experiments-1 --experiments 36 37 38
# All experiments
python re-train.py --experiment_dir ./experiments-1
Configuration via JSON files:
Create experiment configuration files in your experiment directory:
{
"MODEL_NAME_OR_PATH": "Helsinki-NLP/opus-mt-en-ru",
"TRAIN_DATASET_NAME": "sethjsa/medline_en_ru_parallel",
"VALID_DATASET_NAME": null,
"TEST_DATASET_NAME": null,
"SOURCE_LANG": "en",
"TARGET_LANG": "ru",
"MAX_SOURCE_LENGTH": 128,
"MAX_TARGET_LENGTH": 128,
"LEARNING_RATE": 2e-5,
"PER_DEVICE_TRAIN_BATCH_SIZE": 16,
"PER_DEVICE_EVAL_BATCH_SIZE": 16,
"NUM_TRAIN_EPOCHS": 3,
"OUTPUT_DIR": "./results-custom"
}
Features:
Dataset Handling:
Alternative: Interactive Training
You can also fine-tune models interactively using the Jupyter notebook:
jupyter notebook train.ipynb
The notebook provides a step-by-step interface for model training with real-time monitoring and customization options.
File: domain_classifier_train.py
Trains a multilingual classifier to distinguish medical from non-medical text in both Russian and English.
python domain_classifier_train.py \
--model_checkpoint xlm-roberta-base \
--batch_size 8 \
--learning_rate 2e-5 \
--num_epochs 3 \
--max_length 128
Training Data:
Command Line Arguments:
--model_checkpoint: Base model (default: xlm-roberta-base)--batch_size: Training batch size (default: 8)--learning_rate: Learning rate (default: 2e-5)--num_epochs: Training epochs (default: 3)--max_length: Maximum sequence length (default: 128)--train_size: Training set proportion (default: 0.8)--val_size: Validation set proportion (default: 0.1)Output:
File: llm_bt_diagnostics.py
Comprehensive diagnostic analysis of synthetic translation data quality.
python llm_bt_diagnostics.py \
--human-ds sethjsa/medline_en_ru_parallel \
--synthetic-ds giannhskp/medline_ru_en_llm-backtranslation \
giannhskp/scipar_ru_en_llm-backtranslation \
--eval-ds sethjsa/wmt_biomedical_en_ru_test \
--lm mistralai/Mistral-7B-v0.3 \
--device cuda:0
Three Diagnostic Metrics:
Perplexity Analysis (1A):
Lexical Novelty (1B):
Embedding Distance (1C):
Command Line Options:
--human-ds: Reference human dataset--synthetic-ds: List of synthetic datasets to analyze--eval-ds: Evaluation dataset for embedding comparison--lm: Language model for perplexity computation--embedder: Sentence transformer model--device: Computation device (cpu/cuda)--max-ce: Maximum cross-entropy before clamping--filter-gt5: Only analyze sentences >5 wordsOutputs:
output_llm-bt_diagnostics/ppl_<dataset>.csv: Perplexity scoresoutput_llm-bt_diagnostics/novelty_<dataset>.csv: Novelty ratiosoutput_llm-bt_diagnostics/dist_<dataset>.csv: Embedding distances| File | Purpose | Input | Output |
|---|---|---|---|
dataset_size.py | Calculate dataset sizes | HF dataset names | Console size report |
llm-backtranslation-Tower.py | LLM backtranslation | Russian text dataset | EN-RU parallel dataset |
pivot.py | Pivot-based backtranslation | FR-RU datasets | EN-RU parallel datasets |
evaluate-bt-quality.py | Quality evaluation | Backtranslation datasets | CSV scores + metrics |
evaluate-llm.py | LLM evaluation | Test datasets | CSV translations + metrics |
re-train.py | Model training | Training datasets + config | Trained models |
domain_classifier_train.py | Domain classification | Medical/non-medical data | Domain classifier |
llm_bt_diagnostics.py | Diagnostic analysis | Human + synthetic datasets | Diagnostic CSV files |
custom_utils/filter.py | COMET quality filtering | Translation datasets | Quality-filtered datasets |
custom_utils/filter_with_classifier.py | Domain classification filtering | Translation datasets + classifier | Domain-filtered datasets |
| File | Purpose |
|---|---|
evaluation.ipynb | Interactive evaluation experiments |
original_backtranslation.ipynb | Traditional backtranslation methods |
train.ipynb | Interactive model training |
dataset_notebooks/filter_by_length.ipynb | Length-based dataset filtering |
dataset_notebooks/corrupt_data.ipynb | Word deletion data augmentation |
python llm-backtranslation-Tower.py
python evaluate-bt-quality.py
python llm_bt_diagnostics.py \
--human-ds sethjsa/medline_en_ru_parallel \
--synthetic-ds giannhskp/medline_ru_en_llm-backtranslation \
--eval-ds sethjsa/wmt_biomedical_en_ru_test
python re-train.py --experiment_dir ./experiments --experiments 1
python domain_classifier_train.py --num_epochs 3
python custom_utils/filter.py \
--input_dataset "giannhskp/medline_ru_en_llm-backtranslation" \
--threshold 0.4 \
--hf_username "your_username" \
--use_gpu
python custom_utils/filter_with_classifier.py \
--dataset_names "your_username/medline_ru_en_llm-backtranslation_filtered_40_wmt22-cometkiwi-da" \
--model_name_or_path "your_username/xlm-roberta-base_domain_classifier" \
--text_column "en" \
--label_to_keep 1 \
--push_to_hub \
--hub_repo_prefix "your_username/classifier-filtered-"
jupyter notebook dataset_notebooks/filter_by_length.ipynb
# Select filtered dataset and apply length filter
python evaluate-bt-quality.py
jupyter notebook dataset_notebooks/corrupt_data.ipynb
# Configure corruption parameters and select target datasets
python re-train.py --experiment_dir ./experiments-robust --experiments 1
python evaluate-llm.py # Test on standard benchmarks
python llm_bt_diagnostics.py \
--human-ds sethjsa/medline_en_ru_parallel \
--synthetic-ds "your_username/dataset_wd_1_0.15" \
--eval-ds sethjsa/wmt_biomedical_en_ru_test
# Traditional backtranslation
jupyter notebook original_backtranslation.ipynb
# LLM backtranslation
python llm-backtranslation-Tower.py
# Pivot backtranslation
python pivot.py
# Multi-stage filtering
python custom_utils/filter.py --threshold 0.4
python custom_utils/filter_with_classifier.py --label_to_keep 1
jupyter notebook dataset_notebooks/filter_by_length.ipynb
# Create robust training variants
jupyter notebook dataset_notebooks/corrupt_data.ipynb
# Train with different datasets
python re-train.py --experiment_dir ./experiments --experiments 1 2 3
# Quality evaluation
python evaluate-bt-quality.py
# LLM evaluation
python evaluate-llm.py
# Interactive evaluation
jupyter notebook evaluation.ipynb
# Diagnostic analysis
python llm_bt_diagnostics.py
Backtranslation for Domain Adaptation in Neural Machine Translation
Jupyter Notebook
0
63 commits
updated Jun 1, 2025
This repository contains a comprehensive pipeline for neural machine translation research, specifically focusing on Russian-English translation using various backtranslation techniques, data augmentation methods, and quality assessment tools. The pipeline supports both traditional machine translation models and large language models (LLMs) for backtranslation generation.
The research pipeline is designed to:
📝 Note: Each script in this repository contains detailed documentation and instructions within the file itself. Please refer to the docstrings and comments in each script for additional implementation details, parameter explanations, and usage examples.
pip install -r requirements.txt
Set your Hugging Face token in each script or as an environment variable:
export HF_TOKEN='your_huggingface_token_here'
File: dataset_size.py
Calculate the number of examples in various datasets to understand data availability.
python dataset_size.py
Purpose:
Outputs: Console display of dataset sizes in tabular format
This section lists all the datasets available in the pipeline, organized by category. These datasets can be used for training, evaluation, and analysis across all pipeline components.
Original Human-Translated Datasets:
sethjsa/medline_en_ru_parallel - Medical parallel corpus (Medline)sethjsa/scipar_en_ru_parallel - Scientific paper abstracts parallel corpusBasic Backtranslation Datasets:
giannhskp/scipar_ru_en_backtranslation - SciPar RU→EN backtranslationgiannhskp/medline-parallel_ru_en_backtranslation - Medline parallel RU→EN backtranslationgiannhskp/medline_ru_en_backtranslation - Medline RU→EN backtranslationCore LLM Backtranslations:
giannhskp/medline_ru_en_llm-backtranslation - LLM-generated Medline backtranslationgiannhskp/medline-parallel_ru_en_llm-backtranslation - LLM-generated Medline parallel backtranslationgiannhskp/scipar_ru_en_llm-backtranslation - LLM-generated SciPar backtranslationLLM Backtranslation Variants (Different Decoding Strategies):
giannhskp/medline_ru_en_llm-backtranslation_beam5 - Beam search (5 beams)giannhskp/medline-parallel_ru_en_llm-backtranslation_beam5 - Beam search (5 beams)giannhskp/scipar_ru_en_llm-backtranslation_beam5 - Beam search (5 beams)giannhskp/medline_ru_en_llm-backtranslation_sampling - Sampling (top_p=0.9, temp=0.9)giannhskp/medline-parallel_ru_en_llm-backtranslation_sampling - Sampling strategygiannhskp/scipar_ru_en_llm-backtranslation_sampling - Sampling strategyScore-Based Filtering (40.0 threshold):
giannhskp/medline_en_ru_parallel_filtered_40.0giannhskp/medline_ru_en_backtranslation_filtered_40.0giannhskp/medline-parallel_ru_en_backtranslation_filtered_40.0giannhskp/scipar_ru_en_backtranslation_filtered_40.0giannhskp/scipar_en_ru_parallel_filtered_40.0CometKiwi-Based Filtering (60.0 threshold):
giannhskp/medline_en_ru_parallel_filtered_60.0_wmt22-cometkiwi-dagiannhskp/medline-parallel_ru_en_backtranslation_filtered_60.0_wmt22-cometkiwi-dagiannhskp/medline_ru_en_backtranslation_filtered_60.0_wmt22-cometkiwi-dagiannhskp/scipar_ru_en_backtranslation_filtered_60.0_wmt22-cometkiwi-dagiannhskp/scipar_en_ru_parallel_filtered_60.0_wmt22-cometkiwi-daLLM Backtranslation + CometKiwi Filtering (40.0 threshold):
giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-dagiannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-dagiannhskp/scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-daMedical Domain Classification Filtering:
giannhskp/classifier-filtered-medline_en_ru_parallelgiannhskp/classifier-filtered-medline-parallel_ru_en_backtranslationgiannhskp/classifier-filtered-scipar_en_ru_parallelgiannhskp/classifier-filtered-scipar_ru_en_backtranslationgiannhskp/classifier-filtered-medline_ru_en_backtranslationgiannhskp/classifier-filtered-scipar_ru_en_llm-backtranslationgiannhskp/classifier-filtered-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-daMinimum Length Filtering (>5 words):
giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_gt5giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_gt5giannhskp/medline_en_ru_parallel_gt5giannhskp/classifier-filtered-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_gt5Word Deletion Augmentation (various rates):
giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_word_deletion_0.33_0.15giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.5_0.15giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.33giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15giannhskp/classifier-scipar_ru_en_llm-backtranslation_fi_40.0_wmt22-cometkiwi-da_word_deletion_0.33_0.15giannhskp/classifier-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.5_0.15giannhskp/classifier-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.33giannhskp/classifier-filtered-scipar_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.15giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.5_0.15giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_0.33_0.33giannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15The pipeline provides three advanced filtering techniques to improve dataset quality by removing low-quality translations and out-of-domain content.
File: custom_utils/filter.py
Neural-based translation quality filtering using COMET (Crosslingual Optimized Metric for Evaluation of Translation) models.
python custom_utils/filter.py \
--input_dataset "giannhskp/medline-parallel_ru_en_llm-backtranslation" \
--src_field "en" \
--mt_field "ru" \
--hf_username "your_username" \
--threshold 0.4 \
--use_gpu
Key Features:
Supported COMET Models:
Unbabel/wmt22-cometkiwi-da (default) - CometKiwi reference-free modelUnbabel/wmt20-comet-qe-da - Quality estimation modelCommand Line Options:
--input_dataset: HuggingFace dataset name to filter--threshold: COMET score threshold (default: 0.6)--src_field/--mt_field: Column names for source and translation text--comet_model: Specific COMET model to use--hf_username: Username for uploading filtered dataset--use_gpu: Enable GPU accelerationOutput Format:
Filtered datasets are uploaded to Hub with naming convention:
{username}/{dataset_name}_filtered_{threshold*100}_{model_name}
Example: myuser/translation-data_filtered_40_wmt22-cometkiwi-da
File: custom_utils/filter_with_classifier.py
Filters datasets using pre-trained text classification models to keep only domain-relevant content (e.g., medical vs. non-medical text).
python custom_utils/filter_with_classifier.py \
--dataset_names giannhskp/scipar_ru_en_llm-backtranslation \
--model_name_or_path "giannhskp/xlm-roberta-base_domain_classifier" \
--text_column "en" \
--label_to_keep 1 \
--push_to_hub \
--hub_repo_prefix "giannhskp/classifier-filtered-"
Key Features:
Typical Workflow:
domain_classifier_train.pyCommand Line Options:
--dataset_names: One or more datasets to filter--model_name_or_path: Pre-trained classifier model path/name--text_column: Column containing text to classify--label_to_keep: Target label to retain (1=medical, 0=non-medical)--batch_size: Inference batch size (default: 32)--push_to_hub: Upload filtered datasets to Hub--hub_repo_prefix: Repository naming prefixIntegration with Domain Classifier:
# 1. Train multilingual domain classifier
python domain_classifier_train.py --num_epochs 3
# 2. Filter datasets using trained classifier
python custom_utils/filter_with_classifier.py \
--dataset_names your_datasets \
--model_name_or_path "username/xlm-roberta-base_domain_classifier" \
--label_to_keep 1
File: dataset_notebooks/filter_by_length.ipynb
Interactive notebook for filtering translation datasets by minimum text length to remove low-quality or incomplete examples.
jupyter notebook dataset_notebooks/filter_by_length.ipynb
Purpose:
Key Features:
Workflow:
len(example['ru']) < 5){original_name}_gt5Available Dataset Categories:
medline_en_ru_parallel)Filter Criteria:
# Keeps only examples where Russian text has ≥ 5 characters
dataset.filter(lambda example: len(example['ru']) >= 5)
Output Naming: Filtered datasets are uploaded with "_gt5" suffix:
giannhskp/medline_ru_en_llm-backtranslationgiannhskp/medline_ru_en_llm-backtranslation_gt5Integration with Other Filters: Length filtering is often applied as a final step after quality and domain filtering to ensure minimum content requirements.
Multi-Stage Filtering Pipeline:
Example Multi-Stage Workflow:
# Stage 1: COMET quality filtering
python custom_utils/filter.py \
--input_dataset "original_backtranslation_dataset" \
--threshold 0.4 \
--hf_username "username"
# Stage 2: Domain classification filtering
python custom_utils/filter_with_classifier.py \
--dataset_names "username/dataset_filtered_40_wmt22-cometkiwi-da" \
--model_name_or_path "username/domain_classifier" \
--label_to_keep 1 \
--push_to_hub \
--hub_repo_prefix "username/classifier-filtered-"
# Stage 3: Length filtering (using notebook interactively)
# jupyter notebook dataset_notebooks/filter_by_length.ipynb
# Select: username/classifier-filtered-dataset_filtered_40_wmt22-cometkiwi-da
# Result: username/classifier-filtered-dataset_filtered_40_wmt22-cometkiwi-da_gt5
Dataset Naming Conventions:
{dataset}_filtered_{threshold}_{comet_model}classifier-filtered-{dataset}{dataset}_gt5classifier-filtered-{dataset}_filtered_{threshold}_{comet_model}_gt5The pipeline includes data augmentation techniques to improve model robustness and create noisy training data for testing purposes.
File: dataset_notebooks/corrupt_data.ipynb
Interactive tool for creating corrupted versions of translation datasets by randomly deleting words from English text.
jupyter notebook dataset_notebooks/corrupt_data.ipynb
Purpose:
Core Functionality:
Key Parameters:
SENTENCE_CORRUPTION_PROBABILITY = 1.0 # Probability a sentence gets corrupted
WORD_DELETION_PROBABILITY = 0.15 # Probability each word gets deleted
Workflow:
Core Function - delete_linguistic_words_mapper(example):
word_tokenizeWORD_DELETION_PROBABILITYTreebankWordDetokenizerTarget Datasets: Focuses on 6 LLM-backtranslation datasets:
giannhskp/medline_ru_en_llm-backtranslationgiannhskp/scipar_ru_en_llm-backtranslationgiannhskp/medline-parallel_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da)Example Usage:
# Configure corruption parameters
SENTENCE_CORRUPTION_PROBABILITY = 1.0
WORD_DELETION_PROBABILITY = 0.15
# Load and corrupt dataset
dataset = dataset_selector() # Interactive selection
hf_dataset = load_hf_dataset(dataset)
corrupted_dataset = hf_dataset.map(delete_linguistic_words_mapper)
# Upload with automatic naming
repo_id = dataset + f"_wd_{SENTENCE_CORRUPTION_PROBABILITY}_{WORD_DELETION_PROBABILITY}"
corrupted_dataset.push_to_hub(repo_id, private=True)
Output Naming Convention:
{original_name}_wd_{sentence_prob}_{word_prob}
Examples:
giannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-dagiannhskp/medline_ru_en_llm-backtranslation_filtered_40.0_wmt22-cometkiwi-da_wd_1_0.15Research Applications:
🔧 Note: See the notebook's documentation for detailed parameter tuning guidelines.
The pipeline supports three main backtranslation approaches:
File: llm-backtranslation-Tower.py
Uses the TowerInstruct-13B model for high-quality backtranslation from Russian to English.
python llm-backtranslation-Tower.py
Configuration Options:
SOURCE_LANG: Source language (default: 'ru')TARGET_LANG: Target language (default: 'en')MODEL_NAME: LLM model to use (default: "Unbabel/TowerInstruct-13B-v0.1")DATASET_NAME: Input dataset containing Russian textBATCH_SIZE: Processing batch size (default: 1 for LLMs)PUSH_TO_HUB: Whether to upload results to Hugging Face HubKey Features:
Example Usage:
# Modify these variables in the script:
DATASET_NAME = "sethjsa/medline_en_ru_parallel"
OUTPUT_DATASET = "data/medline-parallel_ru_en_llm-backtranslation"
MODEL_NAME = "Unbabel/TowerInstruct-13B-v0.1"
File: pivot.py
Implements pivot translation using French as an intermediate language to generate English-Russian parallel data.
python pivot.py
Two Translation Pipelines:
Pivot-to-Source Translation:
Target-to-Source via Pivot:
Configuration:
MODEL_SRC_PIVOT: French→English model (default: Helsinki-NLP OPUS)MODEL_PIVOT_TGT: Russian→French model (default: Helsinki-NLP OPUS)DATASET_SRC_PIVOT: Source datasets for FR-EN pairsDATASET_PIVOT_TGT: Source datasets for FR-RU pairsOutputs:
data/pivot_en-fr-ru_pivot_to_source_finetunedata/pivot_en-fr-ru_target_to_source_finetuneFile: original_backtranslation.ipynb
Comprehensive notebook for creating traditional backtranslation datasets using neural machine translation models.
jupyter notebook original_backtranslation.ipynb
Two Main Workflows:
Monolingual-to-Backtranslation:
data/medline_ru_en_backtranslationParallel Dataset Expansion:
data/medline-parallel_ru_en_expanded-3)Configuration Options:
cfg.SOURCE_LANG = "ru" # Source language
cfg.TARGET_LANG = "en" # Target language
cfg.MODEL_NAME_OR_PATH = "Helsinki-NLP/opus-mt-ru-en"
cfg.PER_DEVICE_EVAL_BATCH_SIZE = 256 # Translation batch size
Translation Quality Control:
Available Source Datasets:
sethjsa/medline_ru_mono - Russian medical abstracts (monolingual)sethjsa/medline_en_ru_parallel - Medical parallel data (for expansion)sethjsa/scipar_ru_mono - Russian scientific papers (monolingual)Output Integration:
Generated datasets can be loaded and used in training pipelines using load_from_disk() function.
📚 Note: For comprehensive step-by-step instructions, detailed configuration options, and complete code examples, refer to the extensive documentation within the
original_backtranslation.ipynbnotebook itself.
File: evaluate-bt-quality.py
Comprehensive evaluation of LLM-generated backtranslations using multiple metrics.
python evaluate-bt-quality.py
Metrics Computed:
Key Features:
Expected Results: The script includes commented results showing performance comparisons between different generation strategies (greedy, beam search, sampling).
File: evaluate-llm.py
Evaluates LLM translation performance on standard test sets.
python evaluate-llm.py
Test Datasets:
Features:
File: evaluation.ipynb
Comprehensive evaluation framework for assessing fine-tuned translation models on multiple test datasets.
jupyter notebook evaluation.ipynb
Purpose:
re-train.py or train.ipynbKey Features:
Typical Workflow:
File: re-train.py
Comprehensive training pipeline for sequence-to-sequence translation models.
# Single experiment
python re-train.py --experiment_dir ./experiments-1 --experiments 36
# Multiple experiments
python re-train.py --experiment_dir ./experiments-1 --experiments 36 37 38
# All experiments
python re-train.py --experiment_dir ./experiments-1
Configuration via JSON files:
Create experiment configuration files in your experiment directory:
{
"MODEL_NAME_OR_PATH": "Helsinki-NLP/opus-mt-en-ru",
"TRAIN_DATASET_NAME": "sethjsa/medline_en_ru_parallel",
"VALID_DATASET_NAME": null,
"TEST_DATASET_NAME": null,
"SOURCE_LANG": "en",
"TARGET_LANG": "ru",
"MAX_SOURCE_LENGTH": 128,
"MAX_TARGET_LENGTH": 128,
"LEARNING_RATE": 2e-5,
"PER_DEVICE_TRAIN_BATCH_SIZE": 16,
"PER_DEVICE_EVAL_BATCH_SIZE": 16,
"NUM_TRAIN_EPOCHS": 3,
"OUTPUT_DIR": "./results-custom"
}
Features:
Dataset Handling:
Alternative: Interactive Training
You can also fine-tune models interactively using the Jupyter notebook:
jupyter notebook train.ipynb
The notebook provides a step-by-step interface for model training with real-time monitoring and customization options.
File: domain_classifier_train.py
Trains a multilingual classifier to distinguish medical from non-medical text in both Russian and English.
python domain_classifier_train.py \
--model_checkpoint xlm-roberta-base \
--batch_size 8 \
--learning_rate 2e-5 \
--num_epochs 3 \
--max_length 128
Training Data:
Command Line Arguments:
--model_checkpoint: Base model (default: xlm-roberta-base)--batch_size: Training batch size (default: 8)--learning_rate: Learning rate (default: 2e-5)--num_epochs: Training epochs (default: 3)--max_length: Maximum sequence length (default: 128)--train_size: Training set proportion (default: 0.8)--val_size: Validation set proportion (default: 0.1)Output:
File: llm_bt_diagnostics.py
Comprehensive diagnostic analysis of synthetic translation data quality.
python llm_bt_diagnostics.py \
--human-ds sethjsa/medline_en_ru_parallel \
--synthetic-ds giannhskp/medline_ru_en_llm-backtranslation \
giannhskp/scipar_ru_en_llm-backtranslation \
--eval-ds sethjsa/wmt_biomedical_en_ru_test \
--lm mistralai/Mistral-7B-v0.3 \
--device cuda:0
Three Diagnostic Metrics:
Perplexity Analysis (1A):
Lexical Novelty (1B):
Embedding Distance (1C):
Command Line Options:
--human-ds: Reference human dataset--synthetic-ds: List of synthetic datasets to analyze--eval-ds: Evaluation dataset for embedding comparison--lm: Language model for perplexity computation--embedder: Sentence transformer model--device: Computation device (cpu/cuda)--max-ce: Maximum cross-entropy before clamping--filter-gt5: Only analyze sentences >5 wordsOutputs:
output_llm-bt_diagnostics/ppl_<dataset>.csv: Perplexity scoresoutput_llm-bt_diagnostics/novelty_<dataset>.csv: Novelty ratiosoutput_llm-bt_diagnostics/dist_<dataset>.csv: Embedding distances| File | Purpose | Input | Output |
|---|---|---|---|
dataset_size.py | Calculate dataset sizes | HF dataset names | Console size report |
llm-backtranslation-Tower.py | LLM backtranslation | Russian text dataset | EN-RU parallel dataset |
pivot.py | Pivot-based backtranslation | FR-RU datasets | EN-RU parallel datasets |
evaluate-bt-quality.py | Quality evaluation | Backtranslation datasets | CSV scores + metrics |
evaluate-llm.py | LLM evaluation | Test datasets | CSV translations + metrics |
re-train.py | Model training | Training datasets + config | Trained models |
domain_classifier_train.py | Domain classification | Medical/non-medical data | Domain classifier |
llm_bt_diagnostics.py | Diagnostic analysis | Human + synthetic datasets | Diagnostic CSV files |
custom_utils/filter.py | COMET quality filtering | Translation datasets | Quality-filtered datasets |
custom_utils/filter_with_classifier.py | Domain classification filtering | Translation datasets + classifier | Domain-filtered datasets |
| File | Purpose |
|---|---|
evaluation.ipynb | Interactive evaluation experiments |
original_backtranslation.ipynb | Traditional backtranslation methods |
train.ipynb | Interactive model training |
dataset_notebooks/filter_by_length.ipynb | Length-based dataset filtering |
dataset_notebooks/corrupt_data.ipynb | Word deletion data augmentation |
python llm-backtranslation-Tower.py
python evaluate-bt-quality.py
python llm_bt_diagnostics.py \
--human-ds sethjsa/medline_en_ru_parallel \
--synthetic-ds giannhskp/medline_ru_en_llm-backtranslation \
--eval-ds sethjsa/wmt_biomedical_en_ru_test
python re-train.py --experiment_dir ./experiments --experiments 1
python domain_classifier_train.py --num_epochs 3
python custom_utils/filter.py \
--input_dataset "giannhskp/medline_ru_en_llm-backtranslation" \
--threshold 0.4 \
--hf_username "your_username" \
--use_gpu
python custom_utils/filter_with_classifier.py \
--dataset_names "your_username/medline_ru_en_llm-backtranslation_filtered_40_wmt22-cometkiwi-da" \
--model_name_or_path "your_username/xlm-roberta-base_domain_classifier" \
--text_column "en" \
--label_to_keep 1 \
--push_to_hub \
--hub_repo_prefix "your_username/classifier-filtered-"
jupyter notebook dataset_notebooks/filter_by_length.ipynb
# Select filtered dataset and apply length filter
python evaluate-bt-quality.py
jupyter notebook dataset_notebooks/corrupt_data.ipynb
# Configure corruption parameters and select target datasets
python re-train.py --experiment_dir ./experiments-robust --experiments 1
python evaluate-llm.py # Test on standard benchmarks
python llm_bt_diagnostics.py \
--human-ds sethjsa/medline_en_ru_parallel \
--synthetic-ds "your_username/dataset_wd_1_0.15" \
--eval-ds sethjsa/wmt_biomedical_en_ru_test
# Traditional backtranslation
jupyter notebook original_backtranslation.ipynb
# LLM backtranslation
python llm-backtranslation-Tower.py
# Pivot backtranslation
python pivot.py
# Multi-stage filtering
python custom_utils/filter.py --threshold 0.4
python custom_utils/filter_with_classifier.py --label_to_keep 1
jupyter notebook dataset_notebooks/filter_by_length.ipynb
# Create robust training variants
jupyter notebook dataset_notebooks/corrupt_data.ipynb
# Train with different datasets
python re-train.py --experiment_dir ./experiments --experiments 1 2 3
# Quality evaluation
python evaluate-bt-quality.py
# LLM evaluation
python evaluate-llm.py
# Interactive evaluation
jupyter notebook evaluation.ipynb
# Diagnostic analysis
python llm_bt_diagnostics.py