class_docstr: This is a classification model that selects the best heteronym option out of possible dictionary entries.
  Supports only heteronyms, no OOV.
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      self.max_seq_length = cfg.max_seq_length
      self.wordids = self.register_artifact("wordids", cfg.wordids)
      self.heteronym_dict, self.wordid_to_idx = read_wordids(
          self.wordids
      )
      self.idx_to_wordid = {v: k for k, v in self.wordid_to_idx.items()}
      self.supported_heteronyms = list(self.heteronym_dict.keys())
  
      if cfg.class_labels.class_labels_file is None:
          label_ids_file = "/tmp/label_ids.csv"
          with open(label_ids_file, "w") as f:
              for idx in range(len(self.idx_to_wordid)):
                  f.write(self.idx_to_wordid[idx] + "\n")
          self.register_artifact(
              "class_labels.class_labels_file", label_ids_file
          )
  
      super().__init__(cfg=cfg, trainer=trainer)
      self.lang = self._cfg.get("lang", None)
      num_classes = len(self.wordid_to_idx)
      self.classifier = TokenClassifier(
          hidden_size=self.hidden_size,
          num_classes=num_classes,
          num_layers=self._cfg.head.num_fc_layers,
          activation=self._cfg.head.activation,
          log_softmax=False,
          dropout=self._cfg.head.fc_dropout,
          use_transformer_init=self._cfg.head.use_transformer_init,
      )
  
      # Loss Functions
      self.loss = CrossEntropyLoss(logits_ndim=3)
  
      # setup to track metrics
      self.classification_report = ClassificationReport(
          num_classes=num_classes,
          mode="macro",
          dist_sync_on_step=True,
          label_ids=self.wordid_to_idx,
      )
  
      # used for inference to convert predicted wordids to phonemes
      self.wordid_to_phonemes_file = None
      self.wordid_to_phonemes = None
  
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 1 to create a new HeteronymClassificationModel object from inherited base classes: NLPModel with example: obj = HeteronymClassificationModel(cfg, trainer)