code: def collate_fn(self, batch):
      input_text = [x["input"] for x in batch]
      target_text = [x["target"] for x in batch]
  
      # encoder inputs
      inputs = self.tokenizer(
          input_text,
          return_tensors="pt",
          padding=True,
          max_length=self.max_length,
      )
      enc_idxs = inputs["input_ids"]
      enc_attn = inputs["attention_mask"]
  
      # decoder inputs
      targets = self.tokenizer(
          target_text,
          return_tensors="pt",
          padding=True,
          max_length=self.max_output_length,
      )
      dec_idxs = targets["input_ids"]
      # print(self.tokenizer.decode(dec_idxs[0]))
      batch_size = dec_idxs.size(0)
      dec_idxs[:, 0] = self.tokenizer.eos_token_id
      dec_attn = targets["attention_mask"]
  
      # labels
      padding = torch.ones((batch_size, 1), dtype=torch.long)
      padding[:] = self.tokenizer.pad_token_id
      raw_lbl_idxs = torch.cat((dec_idxs[:, 1:], padding), dim=1)
      lbl_attn = torch.cat(
          (
              dec_attn[:, 1:],
              torch.zeros((batch_size, 1), dtype=torch.long),
          ),
          dim=1,
      )
      lbl_idxs = raw_lbl_idxs.masked_fill(
          lbl_attn == 0, -100
      )  # ignore padding
  
      enc_idxs = enc_idxs.cuda()
      enc_attn = enc_attn.cuda()
      dec_idxs = dec_idxs.cuda()
      dec_attn = dec_attn.cuda()
      raw_lbl_idxs = raw_lbl_idxs.cuda()
      lbl_idxs = lbl_idxs.cuda()
  
      return GenBatch(
          input_text=input_text,
          target_text=target_text,
          enc_idxs=enc_idxs,
          enc_attn=enc_attn,
          dec_idxs=dec_idxs,
          dec_attn=dec_attn,
          lbl_idxs=lbl_idxs,
          raw_lbl_idxs=raw_lbl_idxs,
          infos=[x["info"] for x in batch],
      )
  
imports: import json, logging, pickle
  from mimetypes import knownfiles
  from unittest.mock import NonCallableMagicMock
  import torch
  from torch.utils.data import Dataset
  from collections import namedtuple
label_desc: Use image node_id 5 for calling the GenDataset obj's underlying member method code with example usage: obj.collate_fn(batch) and returns: GenBatch