kamaladhi/Efficient-English-Tamil-Translation-using-Unsloth-Optimized-Transformer

English→Tamil translation model built using an Unsloth-optimized transformer with LoRA and 4-bit quantization. Developed as part of our Text Analytics semester project, including our own implementation work, experiments, and model evaluations.

1

stars

26

commits

Python

primary language

Aug 5, 2026

updated

english-to-tamil
lora
low-resource-nlp
machine-translation
pytorch
quantization
transformer-models
unsloth

README

🚀 Efficient English-Tamil Translation using Unsloth-Optimized Llama 3.1

A Production-Grade, Bidirectional Neural Machine Translation (NMT) Pipeline

Python Framework Model Optimization Benchmark


📑 Executive Summary

This repository contains the source code, training methodology, and evaluation framework for a highly optimized Bidirectional English ↔ Tamil Neural Machine Translation (NMT) system. By leveraging Llama 3.1 8B combined with Unsloth 4-bit QLoRA optimization, this project demonstrates how large language models can be efficiently fine-tuned on resource-constrained hardware (single 16GB GPU) to achieve state-of-the-art translation capabilities.

In standardized benchmarking (FLORES-200), our fine-tuned Llama 3.1 model successfully outperformed Meta's NLLB-200-distilled-600M and AI4Bharat's IndicTrans2 in the English-to-Tamil direction, proving the viability of LLMs for complex, agglutinative Dravidian languages.


🔬 Detailed Methodology

Our training pipeline is designed with strict adherence to modern NLP research standards, ensuring zero data leakage and high reproducibility.

1. Data Curation & Preprocessing

To train a robust bidirectional model, we curated a massive corpus of 100,000 real parallel sentence pairs:

  • OPUS-100 (50,000 pairs): Sourced from Helsinki-NLP's multilingual corpus, providing strong foundational vocabulary.
  • Samanantar (50,000 pairs): Sourced from AI4Bharat's extensive Indian language corpus, providing deep, culturally accurate contextual phrases.

Quality Assurance Pipeline:

  • Length Filtering: Sentences under 5 characters were purged.
  • De-duplication: Exact duplicates were aggressively removed to prevent model memorization and overfitting.
  • Contamination Check: We ensured strict separation between the training data and the FLORES-200 benchmark test sets.

2. Architectural Design & Optimization (Unsloth + QLoRA)

Fine-tuning an 8-Billion parameter model conventionally requires massive compute clusters. We utilized Unsloth to fundamentally rewrite the backpropagation kernels, enabling:

  • 4-bit Quantization (BitsAndBytes): Reduces model footprint by 70%, fitting the entire 8B model into just ~6GB of VRAM.
  • LoRA (Low-Rank Adaptation): We applied trainable rank decomposition matrices (r=64, alpha=32) strictly to the attention and MLP layers (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj).
  • Speed & Memory: Achieved 2x faster training speeds and 0% accuracy degradation compared to standard HuggingFace implementations.

3. Training Dynamics

  • Base Model: unsloth/Meta-Llama-3.1-8B-bnb-4bit
  • Prompt Formatting: We designed a strict bidirectional prompt structure to force the LLM into "Translation Mode", bypassing its conversational alignment.
  • Optimizer: AdamW (8-bit) with a linear learning rate scheduler (lr = 2e-5) and 300 warmup steps.
  • Batching: Effective batch size of 16 (via gradient accumulation steps = 8).

📊 Comprehensive Evaluation (FLORES-200)

We evaluated the model using the strict FLORES-200 devtest benchmark. To ensure a multi-dimensional understanding of the model's quality, we computed four distinct metrics:

  1. BLEU: Traditional n-gram overlap.
  2. chrF++: Character n-gram F-score (critical for agglutinative languages like Tamil where prefixes/suffixes alter word structures).
  3. COMET: State-of-the-art Neural MT metric that uses a cross-lingual encoder to evaluate semantic meaning.
  4. Sentence-BERT: Cosine similarity of sentence embeddings.

🏆 Benchmark Comparison Table

ModelDirectionBLEUchrF++COMETSBERT
Our Model (Llama 3.1 LoRA)ta2en17.4244.020.8350.8124
Our Model (Llama 3.1 LoRA)en2ta11.7322.680.6760.8230
NLLB-200-distilled (Meta)ta2en41.6855.840.8560.8636
NLLB-200-distilled (Meta)en2ta7.1746.980.8670.9269
IndicTrans2 (AI4Bharat)ta2en8.228.990.345-0.0179
IndicTrans2 (AI4Bharat)en2ta0.000.660.2480.0840

Analytical Insights: Our fine-tuned LLM vastly outperformed IndicTrans2 in both directions. Crucially, in the English-to-Tamil direction, our model significantly outperformed Meta's NLLB-200 (11.73 BLEU vs 7.17 BLEU), establishing that generalized LLMs (like Llama 3) when properly fine-tuned with LoRA, possess superior generative capabilities for low-resource translation tasks compared to traditional encoder-decoder architectures.


💻 Codebase & Usage

Project Structure

📂 Efficient-English-Tamil-Translation/
├── 📂 src/
│   ├── config.py             # Global Hyperparameters & Run settings
│   ├── data_loader.py        # OPUS-100 & Samanantar fetching algorithms
│   ├── model.py              # Unsloth Instantiation & LoRA mapping
│   ├── train.py              # Supervised Fine-Tuning (SFT) Loop & Safe-Save
│   ├── inference.py          # Translation parsing & Token generation
│   ├── evaluate.py           # Metric calculation (BLEU, COMET, chrF++)
│   ├── benchmark.py          # FLORES-200 dataset integration
│   └── baselines.py          # NLLB & IndicTrans2 automated loaders
├── run_pipeline.py           # The Master Orchestration Script (E2E)
├── zip_for_kaggle.py         # Deployment / Packaging utility
└── requirements.txt          # Explicit pip dependencies

Installation

git clone https://github.com/your-repo/Efficient-English-Tamil-Translation.git
cd Efficient-English-Tamil-Translation
pip install -r requirements.txt

Training & Benchmarking from Scratch

To execute the entire end-to-end pipeline (Data Download → Unsloth Training → FLORES Benchmarking → Result Compilation):

python run_pipeline.py

Inference Demo (Using the Trained Model)

from src import FastConfig, load_model, TamilTranslator

# Initialize pipeline
config = FastConfig()
model, tokenizer = load_model(config)
translator = TamilTranslator(model, tokenizer)

# Bidirectional Auto-Detection
english_output = translator.translate("நான் பள்ளிக்கு செல்கிறேன்")
print(f"Translation: {english_output}")

tamil_output = translator.translate("The weather is beautiful today.")
print(f"Translation: {tamil_output}")

🔮 Future Roadmap (Tier 2 & 3)

We are actively expanding this architecture. Upcoming features include:

  • Code-Mixed "Tanglish" Adapter: Fine-tuning an additional LoRA adapter to seamlessly translate conversational Chennai-style Tanglish into formal English.
  • GGUF Edge Deployment: Exporting the model weights to 8-bit .gguf formats to allow 100% offline, GPU-free translation on mobile phones and laptops via llama.cpp.
  • Speech-to-Speech UI: Integrating OpenAI Whisper and TTS APIs to create a real-time vocal translator application.

👥 Authors

  • JEEVAKAMAL K R – CB.AI.U4AID23115
  • JEIESH J S – CB.AI.U4AID23116
  • SRI SOMESH S – CB.AI.U4AID23141
  • SAI CHAKRITH – CB.AI.U4AID23143
  • SURIYA DHARSAUN KG – CB.AI.U4AID23144

Developed as part of the Text Analytics coursework at Amrita Vishwa Vidyapeetham.

Contributors

Suriya4169

17 commits

kamaladhi

9 commits

kamaladhi/Efficient-English-Tamil-Translation-using-Unsloth-Optimized-Transformer

English→Tamil translation model built using an Unsloth-optimized transformer with LoRA and 4-bit quantization. Developed as part of our Text Analytics semester project, including our own implementation work, experiments, and model evaluations.

1

stars

26

commits

Python

primary language

Aug 5, 2026

updated

english-to-tamil
lora
low-resource-nlp
machine-translation
pytorch
quantization
transformer-models
unsloth

README

🚀 Efficient English-Tamil Translation using Unsloth-Optimized Llama 3.1

A Production-Grade, Bidirectional Neural Machine Translation (NMT) Pipeline

Python Framework Model Optimization Benchmark


📑 Executive Summary

This repository contains the source code, training methodology, and evaluation framework for a highly optimized Bidirectional English ↔ Tamil Neural Machine Translation (NMT) system. By leveraging Llama 3.1 8B combined with Unsloth 4-bit QLoRA optimization, this project demonstrates how large language models can be efficiently fine-tuned on resource-constrained hardware (single 16GB GPU) to achieve state-of-the-art translation capabilities.

In standardized benchmarking (FLORES-200), our fine-tuned Llama 3.1 model successfully outperformed Meta's NLLB-200-distilled-600M and AI4Bharat's IndicTrans2 in the English-to-Tamil direction, proving the viability of LLMs for complex, agglutinative Dravidian languages.


🔬 Detailed Methodology

Our training pipeline is designed with strict adherence to modern NLP research standards, ensuring zero data leakage and high reproducibility.

1. Data Curation & Preprocessing

To train a robust bidirectional model, we curated a massive corpus of 100,000 real parallel sentence pairs:

  • OPUS-100 (50,000 pairs): Sourced from Helsinki-NLP's multilingual corpus, providing strong foundational vocabulary.
  • Samanantar (50,000 pairs): Sourced from AI4Bharat's extensive Indian language corpus, providing deep, culturally accurate contextual phrases.

Quality Assurance Pipeline:

  • Length Filtering: Sentences under 5 characters were purged.
  • De-duplication: Exact duplicates were aggressively removed to prevent model memorization and overfitting.
  • Contamination Check: We ensured strict separation between the training data and the FLORES-200 benchmark test sets.

2. Architectural Design & Optimization (Unsloth + QLoRA)

Fine-tuning an 8-Billion parameter model conventionally requires massive compute clusters. We utilized Unsloth to fundamentally rewrite the backpropagation kernels, enabling:

  • 4-bit Quantization (BitsAndBytes): Reduces model footprint by 70%, fitting the entire 8B model into just ~6GB of VRAM.
  • LoRA (Low-Rank Adaptation): We applied trainable rank decomposition matrices (r=64, alpha=32) strictly to the attention and MLP layers (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj).
  • Speed & Memory: Achieved 2x faster training speeds and 0% accuracy degradation compared to standard HuggingFace implementations.

3. Training Dynamics

  • Base Model: unsloth/Meta-Llama-3.1-8B-bnb-4bit
  • Prompt Formatting: We designed a strict bidirectional prompt structure to force the LLM into "Translation Mode", bypassing its conversational alignment.
  • Optimizer: AdamW (8-bit) with a linear learning rate scheduler (lr = 2e-5) and 300 warmup steps.
  • Batching: Effective batch size of 16 (via gradient accumulation steps = 8).

📊 Comprehensive Evaluation (FLORES-200)

We evaluated the model using the strict FLORES-200 devtest benchmark. To ensure a multi-dimensional understanding of the model's quality, we computed four distinct metrics:

  1. BLEU: Traditional n-gram overlap.
  2. chrF++: Character n-gram F-score (critical for agglutinative languages like Tamil where prefixes/suffixes alter word structures).
  3. COMET: State-of-the-art Neural MT metric that uses a cross-lingual encoder to evaluate semantic meaning.
  4. Sentence-BERT: Cosine similarity of sentence embeddings.

🏆 Benchmark Comparison Table

ModelDirectionBLEUchrF++COMETSBERT
Our Model (Llama 3.1 LoRA)ta2en17.4244.020.8350.8124
Our Model (Llama 3.1 LoRA)en2ta11.7322.680.6760.8230
NLLB-200-distilled (Meta)ta2en41.6855.840.8560.8636
NLLB-200-distilled (Meta)en2ta7.1746.980.8670.9269
IndicTrans2 (AI4Bharat)ta2en8.228.990.345-0.0179
IndicTrans2 (AI4Bharat)en2ta0.000.660.2480.0840

Analytical Insights: Our fine-tuned LLM vastly outperformed IndicTrans2 in both directions. Crucially, in the English-to-Tamil direction, our model significantly outperformed Meta's NLLB-200 (11.73 BLEU vs 7.17 BLEU), establishing that generalized LLMs (like Llama 3) when properly fine-tuned with LoRA, possess superior generative capabilities for low-resource translation tasks compared to traditional encoder-decoder architectures.


💻 Codebase & Usage

Project Structure

📂 Efficient-English-Tamil-Translation/
├── 📂 src/
│   ├── config.py             # Global Hyperparameters & Run settings
│   ├── data_loader.py        # OPUS-100 & Samanantar fetching algorithms
│   ├── model.py              # Unsloth Instantiation & LoRA mapping
│   ├── train.py              # Supervised Fine-Tuning (SFT) Loop & Safe-Save
│   ├── inference.py          # Translation parsing & Token generation
│   ├── evaluate.py           # Metric calculation (BLEU, COMET, chrF++)
│   ├── benchmark.py          # FLORES-200 dataset integration
│   └── baselines.py          # NLLB & IndicTrans2 automated loaders
├── run_pipeline.py           # The Master Orchestration Script (E2E)
├── zip_for_kaggle.py         # Deployment / Packaging utility
└── requirements.txt          # Explicit pip dependencies

Installation

git clone https://github.com/your-repo/Efficient-English-Tamil-Translation.git
cd Efficient-English-Tamil-Translation
pip install -r requirements.txt

Training & Benchmarking from Scratch

To execute the entire end-to-end pipeline (Data Download → Unsloth Training → FLORES Benchmarking → Result Compilation):

python run_pipeline.py

Inference Demo (Using the Trained Model)

from src import FastConfig, load_model, TamilTranslator

# Initialize pipeline
config = FastConfig()
model, tokenizer = load_model(config)
translator = TamilTranslator(model, tokenizer)

# Bidirectional Auto-Detection
english_output = translator.translate("நான் பள்ளிக்கு செல்கிறேன்")
print(f"Translation: {english_output}")

tamil_output = translator.translate("The weather is beautiful today.")
print(f"Translation: {tamil_output}")

🔮 Future Roadmap (Tier 2 & 3)

We are actively expanding this architecture. Upcoming features include:

  • Code-Mixed "Tanglish" Adapter: Fine-tuning an additional LoRA adapter to seamlessly translate conversational Chennai-style Tanglish into formal English.
  • GGUF Edge Deployment: Exporting the model weights to 8-bit .gguf formats to allow 100% offline, GPU-free translation on mobile phones and laptops via llama.cpp.
  • Speech-to-Speech UI: Integrating OpenAI Whisper and TTS APIs to create a real-time vocal translator application.

👥 Authors

  • JEEVAKAMAL K R – CB.AI.U4AID23115
  • JEIESH J S – CB.AI.U4AID23116
  • SRI SOMESH S – CB.AI.U4AID23141
  • SAI CHAKRITH – CB.AI.U4AID23143
  • SURIYA DHARSAUN KG – CB.AI.U4AID23144

Developed as part of the Text Analytics coursework at Amrita Vishwa Vidyapeetham.

Contributors

Suriya4169

17 commits

kamaladhi

9 commits

Languages

Python

100.0%