class_docstr: T5-based grapheme-to-phoneme model.
code: def validation_step(
      self, batch, batch_idx, dataloader_idx=0, split="val"
  ):
      input_ids, attention_mask, labels = batch
  
      # Get loss from forward step
      val_loss = self.forward(
          input_ids=input_ids,
          attention_mask=attention_mask,
          labels=labels,
      )
  
      # Get preds from generate function and calculate PER
      labels_str = self._tokenizer.batch_decode(
          # Need to do the following to zero out the -100s (ignore_index).
          torch.ones_like(labels) * ((labels == -100) * 100) + labels,
          skip_special_tokens=True,
      )
      generated_str, _, _ = self._generate_predictions(
          input_ids=input_ids, model_max_target_len=self.max_target_len
      )
      per = word_error_rate(
          hypotheses=generated_str, references=labels_str, use_cer=True
      )
      output = {f"{split}_loss": val_loss, "per": per}
      if split == "val":
          if (
              isinstance(self.trainer.val_dataloaders, (list, tuple))
              and len(self.trainer.val_dataloaders) > 1
          ):
              self.validation_step_outputs[dataloader_idx].append(
                  output
              )
          else:
              self.validation_step_outputs.append(output)
      else:
          if (
              isinstance(self.trainer.test_dataloaders, (list, tuple))
              and len(self.trainer.test_dataloaders) > 1
          ):
              self.test_step_outputs[dataloader_idx].append(output)
          else:
              self.test_step_outputs.append(output)
      return output
  
imports: from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Union
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from transformers import AutoTokenizer, T5ForConditionalGeneration
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.tts.g2p.data.t5 import T5G2PDataset
  from nemo.collections.tts.models.base import G2PModel
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types import LabelsType, LossType, MaskType, NeuralType, TokenIndex
  from nemo.utils import logging
label_desc: Use image node_id 9 for calling the T5G2PModel obj's underlying member method code with example usage: obj.validation_step(batch, batch_idx, dataloader_idx, split) and returns: output