class_docstr: Sequence to Sequence Dataset in memory.
class_docstr_tok: ["Sequence","to","Sequence","Dataset","in","memory","."]
code: def collate_fn(self, batch):
      text_enc = [item["text_enc"] for item in batch]
      text_dec = [item["text_dec"] for item in batch]
      labels = [item["labels"] for item in batch]
  
      if isinstance(text_enc[0], np.ndarray):
          text_enc = [x.tolist() for x in text_enc]
  
      if isinstance(text_dec[0], np.ndarray):
          text_dec = [x.tolist() for x in text_dec]
  
      if isinstance(labels[0], np.ndarray):
          labels = [x.tolist() for x in labels]
  
      max_dec_input_length = (
          max([len(item) for item in text_dec]) if text_dec else 0
      )
      max_enc_input_length = (
          max([len(item) for item in text_enc]) if text_enc else 0
      )
      max_label_length = (
          max([len(item) for item in labels]) if labels else 0
      )
  
      loss_mask = [
          ([1] * (len(item))) + ([0] * (max_label_length - len(item)))
          for item in labels
      ]
      text_enc = [
          item
          + [self.src_tokenizer.pad_id]
          * (max_enc_input_length - len(item))
          for item in text_enc
      ]
      text_dec = [
          item
          + [self.tgt_tokenizer.pad_id]
          * (max_dec_input_length - len(item))
          for item in text_dec
      ]
      labels = [
          item
          + [self.tgt_tokenizer.pad_id] * (max_label_length - len(item))
          for item in labels
      ]
  
      text_enc = torch.LongTensor(text_enc)
      text_dec = torch.LongTensor(text_dec)
      labels = torch.LongTensor(labels)
      loss_mask = torch.LongTensor(loss_mask)
  
      enc_mask = (text_enc != self.src_tokenizer.pad_id).long()
      dec_mask = (text_dec != self.tgt_tokenizer.pad_id).long()
  
      return {
          "text_enc": text_enc,
          "text_dec": text_dec,
          "labels": labels,
          "loss_mask": loss_mask,
          "enc_mask": enc_mask,
          "dec_mask": dec_mask,
      }
  
imports: import os
  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_indexed_dataset_, get_samples_mapping
  from nemo.collections.nlp.data.language_modeling.text_memmap_dataset import TextMemMapDataset
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 6 for calling the SequenceToSequenceDataset obj's underlying member method code with example usage: obj.collate_fn(batch) and returns: dict