A
QLoRA adapter for Modi script → Devanagari (Marathi) transliteration,
fine-tuned on
MoDeTrans
(real handwritten Modi documents)
plus SynthMoDe
(synthetic Modi images rendered from the same Devanagari text using Modi fonts).
The majority of examples fall in the "fair" tier — usable as a first draft for expert review.
Synthetic data gave a small but consistent improvement, mainly reducing poor-tier examples.
Vowel-length confusion was unchanged (font rendering does not capture that ambiguity).
1from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor, BitsAndBytesConfig
2from peft import PeftModel
3from PIL import Image
4import torch
5
6MODEL_ID = "Qwen/Qwen2.5-VL-3B-Instruct"
7ADAPTER_ID = "lgtk/qwen25vl-3b-modi-synth-lora" # ← this repo
8
9bnb = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16,
13)
14base = Qwen2_5_VLForConditionalGeneration.from_pretrained(
15 MODEL_ID, quantization_config=bnb, device_map="auto")
16model = PeftModel.from_pretrained(base, ADAPTER_ID)
17model.eval()
18processor = AutoProcessor.from_pretrained(MODEL_ID, max_pixels=512 * 28 * 28)
19
20PROMPT = (
21 "This image contains handwritten text in Modi script, a historical cursive "
22 "script used to write the Marathi language. "
23 "Transliterate the text in this image into Devanagari script. "
24 "Output only the Devanagari text, with no explanation."
25)
26
27image = Image.open("your_modi_image.jpg").convert("RGB")
28messages = [{
29 "role": "user",
30 "content": [
31 {{"type": "image", "image": image}},
32 {{"type": "text", "text": PROMPT}},
33 ],
34}]
35text_in = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
36inputs = processor(text=[text_in], images=[image], return_tensors="pt").to(model.device)
37
38with torch.no_grad():
39 out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
40
41result = processor.batch_decode(
42 out[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True
43)[0].strip()
44print(result)