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 internal 1 ezafe 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 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.

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 (خُداوَندِ مِهرَبان, گُلِ قِرمِز روی میز اَست, پُر اَز گِل شُد).

Benchmark Comparison


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-4 cosine).

Credits & License

  • License: MIT (inherits from MahtaFetrat/Homo-GE2PE-Persian; base google/byt5-small is Apache-2.0; training dataset HomoRich-G2P-Persian is 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
Safetensors
Model size
8.26M params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for mehdi-hf/persian-g2p-tiny

Finetuned
(2)
this model

Dataset used to train mehdi-hf/persian-g2p-tiny

Paper for mehdi-hf/persian-g2p-tiny