A decoder-only transformer with 17.3 million parameters that writes an Urdu sentence from one to four Urdu keywords. The sentence can mix Urdu and English.
| Property | Value |
|---|---|
| Architecture | Decoder-only transformer, pre-norm, RMSNorm, SwiGLU, learned positions, tied output head |
| Layers, width, heads | 8, 384, 6 |
| Parameters | 17,283,456 (14,162,304 outside the embeddings) |
| Vocabulary | 8000 BPE pieces (SentencePiece), trained on the Urdu corpus and the keywords |
| Context | 128 tokens |
| Precision | float32 weights, 69 MB |
The prompt is the BOS token, the keywords joined by +, and the <sep> token. The model writes the
sentence and ends it with the EOS token. config.json holds the token ids.
modeling.py holds the model class and generation.py the beam search.
import json
import sentencepiece as spm
from safetensors.torch import load_file
from generation import beam_search
from modeling import Transformer
config = json.load(open("config.json"))
tok = spm.SentencePieceProcessor(model_file="tokenizer.model")
model = Transformer.from_state_dict(load_file("model.safetensors"))
keywords = ["میں", "پانی", "چاہیے"]
prompt = [config["bos_token_id"], *tok.encode(" + ".join(keywords)), config["sep_token_id"]]
sentences = beam_search(model, prompt, config["eos_token_id"], beams=5, max_new=40, length_alpha=0.7)
for tokens in sentences[:3]:
print(tok.decode(tokens))
Output:
مجھے پانی چاہیے۔
مجھے پانی چاہیے ہے۔
میں پانی چاہتا ہوں۔
The evaluation below used beam search with 5 beams and returned the three best sentences.
The pairs combine 2,575 Tatoeba sentences and 5,290 web sentences that a
language model mapped back to keywords, and 13,191 sentences that a language model
(gemma4:e4b) wrote for sampled keyword selections. Pairs that match an evaluation case were removed.
125 held-out keyword selections (93 Urdu, 32 code-mixed) with reference sentences. Exact match compares normalised sentences.
| Metric | Seed 0 (this model) | Mean of seeds 0 to 2 |
|---|---|---|
| Exact match at 1 | 0.408 | 0.427 |
| Exact match at 3 | 0.728 | 0.728 |
| Urdu cases, exact match at 3 | 0.806 | 0.803 |
| Code-mixed cases, exact match at 3 | 0.500 | 0.510 |
| Judge acceptance of the top sentence | 0.880 | |
| Latency, median of beam search | 18 ms |
The judge is qwen3.5:9b, which accepted 0.952 of the reference sentences and
0.008 of mismatched ones. The mT5-small baseline fine-tuned on the same pairs reaches
exact match at 3 of 0.608.
Pretraining text: CC-100 (Urdu), Urdu Wikipedia (wikimedia/wikipedia, snapshot 20231101.ur) and
Tatoeba. Fine-tuning pairs: keyword selections with a sentence, built from Tatoeba, web sentences and
sentences written by gemma4:e4b.
The fine-tuning pairs and the Tatoeba sentences are in
https://github.com/syedtaha22/goyai-experiments, folder models/inputs/data/ (pairs.tar.xz and
tatoeba_ur.jsonl.xz). The code in models/steps/corpus/ builds the training sets from them.
Apache License 2.0. The text is in LICENSE, and the sources of the training text are credited in
NOTICE.