code: def padder_collate(batch, debug=False):
      """Puts each data field into a tensor with outer dimension batch size
      Pad variable length input tensors and add a weight tensor to the target
      """
      transposed_inputs = tuple(zip(*batch))
      if len(transposed_inputs) == 2:
          inputs, targets = transposed_inputs
          transposed_inputs = tuple(zip(*inputs))
          transposed_targets = tuple(zip(*targets))
      else:
          transposed_targets = None
  
      max_pairs = (
          max(len(t) for t in transposed_inputs[3])
          if len(transposed_inputs) == 8
          else 0
      )  # Get max nb of pairs (batch are sorted by nb of pairs)
      if max_pairs > 0:
          out_inputs = []
          out_targets = []
          for t_inp in transposed_inputs:
              if len(t_inp[0].shape) == 2:
                  out_inputs.append(
                      torch.stack(
                          [
                              torch.cat(
                                  [
                                      t,
                                      t.new(
                                          max_pairs - len(t), len(t[0])
                                      ).zero_(),
                                  ]
                              )
                              if len(t) != max_pairs
                              else t
                              for t in t_inp
                          ],
                          0,
                      )
                  )
              else:
                  out_inputs.append(torch.stack(t_inp, 0))
          if transposed_targets is not None:
              for i, t_targ in enumerate(
                  transposed_targets
              ):  # 0:labels, 1:costs, 2:true_ants, 3:false_ants
                  if i == 2 or i == 3:
                      if debug:
                          print("collate before", t_targ)
                      # shift the antecedent index associated to single anaphores (last)
                      t_targ = tuple(
                          t.masked_fill_(
                              torch.eq(t, len(t) - 1), max_pairs
                          )
                          for t in t_targ
                      )
                      if debug:
                          print("collate after", t_targ)
                  out_targets.append(
                      torch.stack(
                          [
                              torch.cat(
                                  [
                                      t[:-1]
                                      if len(t) > 2
                                      else t.new(1).fill_(t[0]),
                                      t.new(
                                          max_pairs + 1 - len(t)
                                      ).fill_(t[0]),
                                      t.new(1).fill_(t[-1]),
                                  ]
                              )
                              if len(t) != max_pairs + 1
                              else t
                              for t in t_targ
                          ],
                          0,
                      )
                  )
  
              t_costs = transposed_targets[
                  1
              ]  # We build the weights from the costs to have a float Tensor
              out_targets.append(
                  torch.stack(
                      [
                          torch.cat(
                              [
                                  t.new(len(t) - 1).fill_(1),
                                  t.new(max_pairs + 1 - len(t)).zero_(),
                                  t.new(1).fill_(1),
                              ]
                          )
                          if len(t) != max_pairs + 1
                          else t.new(max_pairs + 1).fill_(1)
                          for t in t_costs
                      ],
                      0,
                  )
              )
          else:
              # Remark this mask is the inverse of the weights in the above target (used for evaluation masking)
              t_base = transposed_inputs[3]
              out_targets = torch.stack(
                  [
                      torch.cat(
                          [
                              t.new(len(t) - 1).zero_().bool(),
                              t.new(max_pairs + 1 - len(t))
                              .fill_(1)
                              .bool(),
                              t.new(1).zero_().bool(),
                          ]
                      )
                      if len(t) != max_pairs + 1
                      else t.new(max_pairs + 1).zero_().bool()
                      for t in t_base
                  ],
                  0,
              )
      else:
          out_inputs = [
              torch.stack(t_inp, 0) for t_inp in transposed_inputs
          ]
          if transposed_targets is not None:
              out_targets = [
                  torch.stack(t_targ, 0)
                  for t_targ in transposed_targets
              ]
              out_targets.append(
                  out_targets[1].new(len(out_targets[1]), 1).fill_(1)
              )
          else:
              out_targets = (
                  out_inputs[0]
                  .new(len(out_inputs[0]), 1)
                  .zero_()
                  .bool()
              )
      return (out_inputs, out_targets)
  
imports: import os
  import io
  import numpy
  import torch
  import torch.utils.data
  from torch.utils.data.sampler import Sampler
  from torch.utils.data import Dataset
  from neuralcoref.train.utils import encode_distance, BATCH_SIZE_PATH, SIZE_FP, SIZE_FP_COMPRESSED, SIZE_FS, SIZE_FS_COMPRESSED, SIZE_GENRE, SIZE_PAIR_IN, SIZE_SINGLE_IN
  from neuralcoref.train.conllparser import FEATURES_NAMES
label_desc: Use image node_id 2 for calling a global function with example usage: padder_collate(batch, debug) and returns: out_inputs,  out_targets