--- language: - he license: apache-2.0 library_name: pytorch tags: - hebrew - g2p - phonemization - phonemes --- # pitput phonemizer A Hebrew grapheme-to-phoneme model: plain text in, IPA with stress out. **10,083,873 parameters**, about 40 MB. It reads a whole sentence at once, so the same letters can be two different words, and it can take the gender of the speaker and of the person being spoken to. It is the pronunciation front end of [pitput](https://huggingface.co/useless-ai/pitput), a 5M-parameter Hebrew text-to-speech model. This release is the phonemizer on its own. A name, a form of address or the story is enough to choose לך, אותך, אמרת and the rest. ## Usage ```bash pip install torch ``` ```python from phonemizer import Phonemizer g2p = Phonemizer.from_pretrained("useless-ai/pitput-phonemizer") g2p("שלום, מה שלומך?") # ʃalˈom, mˈa ʃlomχˈa? g2p("דנה, מה שלומך?") # the name is the cue # dˈana, mˈa ʃlomˈeχ? g2p("דנה, מה שלומך?", listener="m") # an explicit listener wins # dˈana, mˈa ʃlomχˈa? g2p("אני בודקת את זה", speaker="f") # ʔanˈi bodˈeket ʔˈet zˈe g2p("המחיר 1250 שקלים") # digits are read as words first # hameχˈiʁ ʔˈelef matˈajim veχamiʃˈim ʃkalˈim ``` From the command line, reading UTF-8 from a file or from the argument: ```bash python phonemizer.py --text "דנה, מה שלומך?" python phonemizer.py --text-file story.txt --listener f --speaker f ``` | Argument | Meaning | |---|---| | `listener` | Who is being spoken to. Omitted: decide from the sentence. `"f"` or `"m"`: use that form for לך, אותך, שלך, אמרת, ראית and the rest. `"m"` overrides a feminine name. | | `speaker` | Who is speaking. Omitted: unknown. `"f"` / `"m"`: first-person forms such as בודקת / בודק. | | `0` / `1` / `2` | The same two arguments as integers: unknown, man, woman. | Niqqud is optional. A pointed letter is followed; an unpointed letter is still predicted from the sentence. Kamatz may be *a* or *o*, and shva may be *e* or silent, because the mark itself allows both. Stress is predicted either way: ordinary niqqud does not write it. Text longer than 512 characters is split on sentence ends, then on commas, then on spaces. ## Model A character transformer. - One id per character (Hebrew letters, punctuation, digits, Latin letters and a few symbols), plus an optional vowel mark and consonant mark on that character, plus a speaker id and a listener id. - 8 transformer layers, 320 channels, 5 heads, pre-norm, GELU, feed-forward width 1,280. - Three heads on every character: 25 consonants, 6 vowels, stressed or not. Empty is one of the classes, so a letter can be silent (א, ע, ה) or vowelless. - Decoding picks the best legal consonant and vowel for each letter, and one stressed vowel in the word. A geresh rewrites צ כ ג as tʃ, χ, dʒ. A final ח before a pause is aχ. ## Limitations - בין and בית are read with *ej* (`bˈejn`, `bˈejt`). - With both inputs unknown, "ראית את הסרט החדש, מיכל?" is read as masculine. Set `listener` or `speaker` when the sentence does not carry the cue on its own. - Foreign words written in Hebrew letters are pronounced as Hebrew. Acronyms are left as written. - The number reading is a fixed set of rules, up to thousands, dates, times and a few fractions. - This package returns a pronunciation. For audio, use [pitput](https://huggingface.co/useless-ai/pitput). ## License Apache License 2.0, for the code and the weights. RenikudPlus is by notmax123, Apache-2.0. The decoding and the number expander shipped here (`renikud_onnx.py`) are taken from its wrapper; see `NOTICE`. The transformer and its weights are trained by us. ## Files | File | Contents | |---|---| | `model.safetensors` | The 10.1M weights | | `config.json` | Width, layers, the character inventory, consonant and vowel names | | `phonemizer.py` | `Phonemizer`, including `from_pretrained`, and the command line | | `renikud_onnx.py` | Decoding and number expansion from RenikudPlus | | `NOTICE`, `LICENSE` | Attribution and the Apache license | ## Acknowledgements [RenikudPlus](https://huggingface.co/notmax123/RenikudPlus) for the per-letter distributions, the decoder and the number expander, and the text: Hebrew Wikipedia, HeDC4, news archives, HeSum and ivrit.ai.