docstr: Args:
      batch:  A list of tuples of (input_ids, subtokens_mask, [Optional] target_word_ids).
docstr_tok: ["Args",":","batch",":","A","list","of","tuples","of","(","input_ids",",","subtokens_mask",",","[","Optional","]","target_word_ids",")","."]
code: def _collate_fn(self, batch):
      """
      Args:
          batch:  A list of tuples of (input_ids, subtokens_mask, [Optional] target_word_ids).
      """
      max_length = max([len(entry["input_ids"]) for entry in batch])
  
      padded_input_ids = []
      padded_subtokens_mask = []
      padded_attention_mask = []
  
      if self.with_labels:
          padded_targets = []
  
      for item in batch:
          input_ids = item["input_ids"]
          if len(input_ids) < max_length:
              pad_width = max_length - len(input_ids)
              padded_attention_mask.append(
                  [1] * len(input_ids) + [0] * pad_width
              )
              padded_input_ids.append(
                  np.pad(
                      input_ids,
                      pad_width=[0, pad_width],
                      constant_values=self.PAD_TOKEN,
                  )
              )
              padded_subtokens_mask.append(
                  np.pad(
                      item["subtokens_mask"],
                      pad_width=[0, pad_width],
                      constant_values=self.PAD_TOKEN,
                  )
              )
  
              if self.with_labels:
                  padded_targets.append(
                      np.pad(
                          item["target"],
                          pad_width=[0, pad_width],
                          constant_values=self.LOSS_PAD_TOKEN,
                      )
                  )
          else:
              padded_attention_mask.append([1] * len(input_ids))
              padded_input_ids.append(input_ids)
              padded_subtokens_mask.append(item["subtokens_mask"])
              if self.with_labels:
                  padded_targets.append(item["target"])
  
      output = {
          "input_ids": torch.LongTensor(np.array(padded_input_ids)),
          "attention_mask": torch.LongTensor(
              np.array(padded_attention_mask)
          ),
          "subtokens_mask": torch.LongTensor(
              np.array(padded_subtokens_mask)
          ),
      }
      if self.with_labels:
          output["targets"] = torch.LongTensor(padded_targets)
      return output
  
file_path: NeMo/nemo/collections/tts/g2p/data/heteronym_classification.py
imports: import json
  import os
  import re
  from typing import Dict, List, Optional, Tuple
  import numpy
  import torch
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling the HeteronymClassificationDataset obj's underlying member method code with example usage: obj._collate_fn(batch) and returns: output