class_docstr: CTC-based grapheme-to-phoneme model.
class_docstr_tok: ["CTC-based","grapheme-to-phoneme","model","."]
docstr: Called at the end of validation to aggregate outputs (reduces across batches, not workers).
docstr_tok: ["Called","at","the","end","of","validation","to","aggregate","outputs","(","reduces","across","batches",",","not","workers",")","."]
code: def multi_validation_epoch_end(
      self, outputs, dataloader_idx=0, split="val"
  ):
      """
      Called at the end of validation to aggregate outputs (reduces across batches, not workers).
      """
      avg_loss = torch.stack(
          [x[f"{split}_loss"] for x in outputs]
      ).mean()
      self.log(f"{split}_loss", avg_loss, prog_bar=True)
  
      wer_num = torch.stack(
          [x[f"{split}_wer_num"] for x in outputs]
      ).sum()
      wer_denom = torch.stack(
          [x[f"{split}_wer_denom"] for x in outputs]
      ).sum()
      wer = wer_num / wer_denom
  
      per_num = torch.stack(
          [x[f"{split}_per_num"] for x in outputs]
      ).sum()
      per_denom = torch.stack(
          [x[f"{split}_per_denom"] for x in outputs]
      ).sum()
      per = per_num / per_denom
  
      if split == "test":
          dataloader_name = self._test_names[dataloader_idx].upper()
      else:
          dataloader_name = self._validation_names[
              dataloader_idx
          ].upper()
  
      self.log(f"{split}_wer", wer)
      self.log(f"{split}_per", per)
  
      self.log(f"{split}_per", per)
      # to save all PER values for each dataset in WANDB
      self.log(f"{split}_per_{dataloader_name}", per)
  
      logging.info(f"PER: {per * 100}% {dataloader_name}")
      logging.info(f"WER: {wer * 100}% {dataloader_name}")
  
imports: import os
  import string
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Union
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig, ListConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from transformers import AutoConfig, AutoModel, AutoTokenizer
  from nemo.collections.tts.g2p.data.ctc import CTCG2PBPEDataset
  from nemo.collections.tts.models.base import G2PModel
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 9 for calling the CTCG2PModel obj's underlying member method code with example usage: obj.multi_validation_epoch_end(outputs, dataloader_idx, split) without return types