code: def collate_fn(self, batch):
      enc_query = [item["text_enc"] for item in batch]
      dec_input = [item["text_dec"] for item in batch]
      labels = [item["labels"] for item in batch]
  
      enc_query = torch.LongTensor(self._collate_item(enc_query))
      dec_input = torch.LongTensor(self._collate_item(dec_input))
      loss_mask = torch.LongTensor(
          [
              ([1] * (len(item)))
              + ([0] * (dec_input.size(1) - len(item)))
              for item in labels
          ]
      )
      labels = torch.LongTensor(self._collate_item(labels))
  
      enc_mask = (enc_query != self.tokenizer.pad_id).long()
      dec_mask = (dec_input != self.tokenizer.pad_id).long()
  
      processed_example = {
          "text_enc": enc_query,
          "text_dec": dec_input,
          "labels": labels,
          "loss_mask": loss_mask,
          "enc_mask": enc_mask,
          "dec_mask": dec_mask,
      }
  
      # Collate additional args if present in the batch.
      if "original" in batch[0]:
          original = self._collate_item(
              [item["original"] for item in batch]
          )
          processed_example["original"] = torch.LongTensor(original)
  
      if "template" in batch[0]:
          template = self._collate_item(
              [item["template"] for item in batch]
          )
          processed_example["template"] = torch.LongTensor(template)
  
      if "prompt" in batch[0]:
          prompt = self._collate_item(
              [item["prompt"] for item in batch]
          )
          processed_example["prompt"] = torch.LongTensor(prompt)
  
      if "task_name_with_prompt" in batch[0]:
          task_name_with_prompt = self._collate_item(
              [item["task_name_with_prompt"] for item in batch]
          )
          processed_example["task_name_with_prompt"] = torch.LongTensor(
              task_name_with_prompt
          )
  
      return processed_example
  
file_path: NeMo/nemo/collections/nlp/data/language_modeling/t0_dataset.py
imports: import numpy
  import torch
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.collections.nlp.data.language_modeling.megatron.dataset_utils import get_samples_mapping
  from nemo.collections.nlp.data.language_modeling.text_memmap_dataset import JSONLMemMapDataset, TextMemMapDataset
  from nemo.core.classes import Dataset
label_desc: Use image node_id 8 for calling the T0Dataset obj's underlying member method code with example usage: obj.collate_fn(batch) and returns: processed_example