A fast, 8.26M-parameter (16 MB) Persian (Farsi) Grapheme-to-Phoneme (G2P) model with explicit ezafe restoration (-e / -ye), homograph disambiguation, and 100% deterministic kasra (ـِ) override support.
Fine-tuned from mehdi-hf/Homo-GE2PE-Persian-HF (2+2-layer ByT5) on a strictly leak-free, deduplicated, CC0-1.0 version of MahtaFetrat/HomoRich-G2P-Persian with kasra-override augmentation.
For higher homograph and ezafe accuracy (596M parameters, Apache-2.0), see the sibling flagship model: mehdi-hf/persian-g2p-0.6b.
Homo-GE2PE-Persian-HF/→a, @→?, $→S, c→C) and no leaked internal 1 ezafe flags.-e / -ye) — e.g., ketAb-e jadid-e man (trivially convertible to flat phonemes or IPA).ـِ) override — typing explicit Persian kasra (کتابِ من) deterministically forces ezafe.transformers.T5ForConditionalGeneration.SentenceBench rows and 91,040 duplicates were removed from HomoRich prior to training (0% test overlap), yet persian-g2p-tiny still beats the leaked baseline on PER, WER, Ezafe F1, and throughput.SentenceBench, 400 rows)| Model | Params | License | Leak-Free? | Valid PER ↓ (4k) | SB PER ↓ | SB PER (glottal) ↓ | SB WER ↓ | Official Homograph ↑ (212) | All-Ambig Homograph ↑ (359) | Ezafe F1 ↑ (P / R) | Kasra Override | Speed (A100) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Baseline (Homo-GE2PE) |
8.26M | MIT | No (403 leaked) | — | 3.21% | 3.39% | 16.04% | 70.28% | 77.44% | 86.76% (84.2 / 89.5) | 10/10 | 43.7 s/s |
persian-g2p-tiny (this) |
8.26M | MIT | Yes (0 leak) | 1.81% | 3.23% | 3.35% | 15.37% | 69.34% | 77.16% | 87.10% | 10/10 | 49.2 s/s |
persian-g2p-0.6b |
596M | Apache-2.0 | Yes (0 leak) | 1.58% | 3.18% | 3.35% | 14.79% | 72.17% | 80.50% | 88.89% (83.1 / 95.5) | 10/10 | 26.5 s/s |
ـَ fatha, ـِ kasra, ـُ damma)Because persian-g2p-tiny is byte-level (ByT5), it handles Persian diacritics with zero subword breakage. After a 2-epoch continuation fine-tune on 256k balanced plain + kasra + internal-vowel diacritized examples:
ـِ) ezafe override: 10/10 (100%)ـَ / ـِ / ـُ Diacritic Suite (22 homograph & general items): 19/22 (86.36%) — including گُل (gol) vs گِل (gel), مَرد (mard) vs مُرد (mord), قَدر (qadr) vs قَدَر (qadar), طِبق (tebq) vs طَبَق (tabaq), کَرَم (karam) vs کِرِم (kerem), شِش (SeS) vs شُش (SoS), بَعد (ba?d) vs بُعد (bo?d), and full-sentence diacritics (خُداوَندِ مِهرَبان, گُلِ قِرمِز روی میز اَست, پُر اَز گِل شُد).ژ (/ʒ/ → Z) Suite (27 words): 27/27 (100%) — nails every word-initial, medial, and final ژ (ژاپن → ZApon, ژاپنی → ZAponi, آژانس → ?AZAns, شارژ → SArZ, شارژر → SArZer, انرژی → ?enerZi, پروژه → proZe, ویژه → viZe, پژوهش → paZuheS, رژیم → reZim, ژنتیک → Zenetik, ژاکت → ZAket).import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
REPO = "mehdi-hf/persian-g2p-tiny"
tok = AutoTokenizer.from_pretrained(REPO)
model = T5ForConditionalGeneration.from_pretrained(REPO).eval()
def g2p(sentences: list[str], num_beams: int = 4) -> list[str]:
enc = tok(sentences, padding=True, truncation=True, max_length=512, return_tensors="pt")
with torch.no_grad():
out = model.generate(
enc["input_ids"],
attention_mask=enc["attention_mask"],
num_beams=num_beams,
max_new_tokens=384,
)
return [s.strip() for s in tok.batch_decode(out, skip_special_tokens=True)]
print(g2p([
"نشست سران سیاسی کشورها به خوبی پیش رفت",
"کتابِ جدیدِ من روی میز است",
]))
# ['neSast-e sarAn-e siyAsi-ye keSvarhA be xubi piS raft',
# 'ketAb-e jadid-e man ru-ye miz ?ast']
REPR1_TO_IPA = {
"a": "æ", "A": "ɒː", "e": "e", "o": "o", "i": "iː", "u": "uː",
"p": "p", "b": "b", "t": "t", "d": "d", "k": "k", "g": "ɡ", "q": "q", "?": "ʔ",
"f": "f", "v": "v", "s": "s", "z": "z", "S": "ʃ", "Z": "ʒ", "x": "x", "h": "h",
"C": "tʃ", "j": "dʒ", "m": "m", "n": "n", "l": "l", "r": "ɾ", "y": "j",
}
def to_ipa(repr1: str) -> str:
return " ".join(
"".join(REPR1_TO_IPA.get(ch, "") for ch in w.replace("-", ""))
for w in repr1.split()
)
| Symbol | IPA | Persian Sound | Example |
|---|---|---|---|
a |
/æ/ |
short a (ـَ) |
dard (درد) |
A |
/ɒː/ |
long ā (آ / ا) |
mAh (ماه) |
e |
/e/ |
short e (ـِ) |
zehn (ذهن) |
o |
/o/ |
short o (ـُ) |
zohr (ظهر) |
i |
/iː/ |
long i (ای) |
miz (میز) |
u |
/uː/ |
long u (او) |
dust (دوست) |
S |
/ʃ/ |
ش |
Sahr (شهر) |
C |
/tʃ/ |
چ |
Catr (چتر) |
Z |
/ʒ/ |
ژ |
ZAle (ژاله) |
q |
/q, ɣ/ |
ق / غ |
qazA (غذا) |
x |
/x/ |
خ |
xAk (خاک) |
? |
/ʔ/ |
glottal stop (ع / ء) |
?omr (عمر) |
-e, -ye |
/e/, /je/ |
explicit ezafe suffix | ketAb-e man |
MahtaFetrat/HomoRich-G2P-Persian (CC0-1.0), cleaned & deduplicated (423,769 base train + 41,742 kasra-augmented = 465,511 train; 4,000 valid; 0 SentenceBench overlap).lr=5e-4 cosine).MahtaFetrat/Homo-GE2PE-Persian; base google/byt5-small is Apache-2.0; training dataset HomoRich-G2P-Persian is CC0-1.0).mehdi-hf/Homo-GE2PE-Persian-HF