### Install and Sync Dependencies with uv Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Installs uv and synchronizes project dependencies. This is the initial setup step for the project. ```console pip install uv uv sync ``` -------------------------------- ### Install Phonikud and ONNX Model Source: https://github.com/thewh1teagle/phonikud/blob/main/README.md Installs the necessary Python packages for Phonikud and its ONNX runtime. This is the first step to using the library for Hebrew grapheme-to-phoneme conversion. ```console pip install phonikud phonikud-onnx ``` -------------------------------- ### Monitor GPU Usage with nvitop Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Installs the nvitop package and launches it to monitor GPU utilization. This is useful for observing hardware performance during training. ```console uv pip install nvitop uv run nvitop ``` -------------------------------- ### Download and Prepare Training Data Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Downloads a 7z compressed dataset, installs p7zip-full if not present, extracts the data, and copies it to the 'data/' directory. This prepares the necessary text files for model training. ```console wget https://huggingface.co/datasets/thewh1teagle/phonikud-data/resolve/main/knesset_nikud_v6.txt.7z sudo apt install p7zip-full -y 7z x knesset_nikud_v6.txt.7z cp knesset_nikud_v6.txt data/ ``` -------------------------------- ### Monitor Training Loss with TensorBoard Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Starts TensorBoard to visualize training logs stored in the './ckpt' directory. This allows for monitoring the model's loss during training. ```console uv run tensorboard --logdir ./ckpt ``` -------------------------------- ### Upload Model to HuggingFace Hub Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Installs huggingface_hub, configures git credentials for private repo access, logs in to HuggingFace, and uploads the model's checkpoint contents to a specified repository. It also shows how to clone private repositories and download individual files. ```console uv pip install huggingface_hub git config --global credential.helper store # Allow clone private repo from HF huggingface-cli login --token "token" --add-to-git-credential # https://huggingface.co/settings/tokens uv run huggingface-cli upload --repo-type model phonikud ./ckpt/path # upload contents of the folder # Fetch the model by git lfs install git clone https://huggingface.co/user/phonikud # Fetch file by huggingface-cli download --repo-type dataset user/some-dataset some_file.7z --local-dir . sudo apt install p7zip-full 7z x some_file.7z ``` -------------------------------- ### Install phonikud-onnx using pip Source: https://github.com/thewh1teagle/phonikud/blob/main/phonikud_onnx/README.md This command installs the phonikud-onnx library, which is required to add diacritics and phonetic marks to Hebrew text. It uses pip, the standard Python package installer. ```console pip install phonikud-onnx ``` -------------------------------- ### Handle Mixed English/Hebrew Text with Fallback (Python) Source: https://context7.com/thewh1teagle/phonikud/llms.txt This example demonstrates how to use the `phonikud` library with a fallback mechanism to phonemize text containing both Hebrew and English. It utilizes `EspeakWrapper` for English phonemization and allows custom fallback functions for specific domains, enabling multilingual TTS applications. ```python from phonemizer.backend.espeak.wrapper import EspeakWrapper import phonemizer import espeakng_loader import phonikud # Setup espeak for English phonemization EspeakWrapper.set_library(espeakng_loader.get_library_path()) EspeakWrapper.set_data_path(espeakng_loader.get_data_path()) def english_fallback(text: str) -> str: """Convert English text to IPA phonemes""" return phonemizer.phonemize(text) # Process mixed Hebrew and English text text = "מֵרְאִיָּה מְמֻחְשֶׁבֶת עַד Large Language Models" phonemes = phonikud.phonemize( text, preserve_punctuation=True, preserve_stress=True, fallback=english_fallback ) print(phonemes) # Output: meʁaˈja memuχʃˈevet ʔad lɑːrdʒ læŋɡwɪdʒ mɒdəlz # Custom fallback for specific domains def technical_fallback(text: str) -> str: # Handle technical terms, acronyms, etc. custom_dict = { "API": "eɪpiːaɪ", "GPU": "dʒiːpiːjuː" } return custom_dict.get(text, phonemizer.phonemize(text)) text = "עִיבּוּד עַל GPU מְהִיר יוֹתֵר" phonemes = phonikud.phonemize(text, fallback=technical_fallback) print(phonemes) ``` -------------------------------- ### Update CUDA Version with PyTorch Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Ensures the PyTorch installation is up-to-date, potentially resolving CUDA version conflicts. This command refreshes the installation and upgrades to the latest compatible version. ```console uv pip install --refresh -U torch ``` -------------------------------- ### Enable Cloud WandB Monitoring Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Runs the training script with WandB mode set to 'online', enabling cloud-based monitoring and logging of training metrics. ```console uv run src/train/main.py --wandb_mode online ``` -------------------------------- ### Phonikud Usage: Plain Schema Source: https://github.com/thewh1teagle/phonikud/blob/main/README.md Shows how to use the 'plain' schema for simplified phonemization in Phonikud, where characters like 'x' are used instead of 'χ'. This can be helpful for simpler applications or when precise phonetic representation is not strictly required. ```python phonemize(..., schema='plain') ``` -------------------------------- ### Train Phonikud Model Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Initiates the training process for the Phonikud model using a specified device (e.g., CUDA), checkpoint interval, WandB mode, validation split, early stopping patience, number of workers, learning rate, epochs, and batch size. It also includes a max_lines parameter to limit the training data. ```console uv run src/train/main.py \ --device cuda \ --checkpoint_interval 1758 \ --wandb_mode online \ --val_split 0.05 \ --early_stopping_patience 0 \ --num_workers 16 \ --learning_rate 5e-3 \ --epochs 999999 \ --batch_size 128 \ --wandb_mode online \ --max_lines 1000000 ``` -------------------------------- ### Process Dictionary of Words with Known Stress Patterns (Python) Source: https://context7.com/thewh1teagle/phonikud/llms.txt Demonstrates how to process a dictionary of Hebrew words with predefined stress positions. The `add_stress` function (assumed to be defined elsewhere) is used to apply stress markers to words based on their positions. This is useful for linguistic analysis and TTS preparation. ```python stress_dict = { "אוֹמֶרֶת": -2, # Milel "גִּימִיקִים": -3, # Third from end "קוֹרֶה": -1, # Milra "רַדְיוֹ": -2, # Milel "רֵפוֹרְמוֹת": -2 # Milel } for word, position in stress_dict.items(): stressed_word = add_stress(word, position) print(f"{word} → {stressed_word}") # Output: Each word with stress marker at specified position ``` -------------------------------- ### Phonikud Testing Command Source: https://github.com/thewh1teagle/phonikud/blob/main/README.md Provides the command to run the project's tests using pytest. This is essential for verifying the correct functionality of the Phonikud model and ensuring code integrity. ```bash uv run pytest ``` -------------------------------- ### Run Phonikud Model Inference Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Executes the Phonikud model for inference. Requires specifying the path to the trained checkpoint. ```console uv run src/run/main.py -m path/to/checkpoint/ ``` -------------------------------- ### Phonikud Usage: Custom Phoneme Input Source: https://github.com/thewh1teagle/phonikud/blob/main/README.md Demonstrates how to provide custom phonemes for words using a markdown-like syntax. This is useful for handling specific pronunciations or when the model's default prediction may not be accurate. ```markdown `[...title](/ʔentsiklopˈedja/)` ``` -------------------------------- ### Python Usage: Hebrew Grapheme-to-Phoneme Source: https://github.com/thewh1teagle/phonikud/blob/main/README.md Demonstrates how to use the Phonikud library in Python to convert Hebrew text to its phonetic representation (IPA). It involves loading an ONNX model, adding diacritics, and then phonemizing the text. ```python from phonikud_onnx import Phonikud from phonikud import phonemize model = Phonikud("./phonikud-1.0.int8.onnx") text = "שלום עולם" vocalized = model.add_diacritics(text) phonemes = phonemize(vocalized) print(phonemes) # ʃalˈom olˈam ``` -------------------------------- ### Override Automatic Phonemization with Markdown Syntax (Python) Source: https://context7.com/thewh1teagle/phonikud/llms.txt This snippet demonstrates the `hyper_phonemes` feature in `phonikud`, which allows manual specification of phoneme sequences for words using a markdown-like syntax. This is particularly useful for ensuring correct pronunciation of names, foreign words, or correcting errors in automatic G2P conversion. ```python from phonikud import phonemize # Override specific word pronunciations text = """ שָׁל֫וֹם לְכֻלָּ֫ם! הַיּ֫וֹם נִלְמַ֫ד אַנְגְּלִ֫ית: [hello](/hɛˈloʊ/) [world](/wɜːrld/) [אנציקלופדיה](/ʔantsikloˈpedja/) """ phonemes = phonemize(text) print(phonemes) # Output: ʃalˈom lχuˈlam! hajˈom nilmˈad ʔanɡlˈit: # hɛˈloʊ wɜːrld # ʔantsikloˈpedja # Use for proper names and foreign words text = """ הִזְמַנְתִּי שִׁירוּת מִן [Uber](/ˈuːbər/) וְקָנִיתִי [pizza](/ˈpiːtsə/) מִן [Domino's](/ˈdɒmɪnoʊz/) """ phonemes = phonemize(text) # Foreign words get exact pronunciation specified # Override problematic model predictions text = "[encyclopedia](/ɪnˌsaɪkləˈpiːdiə/) הִיא מִקּוֹר מֵידָע" phonemes = phonemize(text, preserve_punctuation=True) print(phonemes) # Manual phonemes used instead of automatic conversion ``` -------------------------------- ### Fix Hebrew Display Issues in SSH Source: https://github.com/thewh1teagle/phonikud/blob/main/model/README.md Resolves issues with Hebrew characters not displaying correctly in SSH terminals by regenerating locales and setting the default locale to UTF-8. Requires closing and reopening the terminal after execution. ```console sudo locale-gen en_US.UTF-8 sudo update-locale LANG=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 ``` -------------------------------- ### Expand Numbers, Dates, and Times to Words (Python) Source: https://context7.com/thewh1teagle/phonikud/llms.txt This code snippet illustrates the `Expander` functionality in `phonikud`, which automatically converts numbers, dates, and times into their spoken Hebrew word equivalents with nikud. It supports various formats including years, times, currency, and symbols, ensuring correct pronunciation in TTS systems. The expander can also be toggled on or off. ```python from phonikud import phonemize # Numbers automatically expanded to Hebrew words text = "יִשְׂרָאֵל הוּקְמָה בִּשְׁנַת 1948" phonemes = phonemize(text, use_expander=True) print(phonemes) # "1948" → "אֶלֶף תְּשַׁע מֵאוֹת אַרְבָּעִים שְׁמוֹנֶה" # Output: jiʃˈraʔel huqmˈa biʃnˈat ʔˈelef tʃˈa meˈot ʔˈarbaʔim ʃmˈone # Time expansion text = "מָחָר בְּשָׁעָה 22:00 נִפְגָּשׁ" phonemes = phonemize(text, use_expander=True) # "22:00" → Hebrew time expression print(phonemes) # Currency and symbols text = "אַתָּה חַיָּב לִי 50 שֶׁקֶל וְהַסֵּמֶל הוּא ₪" phonemes = phonemize(text, use_expander=True) # "50" → "חֲמִשִּׁים" # "₪" → "שֶׁקֶל" print(phonemes) # Disable expander when needed phonemes_no_expand = phonemize(text, use_expander=False) # Numbers remain as-is print(phonemes_no_expand) # Multiple numeric expressions text = "בְּתַארִיךְ 15/03/2024 בְּשָׁעָה 14:30" phonemes = phonemize(text, use_expander=True) ``` -------------------------------- ### Extract Syllables from Hebrew Text using get_syllables (Python) Source: https://context7.com/thewh1teagle/phonikud/llms.txt This snippet shows how to use the `get_syllables` function from `phonikud.syllables` to segment Hebrew words into their constituent syllables. It handles basic segmentation, complex words, and special cases like double vav, providing accurate syllable breakdowns for linguistic analysis. ```python from phonikud.syllables import get_syllables # Basic syllable segmentation word = "שָׁלוֹם" syllables = get_syllables(word) print(syllables) # Output: ['שָׁ', 'לוֹם'] # Complex words with multiple syllables word = "אֶנְצִיקְלוֹפֶּדְיָה" syllables = get_syllables(word) print(syllables) # Output: ['אֶ', 'נְצִי', 'קְלוֹ', 'פֶּ', 'דְיָה'] # Handle special cases like double vav words = [ "וָואלָה", # Double vav at start "הֲוֹלְטֶר", # Double vav in middle "אוֹרְחִים", # Single vav with vowel ] for word in words: syllables = get_syllables(word) print(f"{word}: {' · '.join(syllables)}") # Output: Properly segmented syllables for each case ``` -------------------------------- ### Phonikud: Normalize Hebrew Text Source: https://context7.com/thewh1teagle/phonikud/llms.txt Normalizes Hebrew text by decomposing Unicode, sorting diacritics, and standardizing quotation marks. Essential for consistent text handling in TTS training. Dependencies: phonikud. ```python from phonikud import normalize # Normalize text with mixed diacritics text = "שָׁלוֹם" normalized = normalize(text) print(f"Original: {repr(text)}") print(f"Normalized: {repr(normalized)}") # Output: Properly decomposed and sorted Unicode # Handle non-standard Hebrew quotation marks text = "צַהַ״ל" # Hebrew geresh normalized = normalize(text) print(normalized) # Output: Normalized with standard quotation marks # Normalize for model training training_data = [ "מַלְכּוּת", "אֱלֹהִים", "בְּרֵאשִׁית" ] normalized_data = [normalize(text) for text in training_data] # All diacritics properly sorted and deduplicated ``` -------------------------------- ### Phonikud ONNX: Add Diacritics and Phonemize Hebrew Text Source: https://context7.com/thewh1teagle/phonikud/llms.txt Adds nikud (diacritical marks) to plain Hebrew text using the phonikud-onnx model, completing the G2P pipeline. Recommended for production TTS systems. Dependencies: phonikud-onnx, phonikud. ```python from phonikud_onnx import Phonikud from phonikud import phonemize # Initialize model with ONNX file model = Phonikud("./phonikud-1.0.int8.onnx") # Complete pipeline: raw text → nikud → phonemes sentence = "בשנת 1948 השלים אפרים קישון את לימודיו" with_diacritics = model.add_diacritics(sentence) phonemes = phonemize(with_diacritics) print(f"Original: {sentence}") print(f"With nikud: {with_diacritics}") # Output: בִּשְׁנַת 1948 הִשְׁלִים אֶפְרַיִם קִישׁוֹן אֶת לִימּוּדָיו print(f"Phonemes: {phonemes}") # Output: biʃnˈat ʔˈelef tʃˈa meˈot ʔˈarbaʔim ʃmˈone hiʃlˈim ʔˈefrajim kiʃˈon ʔet limuˈdav # Process multiple sentences texts = [ "שלום עולם", "מה שלומך היום", "אני אוהב ללמוד עברית" ] for text in texts: vocalized = model.add_diacritics(text) result = phonemize(vocalized) print(f"{text} → {result}") ``` -------------------------------- ### Phonikud: Add Stress Diacritics to Hebrew Syllables Source: https://context7.com/thewh1teagle/phonikud/llms.txt Programmatically adds Hat'ama (stress) diacritics to Hebrew words at specified syllable positions. Useful for correcting stress or creating custom dictionaries. Dependencies: phonikud.syllables. ```python from phonikud.syllables import add_stress # Add stress to the last syllable (Milra pattern) word = "אוֹמֶרֶת" stressed = add_stress(word, -1) print(stressed) # Output: אוֹמֶרֶ֫ת (stress on last syllable) # Add stress to second-to-last syllable (Milel pattern) word = "דֶרֶךְ" stressed = add_stress(word, -2) print(stressed) # Output: דֶ֫רֶךְ (stress on penultimate syllable) ``` -------------------------------- ### Add Diacritics to Hebrew Text with Python Source: https://github.com/thewh1teagle/phonikud/blob/main/phonikud_onnx/README.md This Python code snippet demonstrates how to use the phonikud-onnx library to add diacritics to Hebrew text. It initializes the Phonikud model with the ONNX file and then calls the `add_diacritics` method to process the input string. ```python from phonikud_onnx import Phonikud phonikud = Phonikud("./phonikud-1.0.int8.onnx") with_diacritics = phonikud.add_diacritics("מתכת יקרה") print(with_diacritics) ``` -------------------------------- ### Phonikud: Convert Hebrew to IPA Phonemes Source: https://context7.com/thewh1teagle/phonikud/llms.txt Transforms Hebrew text with diacritics into IPA phonetic representation. Handles stress placement, vowel prediction, and punctuation. Supports modern/plain schemas and fallback phonemizers. Dependencies: phonikud. ```python from phonikud import phonemize # Basic usage with diacritized Hebrew text text = "שָׁלוֹם חֲבֵרִים! מָה שְׁלוֹמְכֶם?" phonemes = phonemize(text) print(phonemes) # Output: ʃalˈom χaveˈrim! ma ʃlomχˈem? # Advanced usage with options text = "הַיּוֹם נִלְמַד עִבְרִית" phonemes = phonemize( text, preserve_punctuation=True, preserve_stress=True, use_expander=True, use_post_normalize=True, predict_stress=True, predict_vocal_shva=True, schema='modern' ) print(phonemes) # Output: hajˈom nilmˈad ʔivˈrit # Using plain schema for simplified phonemes phonemes = phonemize("שָׁלוֹם", schema='plain') print(phonemes) # Output: Simplified phonemes without special characters like χ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.