class_docstr: This is a classification model that selects the best heteronym option out of possible dictionary entries.
  Supports only heteronyms, no OOV.
docstr: Replaces heteronyms, supported by the model, with the phoneme form (if wordid_to_phonemes_file)
  or with predicted wordids.
  
  Args:
      sentences: Sentences to use for inference
      batch_size: batch size to use during inference.
          Bigger will result in better throughput performance but would use more memory.
      num_workers: number of workers for DataLoader
      wordid_to_phonemes_file: (Optional) file with mapping between wordid predicted by the model to phonemes
  
  Returns:
      preds: model predictions
      output: sentences with heteronym replaced with phonemes (if wordid_to_phonemes_file specified)
docstr_tok: ["Replaces","heteronyms",",","supported","by","the","model",",","with","the","phoneme","form","(","if","wordid_to_phonemes_file",")","or","with","predicted","wordids",".","Args",":","sentences",":","Sentences","to","use","for","inference","batch_size",":","batch","size","to","use","during","inference",".","Bigger","will","result","in","better","throughput","performance","but","would","use","more","memory",".","num_workers",":","number","of","workers","for","DataLoader","wordid_to_phonemes_file",":","(","Optional",")","file","with","mapping","between","wordid","predicted","by","the","model","to","phonemes","Returns",":","preds",":","model","predictions","output",":","sentences","with","heteronym","replaced","with","phonemes","(","if","wordid_to_phonemes_file","specified",")"]
code: def disambiguate(
      self,
      sentences: List[str],
      batch_size: int = 4,
      num_workers: int = 0,
      wordid_to_phonemes_file: Optional[str] = None,
  ):
      """
      Replaces heteronyms, supported by the model, with the phoneme form (if wordid_to_phonemes_file)
      or with predicted wordids.
  
      Args:
          sentences: Sentences to use for inference
          batch_size: batch size to use during inference.
              Bigger will result in better throughput performance but would use more memory.
          num_workers: number of workers for DataLoader
          wordid_to_phonemes_file: (Optional) file with mapping between wordid predicted by the model to phonemes
  
      Returns:
          preds: model predictions
          output: sentences with heteronym replaced with phonemes (if wordid_to_phonemes_file specified)
      """
      if isinstance(sentences, str):
          sentences = [sentences]
      batch_size = min(batch_size, len(sentences))
  
      start_end, heteronyms = get_heteronym_spans(
          sentences, self.heteronym_dict
      )
      if len(sentences) != len(start_end) != len(heteronyms):
          raise ValueError(
              f"Number of sentences should match the lengths of provided start-end indices, {len(sentences)} != {len(start_end)}"
          )
  
      tmp_manifest = "/tmp/manifest.json"
      with open(tmp_manifest, "w") as f:
          for cur_sentence, cur_start_ends, cur_heteronyms in zip(
              sentences, start_end, heteronyms
          ):
              item = {
                  "text_graphemes": cur_sentence,
                  "start_end": cur_start_ends,
                  "heteronym_span": cur_heteronyms,
              }
              f.write(json.dumps(item, ensure_ascii=False) + "\n")
  
      all_preds = self._disambiguate(
          manifest=tmp_manifest,
          batch_size=batch_size,
          num_workers=num_workers,
      )
  
      if wordid_to_phonemes_file is not None:
          self.set_wordid_to_phonemes(wordid_to_phonemes_file)
  
      output = []
      for sent_idx, sent_start_end in enumerate(start_end):
          output.append(
              self._process_sentence(
                  text=sentences[sent_idx],
                  start_end=sent_start_end,
                  predictions=all_preds[sent_idx],
              ),
          )
  
      return all_preds, output
  
imports: import json
  import os
  from typing import List, Optional
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import CrossEntropyLoss
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport
  from nemo.collections.nlp.modules.common import TokenClassifier
  from nemo.collections.nlp.parts.utils_funcs import tensor2list
  from nemo.collections.tts.g2p.data.heteronym_classification import HeteronymClassificationDataset
  from nemo.collections.tts.g2p.utils import get_heteronym_spans, get_wordid_to_phonemes, read_wordids
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 12 for calling the HeteronymClassificationModel obj's underlying member method code with example usage: obj.disambiguate(sentences, batch_size, num_workers, wordid_to_phonemes_file) and returns: all_preds,  output