A neural machine translation system for translating English text to Tulu language using IndicTrans2 with LoRA (Low-Rank Adaptation) fine-tuning.
This project implements a production-ready translation system for English-to-Tulu translation, leveraging the power of IndicTrans2 (200M parameter model) fine-tuned on a custom Tulu dataset. The system includes both training infrastructure and a web application for real-time translation with confidence scoring and alternative predictions.
LangTranslation/
├── data/
│ └── experimental_full.csv # Training dataset (~10k sentence pairs)
├── indictrans2-200m-en-tulu/ # Fine-tuned LoRA adapters
│ ├── adapter_model.safetensors # LoRA weights
│ ├── adapter_config.json # LoRA configuration
│ └── checkpoint-*/ # Training checkpoints
├── templates/
│ └── index_shadcn.html # Web UI
├── exp_train.py # Initial training script
├── exp_continue_train.py # Continue training from checkpoint
├── exp_flask_app.py # Flask web application
├── database.py # Database utilities
└── requirements.txt # Python dependencies
Base Model: IndicTrans2 (ai4bharat/indictrans2-en-indic-dist-200M)
Fine-tuning Strategy: LoRA (Low-Rank Adaptation)
Language Mapping:
eng_Latn)kan_Knda)Training Parameters:
- Batch size: 8 per device
- Gradient accumulation: 4 steps (effective batch size: 32)
- Learning rate: 3e-4 with linear decay
- Epochs: 10-30 (configurable)
- Precision: FP16 (half-precision)
- Optimization: Flash Attention 2 enabled
git clone <repository-url>
cd LangTranslation
Using Conda (recommended):
conda env create -f environment.yml
conda activate translation-env
Or using venv:
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
For CUDA 12.1+ (check with nvidia-smi):
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
For CUDA 11.8:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
For CPU only (not recommended):
conda install pytorch torchvision torchaudio cpuonly -c pytorch
pip install transformers==4.42.3
pip install datasets sentencepiece sacrebleu
pip install peft # For LoRA support
pip install flash-attn --no-build-isolation # Optional but recommended
pip install IndicTransToolkit # IndicTrans2 preprocessing
pip install flask python-dotenv pandas tqdm
Or install all at once:
pip install -r requirements.txt
pip install peft flash-attn IndicTransToolkit
IndicTrans2 requires authentication:
# Login to Hugging Face
huggingface-cli login
# Or set token as environment variable
export HF_TOKEN="your_huggingface_token_here"
Get your token from: https://huggingface.co/settings/tokens
Access the model: https://huggingface.co/ai4bharat/indictrans2-en-indic-dist-200M
python exp_train.py
This will:
data/experimental_full.csvindictrans2-200m-en-tulu/indictrans2-200m-en-tulu/Training time: ~2-4 hours on RTX 4050 (6GB VRAM)
python exp_continue_train.py
This resumes from the last checkpoint and trains for 10-20 more epochs.
python exp_flask_app.py
The Flask app will:
Web Interface Features:
POST /translate
{
"text": "Hello, how are you?",
"include_details": true
}
GET /history?limit=50
GET /search?q=hello
GET /statistics
Edit exp_train.py or exp_continue_train.py:
# Data
DATA_FILE = "data/experimental_full.csv"
COL_ENGLISH = "English"
COL_TULU = "Tulu"
# Model
MODEL_NAME = "ai4bharat/indictrans2-en-indic-dist-200M"
OUTPUT_DIR = "indictrans2-200m-en-tulu"
# Languages
SRC_LANG = "eng_Latn" # English
TGT_LANG = "kan_Knda" # Tulu (Kannada script)
# LoRA Config
r = 64 # Rank
lora_alpha = 128 # Scaling factor
lora_dropout = 0.1 # Dropout rate
# Training
batch_size = 8 # Per device
gradient_accumulation = 4
learning_rate = 3e-4
num_epochs = 10
For 4GB VRAM GPUs:
per_device_train_batch_size = 2
gradient_accumulation_steps = 16
For 8GB+ VRAM GPUs:
per_device_train_batch_size = 16
gradient_accumulation_steps = 2
| Epoch | Loss | Learning Rate |
|---|---|---|
| 1 | 8.78 | 2.95e-4 |
| 5 | 8.61 | 1.49e-4 |
| 10 | 8.55 | 2.83e-6 |
Loss steadily decreases indicating successful learning of English-Tulu patterns.
Reduce batch size:
per_device_train_batch_size = 2
gradient_accumulation_steps = 16
Skip Flash Attention (slower but works):
# In training script, remove:
attn_implementation="flash_attention_2"
Ensure you're loading tokenizer from base model, not adapter:
tokenizer = AutoTokenizer.from_pretrained(
BASE_MODEL, # Not ADAPTER_PATH
trust_remote_code=True
)
huggingface-cli loginexport HF_TOKEN="your_token"If you use this work, please cite:
IndicTrans2:
@article{gala2023indictrans,
title={IndicTrans2: Towards High-Quality and Accessible Machine Translation Models for all 22 Scheduled Indian Languages},
author={Gala, Jay and others},
journal={arXiv preprint arXiv:2305.16307},
year={2023}
}
LoRA:
@article{hu2021lora,
title={LoRA: Low-Rank Adaptation of Large Language Models},
author={Hu, Edward J and others},
journal={arXiv preprint arXiv:2106.09685},
year={2021}
}
This project builds upon IndicTrans2 which is released under MIT License. Please refer to the original model's license terms.
For questions or issues, please open an issue on GitHub or contact the maintainers.
Status: ✅ Production Ready | 🔄 Active Development | 📊 10k+ Training Samples
HTML
56.9%
Python
43.1%
A neural machine translation system for translating English text to Tulu language using IndicTrans2 with LoRA (Low-Rank Adaptation) fine-tuning.
This project implements a production-ready translation system for English-to-Tulu translation, leveraging the power of IndicTrans2 (200M parameter model) fine-tuned on a custom Tulu dataset. The system includes both training infrastructure and a web application for real-time translation with confidence scoring and alternative predictions.
LangTranslation/
├── data/
│ └── experimental_full.csv # Training dataset (~10k sentence pairs)
├── indictrans2-200m-en-tulu/ # Fine-tuned LoRA adapters
│ ├── adapter_model.safetensors # LoRA weights
│ ├── adapter_config.json # LoRA configuration
│ └── checkpoint-*/ # Training checkpoints
├── templates/
│ └── index_shadcn.html # Web UI
├── exp_train.py # Initial training script
├── exp_continue_train.py # Continue training from checkpoint
├── exp_flask_app.py # Flask web application
├── database.py # Database utilities
└── requirements.txt # Python dependencies
Base Model: IndicTrans2 (ai4bharat/indictrans2-en-indic-dist-200M)
Fine-tuning Strategy: LoRA (Low-Rank Adaptation)
Language Mapping:
eng_Latn)kan_Knda)Training Parameters:
- Batch size: 8 per device
- Gradient accumulation: 4 steps (effective batch size: 32)
- Learning rate: 3e-4 with linear decay
- Epochs: 10-30 (configurable)
- Precision: FP16 (half-precision)
- Optimization: Flash Attention 2 enabled
git clone <repository-url>
cd LangTranslation
Using Conda (recommended):
conda env create -f environment.yml
conda activate translation-env
Or using venv:
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
For CUDA 12.1+ (check with nvidia-smi):
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
For CUDA 11.8:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
For CPU only (not recommended):
conda install pytorch torchvision torchaudio cpuonly -c pytorch
pip install transformers==4.42.3
pip install datasets sentencepiece sacrebleu
pip install peft # For LoRA support
pip install flash-attn --no-build-isolation # Optional but recommended
pip install IndicTransToolkit # IndicTrans2 preprocessing
pip install flask python-dotenv pandas tqdm
Or install all at once:
pip install -r requirements.txt
pip install peft flash-attn IndicTransToolkit
IndicTrans2 requires authentication:
# Login to Hugging Face
huggingface-cli login
# Or set token as environment variable
export HF_TOKEN="your_huggingface_token_here"
Get your token from: https://huggingface.co/settings/tokens
Access the model: https://huggingface.co/ai4bharat/indictrans2-en-indic-dist-200M
python exp_train.py
This will:
data/experimental_full.csvindictrans2-200m-en-tulu/indictrans2-200m-en-tulu/Training time: ~2-4 hours on RTX 4050 (6GB VRAM)
python exp_continue_train.py
This resumes from the last checkpoint and trains for 10-20 more epochs.
python exp_flask_app.py
The Flask app will:
Web Interface Features:
POST /translate
{
"text": "Hello, how are you?",
"include_details": true
}
GET /history?limit=50
GET /search?q=hello
GET /statistics
Edit exp_train.py or exp_continue_train.py:
# Data
DATA_FILE = "data/experimental_full.csv"
COL_ENGLISH = "English"
COL_TULU = "Tulu"
# Model
MODEL_NAME = "ai4bharat/indictrans2-en-indic-dist-200M"
OUTPUT_DIR = "indictrans2-200m-en-tulu"
# Languages
SRC_LANG = "eng_Latn" # English
TGT_LANG = "kan_Knda" # Tulu (Kannada script)
# LoRA Config
r = 64 # Rank
lora_alpha = 128 # Scaling factor
lora_dropout = 0.1 # Dropout rate
# Training
batch_size = 8 # Per device
gradient_accumulation = 4
learning_rate = 3e-4
num_epochs = 10
For 4GB VRAM GPUs:
per_device_train_batch_size = 2
gradient_accumulation_steps = 16
For 8GB+ VRAM GPUs:
per_device_train_batch_size = 16
gradient_accumulation_steps = 2
| Epoch | Loss | Learning Rate |
|---|---|---|
| 1 | 8.78 | 2.95e-4 |
| 5 | 8.61 | 1.49e-4 |
| 10 | 8.55 | 2.83e-6 |
Loss steadily decreases indicating successful learning of English-Tulu patterns.
Reduce batch size:
per_device_train_batch_size = 2
gradient_accumulation_steps = 16
Skip Flash Attention (slower but works):
# In training script, remove:
attn_implementation="flash_attention_2"
Ensure you're loading tokenizer from base model, not adapter:
tokenizer = AutoTokenizer.from_pretrained(
BASE_MODEL, # Not ADAPTER_PATH
trust_remote_code=True
)
huggingface-cli loginexport HF_TOKEN="your_token"If you use this work, please cite:
IndicTrans2:
@article{gala2023indictrans,
title={IndicTrans2: Towards High-Quality and Accessible Machine Translation Models for all 22 Scheduled Indian Languages},
author={Gala, Jay and others},
journal={arXiv preprint arXiv:2305.16307},
year={2023}
}
LoRA:
@article{hu2021lora,
title={LoRA: Low-Rank Adaptation of Large Language Models},
author={Hu, Edward J and others},
journal={arXiv preprint arXiv:2106.09685},
year={2021}
}
This project builds upon IndicTrans2 which is released under MIT License. Please refer to the original model's license terms.
For questions or issues, please open an issue on GitHub or contact the maintainers.
Status: ✅ Production Ready | 🔄 Active Development | 📊 10k+ Training Samples
HTML
56.9%
Python
43.1%