code: def collate_fn(self, data):
      batch_data = {}
      if self.sampling_mode == "normal":
          batch_data["mode"] = "normal"
          batch_h = np.array([item[0] for item in data]).reshape(-1, 1)
          batch_t = np.array([item[1] for item in data]).reshape(-1, 1)
          batch_r = np.array([item[2] for item in data]).reshape(-1, 1)
          batch_h = np.repeat(
              batch_h, 1 + self.neg_ent + self.neg_rel, axis=-1
          )
          batch_t = np.repeat(
              batch_t, 1 + self.neg_ent + self.neg_rel, axis=-1
          )
          batch_r = np.repeat(
              batch_r, 1 + self.neg_ent + self.neg_rel, axis=-1
          )
          for index, item in enumerate(data):
              last = 1
              if self.neg_ent > 0:
                  neg_head, neg_tail = self.__normal_batch(
                      item[0], item[1], item[2], self.neg_ent
                  )
                  if len(neg_head) > 0:
                      batch_h[index][
                          last : last + len(neg_head)
                      ] = neg_head
                      last += len(neg_head)
                  if len(neg_tail) > 0:
                      batch_t[index][
                          last : last + len(neg_tail)
                      ] = neg_tail
                      last += len(neg_tail)
              if self.neg_rel > 0:
                  neg_rel = self.__rel_batch(
                      item[0], item[1], item[2], self.neg_rel
                  )
                  batch_r[index][last : last + len(neg_rel)] = neg_rel
          batch_h = batch_h.transpose()
          batch_t = batch_t.transpose()
          batch_r = batch_r.transpose()
      else:
          self.cross_sampling_flag = 1 - self.cross_sampling_flag
          if self.cross_sampling_flag == 0:
              batch_data["mode"] = "head_batch"
              batch_h = np.array([[item[0]] for item in data])
              batch_t = np.array([item[1] for item in data])
              batch_r = np.array([item[2] for item in data])
              batch_h = np.repeat(batch_h, 1 + self.neg_ent, axis=-1)
              for index, item in enumerate(data):
                  neg_head = self.__head_batch(
                      item[0], item[1], item[2], self.neg_ent
                  )
                  batch_h[index][1:] = neg_head
              batch_h = batch_h.transpose()
          else:
              batch_data["mode"] = "tail_batch"
              batch_h = np.array([item[0] for item in data])
              batch_t = np.array([[item[1]] for item in data])
              batch_r = np.array([item[2] for item in data])
              batch_t = np.repeat(batch_t, 1 + self.neg_ent, axis=-1)
              for index, item in enumerate(data):
                  neg_tail = self.__tail_batch(
                      item[0], item[1], item[2], self.neg_ent
                  )
                  batch_t[index][1:] = neg_tail
              batch_t = batch_t.transpose()
  
      batch_y = np.concatenate(
          [
              np.ones((len(data), 1)),
              np.zeros((len(data), self.neg_ent + self.neg_rel)),
          ],
          -1,
      ).transpose()
      batch_data["batch_h"] = batch_h.squeeze()
      batch_data["batch_t"] = batch_t.squeeze()
      batch_data["batch_r"] = batch_r.squeeze()
      batch_data["batch_y"] = batch_y.squeeze()
      return batch_data
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import random
  import numpy
  import torch
  from torch.utils.data import Dataset, DataLoader
label_desc: Use image node_id 4 for calling the PyTorchTrainDataset obj's underlying member method code with example usage: obj.collate_fn(data) and returns: batch_data