rishitkar's picture
Update README.md
f90bb9e verified
|
Raw History Blame Contribute Delete
10.2 kB
metadata
language:
  - doi
  - pa
license: mit
library_name: peft
base_model: ai4bharat/indictrans2-indic-indic-1B
pipeline_tag: translation
tags:
  - peft
  - lora
  - translation
  - machine-translation
  - dogri
  - punjabi
  - low-resource
  - indictrans2
  - setunlp
metrics:
  - bleu
  - chrf
model-index:
  - name: SetuNLP Dogri-Punjabi LoRA (doi2pan)
    results:
      - task:
          type: translation
          name: Dogri to Punjabi
        metrics:
          - type: bleu
            value: 52.93
            name: BLEU (held-out test)
          - type: chrf
            value: 65.15
            name: chrF++ (held-out test)
  - name: SetuNLP Dogri-Punjabi LoRA (pan2doi)
    results:
      - task:
          type: translation
          name: Punjabi to Dogri
        metrics:
          - type: bleu
            value: 46.38
            name: BLEU (held-out test)
          - type: chrf
            value: 58.75
            name: chrF++ (held-out test)

SetuNLP: Dogri ⇄ Punjabi LoRA Adapters for IndicTrans2-1B

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.

Repository layout

.
β”œβ”€β”€ README.md
β”œβ”€β”€ doi2pan/
β”‚   β”œβ”€β”€ adapter_config.json
β”‚   └── adapter_model.safetensors
└── pan2doi/
    β”œβ”€β”€ adapter_config.json
    └── adapter_model.safetensors

Quick start

1. Install

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.

2. Translate

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.

Important: script handling

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 data

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

  • Removed zero-width noise characters and applied NFC normalisation (not NFKC, to preserve nukta letters).
  • Script checks: Punjabi lines must be predominantly Gurmukhi, Dogri lines predominantly Devanagari.
  • Length checks: 2–120 words per side, maximum length ratio of 3.0, and no identical source and target.
  • LaBSE filter: dropped pairs below a cosine similarity of max(0.55, 5th percentile). This removed 4,798 likely misaligned pairs.
  • Duplicates were removed across the full set, so no sentence appears in more than one split.

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.

Training procedure

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.

Evaluation

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.

Intended use

  • Research and experimentation on Dogri ⇄ Punjabi machine translation.
  • A starting point for further fine-tuning on additional or domain-specific Dogri data.
  • Draft translation assistance with human review.

Limitations and responsible use

  • Domain. The training and test data come from a single parallel corpus whose content looks agriculture and general-information oriented. Quality on other domains (legal, medical, news, conversational or literary text) has not been measured and is likely lower.
  • Small data. About 21k training pairs were used. Rare words, named entities, idioms and long sentences may be mistranslated, dropped or hallucinated.
  • Single split. Results come from one random split with one seed. They do not include variance estimates or human evaluation.
  • Dogri orthography. Dogri is written in Devanagari here. Spelling conventions vary between sources, and the models reflect the conventions of the training corpus.
  • Not for high-stakes use. Do not rely on these models without human review for legal, medical, safety-critical or official translation.
  • Biases and errors present in the base model and the training corpus may carry over.

Licence

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.

Citation

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}
}

Authors

Rishit Kar, Soham Chandane, Chetashri Bhadane (SetuNLP).