Downloads · 30 days
41
10% of all-time downloads
ai4bharat/bhili-translate-mar-bhb
bhili-translate-mar-bhb is a translation model from ai4bharat. Use it when you need text moved from one language to another. It is set up for peft. The card lists the license as mit.
Machine Translation (MT) model for model for Bhili (भीली), specifically the Dehvali Bhili dialect, an Indo-Aryan language spoken by the Bhil community in western India.
Downloads · 30 days
41
10% of all-time downloads
All-time downloads
414
Public
Repo size
346 MB
Likes
0
Public
Click a slice to open those files.
.safetensors308 MB · 88%
From the Hugging Face model README
Machine Translation (MT) model for model for Bhili (भीली), specifically the Dehvali Bhili dialect, an Indo-Aryan language spoken by the Bhil community in western India.
This is a fine-tuned LoRA adapter on top of sarvamai/sarvam-translate, trained on ~40,000 Bhili-Marathi parallel sentences covering general domain text with additional focus on agricultural domain vocabulary and terminology.
Direction: Marathi (mr) → Bhili (bhb)
For the reverse direction (Bhili → Marathi), see ai4bharat/bhili-translate-bhb-mar.
The recommended inference recipe combines three things:
num_beams=4) instead of greedy. Improves decoding quality without retraining.glossary.json, included in this repo) containing 6,400+ Marathi↔Bhili term pairs reviewed by native Bhili speakers.post_edit.py, included in this repo) that substitutes terms the model left in Marathi with their Bhili equivalents from the glossary.This addresses the most common failure mode observed in production: agricultural crop names, scheme names, and technical terms passing through untranslated.
⚠️ For the best results, we strongly recommend using the Translate Gemma system prompt when interacting with this model. Using the recommended system prompt helps ensure more consistent and accurate translation outputs.
pip install torch transformers peft accelerate huggingface_hub
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
from huggingface_hub import hf_hub_download
# Load base model + adapter
base_model_name = "sarvamai/sarvam-translate"
adapter_name = "ai4bharat/bhili-translate-mar-bhb"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
model = AutoModelForCausalLM.from_pretrained(
base_model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
)
model = PeftModel.from_pretrained(model, adapter_name)
model.eval()
# Load glossary + post-edit module from this repo
glossary_path = hf_hub_download(adapter_name, "glossary.json")
post_edit_path = hf_hub_download(adapter_name, "post_edit.py")
import importlib.util
spec = importlib.util.spec_from_file_location("post_edit", post_edit_path)
pe = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pe)
glossary = pe.load_glossary(glossary_path)
# Translate
def translate(text: str) -> str:
messages = [
{
"role": "system",
"content": (
"You are a professional Marathi (mr) to Bhili (bhb) translator. "
"Your goal is to accurately convey the meaning and nuances of the "
"original Marathi text while adhering to Bhili grammar, vocabulary, "
"and cultural sensitivities. Produce only the Bhili translation, "
"without any additional explanations or commentary. Please translate "
"the following Marathi text into Bhili:"
),
},
{"role": "user", "content": text},
]
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
with torch.no_grad():
output = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
num_beams=4,
early_stopping=True,
)
raw = tokenizer.decode(
output[0][len(inputs.input_ids[0]):],
skip_special_tokens=True,
).strip()
# Apply glossary post-edit
edited, _edits = pe.post_edit(
text, raw, glossary["mar2bhb_sorted_keys"], glossary["mar2bhb"]
)
return edited
# Example
print(translate("शेतकऱ्यांना सकाळी फवारणी करणे आवश्यक आहे."))
print(translate("कापसावरील गुलाबी बोंडअळीसाठी कॉपर ऑक्सिक्लोराईड फवारा."))
This model was predominantly trained on agricultural-domain data. As a result, performance on domains outside agriculture may vary and may not be representative of the performance observed on agricultural-domain.