gorkemergune/turkish-english-nmt

Fine-tuning MarianMT on 522K Turkish–English sentence pairs from Tatoeba. Achieves ~43 BLEU on the test set.

Python

1

4 commits

updated Jun 18, 2026

See the code

README

Turkish → English Neural Machine Translation

Open In Colab

Fine-tuning Helsinki-NLP/opus-mt-tr-en (MarianMT) on the ManyThings/Tatoeba Turkish–English parallel corpus.

Results

Training Curves

BLEU Comparison

Dataset

SplitSentences
Train418,380
Validation52,297
Test52,298
Total522,975

Source: ManyThings.org — Tatoeba Turkish–English pairs, CC-BY licensed.

Model

PropertyValue
Base modelHelsinki-NLP/opus-mt-tr-en
ArchitectureMarianMT (Transformer encoder-decoder)
Parameters76.6M
TokenizerSentencePiece BPE (62,389 vocab)
Training deviceGoogle Colab T4 GPU
Training time~60–90 min

Key hyperparameters: lr=5e-5, epochs=3, effective batch=128, fp16=True, max_length=128

Benchmark

MetricBaselineFine-tunedΔ
BLEU~36~43+7
1-gram precision~65%~72%+7%
2-gram precision~42%~50%+8%

Quickstart (Google Colab)

Click the badge above or follow these steps:

  1. Upload train.csv, val.csv, test.csv and colab.py to MyDrive/week03/
  2. Open a new Colab notebook — set runtime to T4 GPU
  3. Run these cells in order:
# Cell 1 — install
!pip install -q "transformers>=4.40.0" sentencepiece sacrebleu sacremoses "accelerate>=1.1.0"
# Cell 2 — mount drive
from google.colab import drive
drive.mount('/content/drive')
# Cell 3 — train
%run /content/drive/MyDrive/week03/colab.py
# Cell 4 — inference
import torch
from transformers import MarianMTModel, MarianTokenizer

DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = MarianTokenizer.from_pretrained('/content/drive/MyDrive/week03/marian-tr-en-finetuned')
model = MarianMTModel.from_pretrained('/content/drive/MyDrive/week03/marian-tr-en-finetuned').to(DEVICE)
model.eval()

def translate(text):
    inp = tokenizer([text], return_tensors='pt', padding=True, truncation=True, max_length=128).to(DEVICE)
    with torch.no_grad():
        out = model.generate(**inp, num_beams=4, max_length=128)
    return tokenizer.batch_decode(out, skip_special_tokens=True)[0]

print(translate("Merhaba, nasılsın?"))  # → "Hi, how are you?"

Local Setup

git clone https://github.com/gorkemergune/turkish-english-nmt
cd turkish-english-nmt

# Requires Python 3.13 (PyTorch does not support 3.14 yet)
python -m venv venv --system-site-packages
source venv/bin/activate

pip install -r requirements.txt

# Clean and split the dataset
python 01_data_cleaning.py   # expects data.txt in the same directory

# Tokenization comparison
python 02_tokenization.py

# Train locally (slow without GPU — use colab.py for Colab)
python 04_training.py

# Evaluate and interactive inference
python 05_evaluation_and_inference.py

Project Structure

turkish-english-nmt/
├── assets/
│   ├── training_curves.png         # Loss and BLEU curves
│   └── bleu_comparison.png         # Baseline vs fine-tuned comparison
├── colab.py                        # End-to-end Colab training script
├── 01_data_cleaning.py             # Data cleaning and train/val/test split
├── 02_tokenization.py              # Char / Word / Byte / BPE comparison
├── 04_training.py                  # Local MarianMT fine-tuning
├── 05_evaluation_and_inference.py  # BLEU evaluation + interactive demo
├── 06_report_generator.py          # Training curves and comparison charts
├── requirements.txt
└── .gitignore

Note: data.txt and the CSV splits are not tracked (see .gitignore). Download the dataset from ManyThings.org (tur-eng.zip), rename it to data.txt, then run 01_data_cleaning.py.

References

gorkemergune/turkish-english-nmt

Fine-tuning MarianMT on 522K Turkish–English sentence pairs from Tatoeba. Achieves ~43 BLEU on the test set.

Python

1

4 commits

updated Jun 18, 2026

See the code

README

Turkish → English Neural Machine Translation

Open In Colab

Fine-tuning Helsinki-NLP/opus-mt-tr-en (MarianMT) on the ManyThings/Tatoeba Turkish–English parallel corpus.

Results

Training Curves

BLEU Comparison

Dataset

SplitSentences
Train418,380
Validation52,297
Test52,298
Total522,975

Source: ManyThings.org — Tatoeba Turkish–English pairs, CC-BY licensed.

Model

PropertyValue
Base modelHelsinki-NLP/opus-mt-tr-en
ArchitectureMarianMT (Transformer encoder-decoder)
Parameters76.6M
TokenizerSentencePiece BPE (62,389 vocab)
Training deviceGoogle Colab T4 GPU
Training time~60–90 min

Key hyperparameters: lr=5e-5, epochs=3, effective batch=128, fp16=True, max_length=128

Benchmark

MetricBaselineFine-tunedΔ
BLEU~36~43+7
1-gram precision~65%~72%+7%
2-gram precision~42%~50%+8%

Quickstart (Google Colab)

Click the badge above or follow these steps:

  1. Upload train.csv, val.csv, test.csv and colab.py to MyDrive/week03/
  2. Open a new Colab notebook — set runtime to T4 GPU
  3. Run these cells in order:
# Cell 1 — install
!pip install -q "transformers>=4.40.0" sentencepiece sacrebleu sacremoses "accelerate>=1.1.0"
# Cell 2 — mount drive
from google.colab import drive
drive.mount('/content/drive')
# Cell 3 — train
%run /content/drive/MyDrive/week03/colab.py
# Cell 4 — inference
import torch
from transformers import MarianMTModel, MarianTokenizer

DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = MarianTokenizer.from_pretrained('/content/drive/MyDrive/week03/marian-tr-en-finetuned')
model = MarianMTModel.from_pretrained('/content/drive/MyDrive/week03/marian-tr-en-finetuned').to(DEVICE)
model.eval()

def translate(text):
    inp = tokenizer([text], return_tensors='pt', padding=True, truncation=True, max_length=128).to(DEVICE)
    with torch.no_grad():
        out = model.generate(**inp, num_beams=4, max_length=128)
    return tokenizer.batch_decode(out, skip_special_tokens=True)[0]

print(translate("Merhaba, nasılsın?"))  # → "Hi, how are you?"

Local Setup

git clone https://github.com/gorkemergune/turkish-english-nmt
cd turkish-english-nmt

# Requires Python 3.13 (PyTorch does not support 3.14 yet)
python -m venv venv --system-site-packages
source venv/bin/activate

pip install -r requirements.txt

# Clean and split the dataset
python 01_data_cleaning.py   # expects data.txt in the same directory

# Tokenization comparison
python 02_tokenization.py

# Train locally (slow without GPU — use colab.py for Colab)
python 04_training.py

# Evaluate and interactive inference
python 05_evaluation_and_inference.py

Project Structure

turkish-english-nmt/
├── assets/
│   ├── training_curves.png         # Loss and BLEU curves
│   └── bleu_comparison.png         # Baseline vs fine-tuned comparison
├── colab.py                        # End-to-end Colab training script
├── 01_data_cleaning.py             # Data cleaning and train/val/test split
├── 02_tokenization.py              # Char / Word / Byte / BPE comparison
├── 04_training.py                  # Local MarianMT fine-tuning
├── 05_evaluation_and_inference.py  # BLEU evaluation + interactive demo
├── 06_report_generator.py          # Training curves and comparison charts
├── requirements.txt
└── .gitignore

Note: data.txt and the CSV splits are not tracked (see .gitignore). Download the dataset from ManyThings.org (tur-eng.zip), rename it to data.txt, then run 01_data_cleaning.py.

References