docstr: Extracts the homograph from the sequence, computes metrics for it
  and registers them
  
  Arguments
  ---------
  predictions: G2PPredictions
      the predictions (as computed by compute_forward)
  batch: PaddedBatch
      a raw G2P data batch
docstr_tok: ["Extracts","the","homograph","from","the","sequence",",","computes","metrics","for","it","and","registers","them","Arguments","--","--","--","--","-","predictions",":","G2PPredictions","the","predictions","(","as","computed","by","compute_forward",")","batch",":","PaddedBatch","a","raw","G2P","data","batch"]
code: def _add_homograph_metrics(self, predictions, batch):
      """Extracts the homograph from the sequence, computes metrics for it
      and registers them
  
      Arguments
      ---------
      predictions: G2PPredictions
          the predictions (as computed by compute_forward)
      batch: PaddedBatch
          a raw G2P data batch
      """
      phns, phn_lens = batch.phn_encoded
      phns_base, phn_base_lens = (
          batch.phn_raw_encoded
          if self.hparams.phn_tokenize
          else (None, None)
      )
      (
          p_seq_homograph,
          phns_homograph,
          phn_lens_homograph,
      ) = self.hparams.homograph_extractor(
          phns,
          phn_lens,
          predictions.p_seq,
          subsequence_phn_start=batch.homograph_phn_start,
          subsequence_phn_end=batch.homograph_phn_end,
          phns_base=phns_base,
          phn_base_lens=phn_base_lens,
      )
      hyps_homograph = self.hparams.homograph_extractor.extract_hyps(
          phns_base if phns_base is not None else phns,
          predictions.hyps,
          batch.homograph_phn_start,
          use_base=True,
      )
      self.seq_metrics_homograph.append(
          batch.sample_id,
          p_seq_homograph,
          phns_homograph,
          phn_lens_homograph,
      )
      self.per_metrics_homograph.append(
          batch.sample_id,
          hyps_homograph,
          phns_homograph,
          None,
          phn_lens_homograph,
          self.hparams.out_phoneme_decoder,
      )
      prediction_labels = phonemes_to_label(
          phns=hyps_homograph, decoder=self.hparams.out_phoneme_decoder
      )
      phns_homograph_list = undo_padding(
          phns_homograph, phn_lens_homograph
      )
      target_labels = phonemes_to_label(
          phns_homograph_list, decoder=self.hparams.out_phoneme_decoder
      )
      self.classification_metrics_homograph.append(
          batch.sample_id,
          predictions=prediction_labels,
          targets=target_labels,
          categories=batch.homograph_wordid,
      )
  
imports: from speechbrain.dataio.dataset import FilteredSortedDynamicItemDataset, DynamicItemDataset
  from speechbrain.dataio.sampler import BalancingDataSampler
  from speechbrain.utils.data_utils import undo_padding
  import datasets
  import logging
  import os
  import random
  import speechbrain
  import sys
  from enum import Enum
  from collections import namedtuple
  from hyperpyyaml import load_hyperpyyaml
  from functools import partial
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.utils.pretrained import save_for_pretrained
  from speechbrain.lobes.models.g2p.dataio import enable_eos_bos, grapheme_pipeline, phoneme_pipeline, tokenizer_encode_pipeline, add_bos_eos, get_sequence_key, phonemes_to_label
  from speechbrain.dataio.wer import print_alignments
  from speechbrain.wordemb.util import expand_to_chars
  from io import StringIO
  from speechbrain.utils import hpopt
  import numpy
label_desc: Use image node_id 8 for calling the G2PBrain obj's underlying member method code with example usage: obj._add_homograph_metrics(predictions, batch) without return types