Two independent LoRA adapters that specialise
ai4bharat/indictrans2-indic-indic-1B
for machine translation between Dogri (doi, Devanagari) and Punjabi (pa, Gurmukhi).
| Adapter | Direction | Source → Target | Test BLEU | Test chrF++ |
|---|---|---|---|---|
doi2pan/ |
Dogri → Punjabi | doi_Deva → pan_Guru |
52.93 | 65.15 |
pan2doi/ |
Punjabi → Dogri | pan_Guru → doi_Deva |
46.38 | 58.75 |
Each direction has its own adapter, trained from scratch. Nothing is shared between the two. This repository contains adapter weights only. The base model is downloaded separately from its original repository.
.
├── README.md
├── doi2pan/
│ ├── adapter_config.json
│ └── adapter_model.safetensors
└── pan2doi/
├── adapter_config.json
└── adapter_model.safetensors
pip install "transformers<4.40" "peft<=0.10.0" "accelerate>=0.28,<0.30" sentencepiece sacrebleu
pip install git+https://github.com/VarunGumma/IndicTransToolkit.git
The versions above match the training environment. IndicTrans2 relies on custom
modelling code (trust_remote_code=True), so newer transformers releases may not work.
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from peft import PeftModel
from IndicTransToolkit import IndicProcessor
BASE = "ai4bharat/indictrans2-indic-indic-1B"
REPO = "YOUR_USERNAME/YOUR_REPO_NAME" # <- this repository
DIRECTION = "doi2pan" # or "pan2doi"
LANG = {"doi2pan": ("doi_Deva", "pan_Guru"), "pan2doi": ("pan_Guru", "doi_Deva")}
src_lang, tgt_lang = LANG[DIRECTION]
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32
tokenizer = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
base = AutoModelForSeq2SeqLM.from_pretrained(BASE, trust_remote_code=True, torch_dtype=dtype)
model = PeftModel.from_pretrained(base, REPO, subfolder=DIRECTION).to(device).eval()
ip = IndicProcessor(inference=True)
sentences = ["बीऽ गी घट्ट डुंह्गेआई च राहओ।"] # Dogri example
batch = ip.preprocess_batch(sentences, src_lang=src_lang, tgt_lang=tgt_lang)
inputs = tokenizer(batch, return_tensors="pt", padding=True, truncation=True, max_length=256).to(device)
with torch.inference_mode():
out = model.generate(**inputs, num_beams=5, max_new_tokens=200,
early_stopping=True, use_cache=True)
decoded = tokenizer.batch_decode(out, skip_special_tokens=True)
print(ip.postprocess_batch(decoded, lang=tgt_lang))
To use both directions in one session, load the base model once, attach the first adapter
with PeftModel.from_pretrained(..., adapter_name="doi2pan"), add the second with
model.load_adapter(..., adapter_name="pan2doi"), and call model.set_adapter(<name>)
before each translation.
IndicTrans2 operates on Devanagari internally. IndicProcessor converts Punjabi (Gurmukhi)
text to Devanagari before tokenisation and converts model output back to the target script.
Always use IndicProcessor for pre- and post-processing, as in the example above. Skipping it
will give poor or wrong-script output.
Training used the Dogri–Punjabi sentence-aligned parallel corpus provided for the SetuNLP task (28,000 aligned sentence pairs).
| Stage | Pairs remaining |
|---|---|
| Raw aligned pairs | 28,000 |
| After rule-based filtering | 27,970 |
| After LaBSE semantic filtering | 23,172 |
| After de-duplication | 23,151 |
Cleaning pipeline
Splits (90 / 5 / 5, fixed seed)
| Split | Pairs |
|---|---|
| Train | 20,835 |
| Validation | 1,158 (a fixed 1,000-pair subset was used for epoch-level model selection) |
| Test | 1,158 |
The test set was used once, after training had finished.
Plain supervised fine-tuning with LoRA on the parallel data. No back-translation, pivot data, monolingual data, adapter averaging or MBR decoding.
| Setting | Value |
|---|---|
| Base model | ai4bharat/indictrans2-indic-indic-1B (frozen, fp16) |
| LoRA target modules | q_proj, k_proj, v_proj, out_proj, fc1, fc2 (encoder self-attention, decoder self-attention, decoder cross-attention, and both FFNs) |
| LoRA rank / alpha / dropout | 96 / 128 / 0.1 |
| Trainable parameters | 106,168,320 (8.08% of 1.31B) |
| Optimiser | AdamW (β = 0.9 / 0.999, ε = 1e-8), weight decay 0.01 |
| Learning rate | 2e-4, cosine schedule, 5% warm-up |
| Label smoothing | 0.1 |
| Gradient clipping | 1.0 |
| Effective batch size | 32 (8 per device × 2 accumulation × 2 GPUs) |
| Epochs | up to 5, early stopping with patience 2 on validation chrF++ |
| Max sequence length | 256 tokens (no pairs exceeded it) |
| Precision | fp16 mixed precision, fp32 LoRA weights |
| Hardware | 2 × NVIDIA Tesla T4 (Kaggle) |
| Software | PyTorch 2.11, Transformers 4.39.3, PEFT 0.10.0 |
| Seed | 42 |
The checkpoint with the highest validation chrF++ was kept. For both directions this was epoch 4.
All scores are on the held-out test set (1,158 sentence pairs), decoded with beam size 5.
BLEU uses SacreBLEU with the flores200 tokenizer. chrF++ uses word_order=2.
| Direction | Model | BLEU | chrF++ |
|---|---|---|---|
| Dogri → Punjabi | IndicTrans2-1B (no adapter) | 45.30 | 58.71 |
| Dogri → Punjabi | + doi2pan adapter |
52.93 | 65.15 |
| Punjabi → Dogri | IndicTrans2-1B (no adapter) | 38.80 | 52.63 |
| Punjabi → Dogri | + pan2doi adapter |
46.38 | 58.75 |
| Direction | BLEU gain | chrF++ gain |
|---|---|---|
| Dogri → Punjabi | +7.63 | +6.45 |
| Punjabi → Dogri | +7.58 | +6.12 |
Pipeline ceiling. Script conversion and tokenisation alone cost a little fidelity. The reference sentences scored chrF++ 97.40 (Punjabi) and 97.51 (Dogri) after being passed through the same pipeline, so the pipeline itself is not a meaningful bottleneck.
The adapter weights are released under the MIT licence, matching the base model (IndicTrans2 is MIT-licensed). The training corpus is subject to its own terms from the SetuNLP organisers. Check those terms before commercial use.
If you use these adapters, please cite the base model and LoRA:
@article{gala2023indictrans2,
title = {IndicTrans2: Towards High-Quality and Accessible Machine Translation Models for all 22 Scheduled Indian Languages},
author = {Jay Gala and Pranjal A. Chitale and Raghavan AK and Varun Gumma and Sumanth Doddapaneni and Aswanth Kumar and Janki Nawale and Anupama Sujatha and Ratish Puduppully and Vivek Raghavan and Pratyush Kumar and Mitesh M. Khapra and Raj Dabre and Anoop Kunchukuttan},
journal = {Transactions on Machine Learning Research},
year = {2023},
url = {https://openreview.net/forum?id=vfT4YuzAYA}
}
@inproceedings{hu2022lora,
title = {LoRA: Low-Rank Adaptation of Large Language Models},
author = {Edward J. Hu and Yelong Shen and Phillip Wallis and Zeyuan Allen-Zhu and Yuanzhi Li and Shean Wang and Lu Wang and Weizhu Chen},
booktitle = {International Conference on Learning Representations},
year = {2022}
}
Rishit Kar, Soham Chandane, Chetashri Bhadane (SetuNLP).
ai4bharat/indictrans2-indic-indic-1B