code: def _gc_dataloader(
      train_size,
      q_type,
      batch_size,
      node_dict,
      edge_dict,
      label_dict,
      reverse_edge,
      path,
  ):
      def _collate_fn(batch):
          graphs = []
          labels = []
          for d in batch:
              edges = d["edges"]
  
              node_ids = []
              for s, e, t in edges:
                  if s not in node_ids:
                      node_ids.append(s)
                  if t not in node_ids:
                      node_ids.append(t)
              g = dgl.graph([])
              g.add_nodes(len(node_ids))
              g.ndata["node_id"] = torch.tensor(
                  node_ids, dtype=torch.long
              )
  
              nid2idx = dict(zip(node_ids, list(range(len(node_ids)))))
  
              labels.append(d["eval"][-1])
  
              edge_types = []
              for s, e, t in edges:
                  g.add_edges(nid2idx[s], nid2idx[t])
                  edge_types.append(e)
                  if e in reverse_edge:
                      g.add_edges(nid2idx[t], nid2idx[s])
                      edge_types.append(reverse_edge[e])
              g.edata["type"] = torch.tensor(
                  edge_types, dtype=torch.long
              )
              annotation = torch.zeros(
                  [len(node_ids), 2], dtype=torch.long
              )
              annotation[nid2idx[d["eval"][0]]][0] = 1
              annotation[nid2idx[d["eval"][2]]][1] = 1
              g.ndata["annotation"] = annotation
              graphs.append(g)
          batch_graph = dgl.batch(graphs)
          labels = torch.tensor(labels, dtype=torch.long)
          return batch_graph, labels
  
      def _get_dataloader(data, shuffle):
          return DataLoader(
              dataset=data,
              batch_size=batch_size,
              shuffle=shuffle,
              collate_fn=_collate_fn,
          )
  
      train_set, dev_set, test_sets = _convert_gc_dataset(
          train_size, node_dict, edge_dict, label_dict, path, q_type
      )
      train_dataloader = _get_dataloader(train_set, True)
      dev_dataloader = _get_dataloader(dev_set, False)
      test_dataloaders = []
      for d in test_sets:
          dl = _get_dataloader(d, False)
          test_dataloaders.append(dl)
  
      return train_dataloader, dev_dataloader, test_dataloaders
  
file_path: dgl/examples/pytorch/ggnn/data_utils.py
imports: import os
  import string
  import dgl
  import torch
  from dgl.data.utils import _get_dgl_url, download, extract_archive, get_download_dir
  from torch.utils.data import DataLoader
label_desc: Use image node_id 4 for calling a global function with example usage: _gc_dataloader(train_size, q_type, batch_size, node_dict, edge_dict, label_dict, reverse_edge, path) and returns: train_dataloader,  dev_dataloader,  test_dataloaders, batch_graph,  labels, DataLoader