Instructions to use mehdi-hf/persian-g2p-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mehdi-hf/persian-g2p-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-speech", model="mehdi-hf/persian-g2p-tiny")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("mehdi-hf/persian-g2p-tiny") model = AutoModelForSeq2SeqLM.from_pretrained("mehdi-hf/persian-g2p-tiny", device_map="auto") - Notebooks
- Google Colab
- Kaggle
persian-g2p-tiny
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.
Key Improvements Over Homo-GE2PE-Persian-HF
- Clean standard Repr. 1 output directly — no custom post-mapping (
/→a,@→?,$→S,c→C) and no leaked internal1ezafe flags. - Explicit ezafe markers (
-e/-ye) — e.g.,ketAb-e jadid-e man(trivially convertible to flat phonemes or IPA). - 100% Kasra (
ـِ) override — typing explicit Persian kasra (کتابِ من) deterministically forces ezafe. - Zero Parsivar / zero GPL dependencies — runs directly via
transformers.T5ForConditionalGeneration. - Strictly leak-free evaluation — all 403 overlapping
SentenceBenchrows and 91,040 duplicates were removed fromHomoRichprior to training (0% test overlap), yetpersian-g2p-tinystill beats the leaked baseline on PER, WER, Ezafe F1, and throughput.
Benchmarks (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.21% | 3.35% | 15.46% | 69.34% | 77.16% | 86.16% (80.5 / 92.7) | 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 |
Full Diacritic Support (ـَ 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:
- Word-final Kasra (
ـِ) ezafe override:10/10(100%) - Full
ـَ / ـِ / ـُDiacritic Suite (22 homograph & general items):18/22(81.82%) — 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 (خُداوَندِ مِهرَبان,گُلِ قِرمِز روی میز اَست,پُر اَز گِل شُد).
Usage
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']
Converting Repr. 1 Output to IPA
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()
)
Phoneme Notation (Repr. 1)
| 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 |
Training Details
- Dataset:
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). - Hardware: 1× NVIDIA A100-40GB, bf16, 3 epochs (10,908 steps, effective batch 128, AdamW
lr=5e-4cosine).
Credits & License
- License: MIT (inherits from
MahtaFetrat/Homo-GE2PE-Persian; basegoogle/byt5-smallis Apache-2.0; training datasetHomoRich-G2P-Persianis CC0-1.0). - Data & Original Model Credit: Elnaz Rahmati, Mahta Fetrat Qharabagh et al. (Fast, Not Fancy: Rethinking G2P with Rich Data and Rule-Based Models, arXiv:2505.12973).
- Downloads last month
- 123
Model tree for mehdi-hf/persian-g2p-tiny
Base model
MahtaFetrat/Homo-GE2PE-Persian