Neura commited on
Commit
2bd9669
·
verified ·
1 Parent(s): 33f9c7c

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +158 -0
README.md ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - fa
4
+ tags:
5
+ - g2p
6
+ - grapheme-to-phoneme
7
+ - persian
8
+ - farsi
9
+ - text-to-speech
10
+ - tts
11
+ - phonetics
12
+ - speech-synthesis
13
+ - seq2seq
14
+ library_name: transformers
15
+ pipeline_tag: translation
16
+ ---
17
+
18
+ # Neura Persian G2P (`Neurai/Persian_G2P`)
19
+
20
+ Welcome to the **Neura Persian G2P (Grapheme-to-Phoneme)** model repository by [Neurai](https://huggingface.co/Neurai). This Sequence-to-Sequence (`Seq2SeqLM`) model converts Persian (Farsi) text orthography (graphemes) into accurate phonetic transcriptions (phonemes), serving as an essential frontend component for Text-to-Speech (TTS), Automatic Speech Recognition (ASR), and Persian NLP pipelines.
21
+
22
+ ## Overview
23
+
24
+ Written Persian omits short vowels (*a*, *e*, *o*) in everyday orthography and relies heavily on context for grammatical constructs such as the *Ezafe* (`-e` / `-ye`), silent letters (e.g., *vav* in «خواهر»), and colloquial pronunciations. `Neurai/Persian_G2P` handles both formal and conversational Persian sentences to output reliable phonetic sequences.
25
+
26
+ * **Developed by:** [Neurai (Neura.info)](https://huggingface.co/Neurai)
27
+ * **Model Repository:** [Neurai/Persian_G2P](https://huggingface.co/Neurai/Persian_G2P)
28
+ * **Architecture:** `AutoModelForSeq2SeqLM` (Transformers)
29
+ * **Language:** Persian (`fa`)
30
+ * **Task:** Grapheme-to-Phoneme (G2P) / Phonetic Transcription
31
+
32
+ ## Installation
33
+
34
+ Install the required dependencies using `pip`:
35
+
36
+ ```bash
37
+ pip install torch transformers gradio
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Python Inference
43
+
44
+ You can run inference directly using `transformers` and `torch`:
45
+
46
+ ```python
47
+ import torch
48
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
49
+
50
+ MODEL_ID = "Neurai/Persian_G2P"
51
+
52
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
53
+
54
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
55
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID).to(device)
56
+ model.eval()
57
+
58
+ def text_to_phoneme(text: str) -> str:
59
+ if not text.strip():
60
+ return ""
61
+
62
+ with torch.no_grad():
63
+ inputs = tokenizer(
64
+ text,
65
+ return_tensors="pt",
66
+ padding=True,
67
+ truncation=True
68
+ ).to(device)
69
+
70
+ outputs = model.generate(
71
+ **inputs,
72
+ max_new_tokens=128,
73
+ do_sample=False
74
+ )
75
+
76
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
77
+
78
+ sample_text = "نه بابا چی میگی این عدده نه هزار رو پانصد و بیست و نه هست"
79
+ phonemes = text_to_phoneme(sample_text)
80
+
81
+ print("Grapheme:", sample_text)
82
+ print("Phoneme :", phonemes)
83
+ ```
84
+
85
+ ### Gradio Web Demo
86
+
87
+ Launch an interactive web interface locally with Gradio:
88
+
89
+ ```python
90
+ import gradio as gr
91
+ import torch
92
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
93
+
94
+ MODEL_ID = "Neurai/Persian_G2P"
95
+
96
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
97
+
98
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
99
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID).to(device)
100
+ model.eval()
101
+
102
+ def generate(text):
103
+ if not text.strip():
104
+ return ""
105
+
106
+ with torch.no_grad():
107
+ inputs = tokenizer(
108
+ text,
109
+ return_tensors="pt",
110
+ padding=True,
111
+ truncation=True
112
+ ).to(device)
113
+
114
+ outputs = model.generate(
115
+ **inputs,
116
+ max_new_tokens=128,
117
+ do_sample=False
118
+ )
119
+
120
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
121
+
122
+ demo = gr.Interface(
123
+ fn=generate,
124
+ inputs=gr.Textbox(
125
+ lines=4,
126
+ label="Grapheme",
127
+ value="نه بابا چی میگی این عدده نه هزار رو پانصد و بیست و نه هست"
128
+ ),
129
+ outputs=gr.Textbox(lines=4, label="Phoneme"),
130
+ title="Neura Persian G2P"
131
+ )
132
+
133
+ demo.launch()
134
+ ```
135
+
136
+ ## Limitations & Considerations
137
+
138
+ * **Sequence Length:** The default generation configuration uses `max_new_tokens=128`. For very long paragraphs, split input text into sentence-level chunks before running inference.
139
+ * **Homographs:** Context-dependent Persian homographs (words spelled identically with different meanings and pronunciations) rely on surrounding sentence context for accurate disambiguation.
140
+ * **Out-of-Vocabulary Terms:** Rare foreign loanwords, technical jargon, or uncommon named entities may occasionally produce fallback phonetic approximations.
141
+
142
+ ## Citation
143
+
144
+ If you use this model in your research, TTS pipeline, or production system, please cite:
145
+
146
+ ```bibtex
147
+ @misc{neurai_persian_g2p_model,
148
+ author = {Neurai},
149
+ title = {Neura Persian G2P: Neural Grapheme-to-Phoneme Model for Persian},
150
+ year = {2025},
151
+ publisher = {Hugging Face},
152
+ url = {https://huggingface.co/Neurai/Persian_G2P}
153
+ }
154
+ ```
155
+
156
+ ## License
157
+
158
+ Please refer to the repository metadata and `LICENSE` file in [Neurai/Persian_G2P](https://huggingface.co/Neurai/Persian_G2P) for usage and redistribution permissions.