code: def batch_fn(self, batch_ex):
      batch_src = []
      batch_dst = []
      batch_neg = []
      for batch in batch_ex:
          batch_src.append(batch[0])
          batch_dst.append(batch[1])
          if len(batch) == 3:  # default neg samples
              batch_neg.append(batch[2])
  
      if len(batch_src) != self.batch_size:
          if self.phase == "train":
              return None  # Skip
  
      if len(batch_neg) > 0:
          batch_neg = np.unique(np.concatenate(batch_neg))
      batch_src = np.array(batch_src, dtype="int64")
      batch_dst = np.array(batch_dst, dtype="int64")
  
      if self.neg_type == "batch_neg":
          batch_neg = batch_dst
      else:
          # TODO user define shape of neg_sample
          neg_shape = batch_dst.shape
          sampled_batch_neg = alias_sample(
              neg_shape, self.alias, self.events
          )
          batch_neg = np.concatenate([batch_neg, sampled_batch_neg], 0)
  
      if self.phase == "train":
          # TODO user define ignore edges or not
          # ignore_edges = np.concatenate([np.stack([batch_src, batch_dst], 1), np.stack([batch_dst, batch_src], 1)], 0)
          ignore_edges = set()
      else:
          ignore_edges = set()
  
      nodes = np.unique(
          np.concatenate([batch_src, batch_dst, batch_neg], 0)
      )
      subgraphs = graphsage_sample(
          self.graph, nodes, self.samples, ignore_edges=ignore_edges
      )
      subgraph = subgraphs[0]
      subgraphs[0].node_feat["index"] = (
          subgraphs[0]
          .reindex_to_parrent_nodes(subgraphs[0].nodes)
          .astype(np.int64)
      )
      subgraphs[0].node_feat["term_ids"] = self.term_ids[
          subgraphs[0].node_feat["index"]
      ].astype(np.int64)
  
      # only reindex from first subgraph
      sub_src_idx = subgraphs[0].reindex_from_parrent_nodes(batch_src)
      sub_dst_idx = subgraphs[0].reindex_from_parrent_nodes(batch_dst)
      sub_neg_idx = subgraphs[0].reindex_from_parrent_nodes(batch_neg)
  
      user_index = np.array(sub_src_idx, dtype="int64")
      pos_item_index = np.array(sub_dst_idx, dtype="int64")
      neg_item_index = np.array(sub_neg_idx, dtype="int64")
  
      user_real_index = np.array(batch_src, dtype="int64")
      pos_item_real_index = np.array(batch_dst, dtype="int64")
  
      num_nodes = np.array([len(subgraph.nodes)], np.int32)
      num_edges = np.array([len(subgraph.edges)], np.int32)
      edges = subgraph.edges
      node_feat = subgraph.node_feat
      edge_feat = subgraph.edge_feat
  
      # pairwise training with label 1.
      fake_label = np.ones_like(user_index)
  
      if self.phase == "train":
          return (
              num_nodes,
              num_edges,
              edges,
              node_feat["index"],
              node_feat["term_ids"],
              user_index,
              pos_item_index,
              neg_item_index,
              user_real_index,
              pos_item_real_index,
              fake_label,
          )
      else:
          return (
              num_nodes,
              num_edges,
              edges,
              node_feat["index"],
              node_feat["term_ids"],
              user_index,
              pos_item_index,
              neg_item_index,
              user_real_index,
              pos_item_real_index,
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from __future__ import absolute_import
  import os
  import pgl
  import sys
  import numpy
  from pgl.utils.logger import log
  from dataset.base_dataset import BaseDataGenerator
  from pgl.sample import alias_sample
  from pgl.sample import pinsage_sample
  from pgl.sample import graphsage_sample
  from pgl.sample import edge_hash
label_desc: Use image node_id 1 for calling the BatchGraphGenerator obj's underlying member method code with example usage: obj.batch_fn(batch_ex) and returns: num_nodes,  num_edges,  edges,  node_feat,  node_feat,  user_index,  pos_item_index,  neg_item_index,  user_real_index,  pos_item_real_index,  fake_label, num_nodes,  num_edges,  edges,  node_feat,  node_feat,  user_index,  pos_item_index,  neg_item_index,  user_real_index,  pos_item_real_index, None