code: def collater(self, samples):
      collated = self.dataset.collater(samples)
      if len(collated) == 0:
          return collated
      indices = set(collated["id"].tolist())
      target = [s["label"] for s in samples if s["id"] in indices]
  
      if self.add_to_input:
          eos = torch.LongTensor([self.eos])
          prev_output_tokens = [
              torch.cat([eos, t], axis=-1) for t in target
          ]
          target = [torch.cat([t, eos], axis=-1) for t in target]
          collated["net_input"][
              "prev_output_tokens"
          ] = prev_output_tokens
  
      if self.batch_targets:
          collated["target_lengths"] = torch.LongTensor(
              [len(t) for t in target]
          )
          target = data_utils.collate_tokens(
              target, pad_idx=self.pad, left_pad=False
          )
          collated["ntokens"] = collated["target_lengths"].sum().item()
          if getattr(collated["net_input"], "prev_output_tokens", None):
              collated["net_input"][
                  "prev_output_tokens"
              ] = data_utils.collate_tokens(
                  collated["net_input"]["prev_output_tokens"],
                  pad_idx=self.pad,
                  left_pad=False,
              )
      else:
          collated["ntokens"] = sum([len(t) for t in target])
  
      collated["target"] = target
      return collated
  
file_path: fairseq/fairseq/data/add_target_dataset.py
imports: import torch
  from .None import BaseWrapperDataset, data_utils
  from fairseq.data.text_compressor import TextCompressor, TextCompressionLevel
label_desc: Use image node_id 5 for calling the AddTargetDataset obj's underlying member method code with example usage: obj.collater(samples) and returns: collated, collated