class_docstr: Creates a dataset to train a T5G2P model.
class_docstr_tok: ["Creates","a","dataset","to","train","a","T5G2P","model","."]
code: def _collate_fn(self, batch):
      graphemes_batch = [entry["graphemes"] for entry in batch]
  
      # Encode inputs (graphemes)
      input_encoding = self.tokenizer(
          graphemes_batch,
          padding="longest",
          max_length=self.max_source_len,
          truncation=True,
          return_tensors="pt",
      )
      input_ids, attention_mask = (
          input_encoding.input_ids,
          input_encoding.attention_mask,
      )
      output = (input_ids, attention_mask)
  
      # labels are available during training and evaluation but not inference
      if self.with_labels:
          # Encode targets (phonemes)
          phonemes_batch = [entry["phonemes"] for entry in batch]
          target_encoding = self.tokenizer(
              phonemes_batch,
              padding="longest",
              max_length=self.max_target_len,
              truncation=True,
          )
          labels = target_encoding.input_ids
  
          # Need to replace padding tokens w/ -100 for loss to ignore them
          labels = [
              [
                  (
                      label
                      if label != self.tokenizer.pad_token_id
                      else -100
                  )
                  for label in labels_example
              ]
              for labels_example in labels
          ]
          labels = torch.tensor(labels)
          output = (
              input_ids,
              attention_mask,
              labels,
          )  # grapheme IDs, attention mask, phoneme IDs
  
      return output
  
file_path: NeMo/nemo/collections/tts/g2p/data/t5.py
imports: import json
  import os
  import torch
  from transformers import PreTrainedTokenizerBase
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 4 for calling the T5G2PDataset obj's underlying member method code with example usage: obj._collate_fn(batch) and returns: output