Downloads · 30 days
0
0% of all-time downloads
ogx786/urdu-roman-transliterator-tiny-aya-V3
urdu-roman-transliterator-tiny-aya-V3 is a text generation model from ogx786. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as cc-by-nc-4.0.
This model transliterates Urdu script text into Roman Urdu (Urdu written in Latin script), fine-tuned from CohereLabs/tiny-aya-global using QLoRA.
Downloads · 30 days
0
0% of all-time downloads
All-time downloads
16
Public
Parameters
3.3B
7 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors6.7 GB · 100%
From the Hugging Face model README
This model transliterates Urdu script text into Roman Urdu (Urdu written in Latin script), fine-tuned from CohereLabs/tiny-aya-global using QLoRA.
Unlike translation, this is a transliteration task: the output preserves the original words and meaning, just rendered in Latin script instead of Urdu script.
Example:
| Urdu Input | Roman Urdu Output |
|---|---|
| کیا حال ہے؟ | kya haal hai? |
CohereLabs/tiny-aya-global (3.35B parameters, Cohere2 architecture)Trained on ~80,000 Urdu ↔ Roman Urdu sentence pairs, combining two sources:
Qasim522/Roman-Urdu-Parl-split (Hugging Face)Split as 70,000 train / 5,000 validation / 5,000 test, deduplicated and shuffled before splitting.
This model was trained on a strict instruction format. Inference must match this format exactly, or output quality will degrade:
### Instruction:
Transliterate the following Urdu text into Roman Urdu.
Output ONLY the Roman Urdu. No translation. No explanation.
### Input:
{urdu_text}
### Response:
The model was trained to generate only the Roman Urdu text after ### Response:\n, followed by an end-of-sequence token. It was not trained to add explanations, translations, or any other content.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_ID = "ogx786/urdu-roman-transliterator-tiny-aya-V3"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
torch_dtype=torch.float16,
device_map="auto",
)
model.eval()
PROMPT_TEMPLATE = """### Instruction:
Transliterate the following Urdu text into Roman Urdu.
Output ONLY the Roman Urdu. No translation. No explanation.
### Input:
{urdu_text}
### Response:
"""
def transliterate(urdu_text: str, max_new_tokens: int = 128) -> str:
prompt = PROMPT_TEMPLATE.format(urdu_text=urdu_text)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False, # deterministic output for transliteration
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.eos_token_id,
)
# Decode only the newly generated tokens, not the prompt
new_tokens = output_ids[0][inputs["input_ids"].shape[1]:]
result = tokenizer.decode(new_tokens, skip_special_tokens=True)
# Safety net: if the model ever continues past the response
# (e.g. starts a new "### Instruction:" block), cut it off there.
result = result.split("### Instruction:")[0].split("### Input:")[0].strip()
return result
if __name__ == "__main__":
examples = [
"کیا حال ہے؟",
"میں ٹھیک ہوں، شکریہ۔",
]
for urdu in examples:
print(f"Urdu: {urdu}")
print(f"Roman: {transliterate(urdu)}")
print()
For transliterating many sentences, batch the prompts together rather than calling generate in a loop:
def transliterate_batch(urdu_texts: list[str], max_new_tokens: int = 128) -> list[str]:
prompts = [PROMPT_TEMPLATE.format(urdu_text=u) for u in urdu_texts]
tokenizer.padding_side = "left" # required for correct batched generation
inputs = tokenizer(prompts, return_tensors="pt", padding=True).to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.eos_token_id,
)
results = []
for i in range(len(urdu_texts)):
new_tokens = output_ids[i][inputs["input_ids"].shape[1]:]
text = tokenizer.decode(new_tokens, skip_special_tokens=True)
text = text.split("### Instruction:")[0].split("### Input:")[0].strip()
results.append(text)
return results
do_sample=False (greedy decoding) is recommended for this task since transliteration should be deterministic; sampling may introduce inconsistency.If you use this model, please cite the base model:
@misc{tinyaya,
title = {Cohere Labs Tiny Aya},
author = {Cohere Labs},
year = {2026},
url = {https://huggingface.co/CohereLabs/tiny-aya-global}
}