docstr: English G2P module. This module converts words from grapheme to phoneme representation using phoneme_dict in CMU dict format.
  Optionally, it can ignore words which are heteronyms, ambiguous or marked as unchangeable by word_tokenize_func (see code for details).
  Ignored words are left unchanged or passed through apply_to_oov_word for handling.
  Args:
      phoneme_dict (str, Path, Dict): Path to file in CMUdict format or dictionary of CMUdict-like entries.
      word_tokenize_func: Function for tokenizing text to words.
          It has to return List[Tuple[Union[str, List[str]], bool]] where every tuple denotes word representation and flag whether to leave unchanged or not.
          It is expected that unchangeable word representation will be represented as List[str], other cases are represented as str.
          It is useful to mark word as unchangeable which is already in phoneme representation.
      apply_to_oov_word: Function that will be applied to out of phoneme_dict word.
      ignore_ambiguous_words: Whether to not handle word via phoneme_dict with ambiguous phoneme sequences. Defaults to True.
      heteronyms (str, Path, List): Path to file with heteronyms (every line is new word) or list of words.
      encoding: Encoding type.
      phoneme_probability (Optional[float]): The probability (0.<var<1.) that each word is phonemized. Defaults to None which is the same as 1.
          Note that this code path is only run if the word can be phonemized. For example: If the word does not have an entry in the g2p dict, it will be returned
          as characters. If the word has multiple entries and ignore_ambiguous_words is True, it will be returned as characters.
docstr_tok: ["English","G2P","module",".","This","module","converts","words","from","grapheme","to","phoneme","representation","using","phoneme_dict","in","CMU","dict","format",".","Optionally",",","it","can","ignore","words","which","are","heteronyms",",","ambiguous","or","marked","as","unchangeable","by","word_tokenize_func","(","see","code","for","details",")",".","Ignored","words","are","left","unchanged","or","passed","through","apply_to_oov_word","for","handling",".","Args",":","phoneme_dict","(","str",",","Path",",","Dict",")",":","Path","to","file","in","CMUdict","format","or","dictionary","of","CMUdict-like","entries",".","word_tokenize_func",":","Function","for","tokenizing","text","to","words",".","It","has","to","return","List","[","Tuple","[","Union","[","str",",","List","[","str","]","]",",","bool","]","]","where","every","tuple","denotes","word","representation","and","flag","whether","to","leave","unchanged","or","not",".","It","is","expected","that","unchangeable","word","representation","will","be","represented","as","List","[","str","]",",","other","cases","are","represented","as","str",".","It","is","useful","to","mark","word","as","unchangeable","which","is","already","in","phoneme","representation",".","apply_to_oov_word",":","Function","that","will","be","applied","to","out","of","phoneme_dict","word",".","ignore_ambiguous_words",":","Whether","to","not","handle","word","via","phoneme_dict","with","ambiguous","phoneme","sequences",".","Defaults","to","True",".","heteronyms","(","str",",","Path",",","List",")",":","Path","to","file","with","heteronyms","(","every","line","is","new","word",")","or","list","of","words",".","encoding",":","Encoding","type",".","phoneme_probability","(","Optional","[","float","]",")",":","The","probability","(","0.","<","var","<","1",".",")","that","each","word","is","phonemized",".","Defaults","to","None","which","is","the","same","as","1",".","Note","that","this","code","path","is","only","run","if","the","word","can","be","phonemized",".","For","example",":","If","the","word","does","not","have","an","entry","in","the","g2p","dict",",","it","will","be","returned","as","characters",".","If","the","word","has","multiple","entries","and","ignore_ambiguous_words","is","True",",","it","will","be","returned","as","characters","."]
code: def __init__(
      self,
      phoneme_dict=None,
      word_tokenize_func=english_word_tokenize,
      apply_to_oov_word=None,
      ignore_ambiguous_words=True,
      heteronyms=None,
      encoding="latin-1",
      phoneme_probability: Optional[float] = None,
      mapping_file: Optional[str] = None,
  ):
      """English G2P module. This module converts words from grapheme to phoneme representation using phoneme_dict in CMU dict format.
      Optionally, it can ignore words which are heteronyms, ambiguous or marked as unchangeable by word_tokenize_func (see code for details).
      Ignored words are left unchanged or passed through apply_to_oov_word for handling.
      Args:
          phoneme_dict (str, Path, Dict): Path to file in CMUdict format or dictionary of CMUdict-like entries.
          word_tokenize_func: Function for tokenizing text to words.
              It has to return List[Tuple[Union[str, List[str]], bool]] where every tuple denotes word representation and flag whether to leave unchanged or not.
              It is expected that unchangeable word representation will be represented as List[str], other cases are represented as str.
              It is useful to mark word as unchangeable which is already in phoneme representation.
          apply_to_oov_word: Function that will be applied to out of phoneme_dict word.
          ignore_ambiguous_words: Whether to not handle word via phoneme_dict with ambiguous phoneme sequences. Defaults to True.
          heteronyms (str, Path, List): Path to file with heteronyms (every line is new word) or list of words.
          encoding: Encoding type.
          phoneme_probability (Optional[float]): The probability (0.<var<1.) that each word is phonemized. Defaults to None which is the same as 1.
              Note that this code path is only run if the word can be phonemized. For example: If the word does not have an entry in the g2p dict, it will be returned
              as characters. If the word has multiple entries and ignore_ambiguous_words is True, it will be returned as characters.
      """
      phoneme_dict = (
          self._parse_as_cmu_dict(phoneme_dict, encoding)
          if isinstance(phoneme_dict, str)
          or isinstance(phoneme_dict, pathlib.Path)
          or phoneme_dict is None
          else phoneme_dict
      )
  
      if apply_to_oov_word is None:
          logging.warning(
              "apply_to_oov_word=None, This means that some of words will remain unchanged "
              "if they are not handled by any of the rules in self.parse_one_word(). "
              "This may be intended if phonemes and chars are both valid inputs, otherwise, "
              "you may see unexpected deletions in your input."
          )
  
      super().__init__(
          phoneme_dict=phoneme_dict,
          word_tokenize_func=word_tokenize_func,
          apply_to_oov_word=apply_to_oov_word,
          mapping_file=mapping_file,
      )
  
      self.ignore_ambiguous_words = ignore_ambiguous_words
      self.heteronyms = (
          set(self._parse_file_by_lines(heteronyms, encoding))
          if isinstance(heteronyms, str)
          or isinstance(heteronyms, pathlib.Path)
          else heteronyms
      )
      self.phoneme_probability = phoneme_probability
      self._rng = random.Random()
  
file_path: NeMo/nemo/collections/tts/g2p/models/en_us_arpabet.py
imports: import pathlib
  import random
  import re
  import time
  from typing import Optional
  import nltk
  import torch
  from nemo.collections.common.tokenizers.text_to_speech.tokenizer_utils import english_word_tokenize
  from nemo.collections.tts.g2p.models.base import BaseG2p
  from nemo.utils import logging
  from nemo.utils.get_rank import is_global_rank_zero
label_desc: Use image node_id 1 to create a new EnglishG2p object from inherited base classes: BaseG2p with example: obj = EnglishG2p(phoneme_dict, word_tokenize_func, apply_to_oov_word, ignore_ambiguous_words, heteronyms, encoding, phoneme_probability, mapping_file)