Downloads · 30 days
34
7% of all-time downloads
AminMadani/persian-byt5-g2p
persian-byt5-g2p is a machine learning model from AminMadani. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
[](https://huggingface.co/AminMadani/persian-byt5-g2p) [](https://huggingface.co/datasets/MahtaFetrat/KaamelDict) [](https://www.gnu.org/licenses/gpl-3.0)
Downloads · 30 days
34
7% of all-time downloads
All-time downloads
474
Public
Parameters
300M
1.2 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors1.2 GB · 100%
From the Hugging Face model README
A lightweight, robust Grapheme-to-Phoneme (G2P) model for Persian, fine-tuned on the comprehensive KaamelDict dictionary (~116,600 phonetic entries) using Google's byte-level google/byt5-small architecture.
Traditional word-piece / subword tokenizers struggle with Persian orthography due to rich morphology (prefixes, suffixes, compound words) and informal spacing.
ByT5 operates directly on raw UTF-8 bytes, providing key advantages:
خوش $\to$ /x o S/ (pronounced with o instead of v).google/byt5-small (300M parameters)5e-4 with AdamW0.03755Evaluated on the official SentenceBench (ICASSP 2025) test suite across 400 complex Persian sentences using the word-level batched inference pipeline:
| Benchmark Subset | Number of Sentences | Phoneme Error Rate (PER) | Accuracy |
|---|---|---|---|
| CommonVoice | 88 | 8.55% | 91.45% |
| Mana-TTS | 100 | 8.94% | 91.06% |
| Homograph Sentences | 212 | 10.78% | 89.22% |
| Overall Performance | 400 | 9.64% | 90.36% |
?AyAbAyadhaqiqatrAbe?AnhAbeguyim (100% exact match).| Persian Orthography | Model Output (Phonemes) | Note |
|---|---|---|
| دانشگاه | d A n e S g A h | Inferred short vowel kasreh (e) |
| کامپیوتر | k A m p i y u t e r | English loanword phonetic mapping |
| خوشآمدید | x o S A m a d i d | Orthographic rule: خو $\to$ /xo/ |
| هوش مصنوعی | h u S e m a s n u ? i | Ezafe connector (e) + glottal stop (?) |
| تلفظ | t a l a f f o z | Inferred gemination / tashdid (ff) |
| واترپولو | v A t e r p o l o | Complex compound loanword |
| دربازکن | d a r b A z k o n | Persian compound with short vowels |
git clone https://github.com/aminmadaniofficial/persian-byt5-g2p.git
cd persian-byt5-g2p
pip install -r requirements.txt
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
MODEL_ID = "AminMadani/persian-byt5-g2p"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
device = "cuda" if torch.cuda.is_available() else "cpu"
model = model.to(device)
def text_to_phonemes(text: str) -> str:
inputs = tokenizer(text, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=128,
num_beams=2,
early_stopping=True
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
print(text_to_phonemes("دانشگاه"))
# Output: d A n e S g A h
Or using the built-in helper class:
from inference import PersianG2P
g2p = PersianG2P()
print(g2p.predict(["دانشگاه", "کامپیوتر"]))
# Output: ['d A n e S g A h', 'k A m p i y u t e r']
# Run interactive transcription shell
python inference.py --interactive
# Transcribe a single word
python inference.py --text "دانشگاه"
The complete training script with Google Drive export and Hugging Face Hub integration is provided in notebook.ipynb. You can run it directly on Google Colab's free T4 GPU tier.
If you use this model or the KaamelDict dataset, please cite the original papers:
@inproceedings{qharabagh2025llm,
title={LLM-Powered Grapheme-to-Phoneme Conversion: Benchmark and Case Study},
author={Qharabagh, Mahta Fetrat and Dehghanian, Zahra and Rabiee, Hamid R},
booktitle={ICASSP 2025-2025 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
pages={1--5},
year={2025},
organization={IEEE}
}
@article{xue2022byt5,
title={ByT5: Towards a token-free future with pre-trained byte-to-byte models},
author={Xue, Linting and Barua, Aditya and Constant, Noah and Al-Rfou, Rami and Narang, Sharan and Kale, Mihir and Roberts, Adam and Raffel, Colin},
journal={Transactions of the Association for Computational Linguistics},
volume={10},
pages={291--306},
year={2022}
}
This project is released under the GNU General Public License v3.0 (GPL-3.0), consistent with the KaamelDict source dataset.