code: def process_amazon(root_path):
      # User-Item 3584 2753 50903 UIUI
      # Item-View 2753 3857 5694 UIVI
      # Item-Brand 2753 334 2753 UIBI
      # Item-Category 2753 22 5508 UICI
  
      # Construct graph from raw data.
      # load data of amazon
      data_path = os.path.join(root_path, "Amazon")
      if not (os.path.exists(data_path)):
          print(
              "Can not find amazon in {}, please download the dataset first.".format(
                  data_path
              )
          )
  
      # item_view
      item_view_src = []
      item_view_dst = []
      with open(os.path.join(data_path, "item_view.dat")) as fin:
          for line in fin.readlines():
              _line = line.strip().split(",")
              item, view = int(_line[0]), int(_line[1])
              item_view_src.append(item)
              item_view_dst.append(view)
  
      # user_item
      user_item_src = []
      user_item_dst = []
      with open(os.path.join(data_path, "user_item.dat")) as fin:
          for line in fin.readlines():
              _line = line.strip().split("\t")
              user, item, rate = (
                  int(_line[0]),
                  int(_line[1]),
                  int(_line[2]),
              )
              if rate > 3:
                  user_item_src.append(user)
                  user_item_dst.append(item)
  
      # item_brand
      item_brand_src = []
      item_brand_dst = []
      with open(os.path.join(data_path, "item_brand.dat")) as fin:
          for line in fin.readlines():
              _line = line.strip().split(",")
              item, brand = int(_line[0]), int(_line[1])
              item_brand_src.append(item)
              item_brand_dst.append(brand)
  
      # item_category
      item_category_src = []
      item_category_dst = []
      with open(os.path.join(data_path, "item_category.dat")) as fin:
          for line in fin.readlines():
              _line = line.strip().split(",")
              item, category = int(_line[0]), int(_line[1])
              item_category_src.append(item)
              item_category_dst.append(category)
  
      # build graph
      hg = dgl.heterograph(
          {
              ("item", "iv", "view"): (item_view_src, item_view_dst),
              ("view", "vi", "item"): (item_view_dst, item_view_src),
              ("user", "ui", "item"): (user_item_src, user_item_dst),
              ("item", "iu", "user"): (user_item_dst, user_item_src),
              ("item", "ib", "brand"): (item_brand_src, item_brand_dst),
              ("brand", "bi", "item"): (item_brand_dst, item_brand_src),
              ("item", "ic", "category"): (
                  item_category_src,
                  item_category_dst,
              ),
              ("category", "ci", "item"): (
                  item_category_dst,
                  item_category_src,
              ),
          }
      )
  
      print("Graph constructed.")
  
      # Split data into train/eval/test
      train_data, eval_data, test_data = split_data(hg, "ui")
  
      # delete the positive edges in eval/test data in the original graph
      train_pos = np.nonzero(train_data[:, 2])
      train_pos_idx = train_pos[0]
      user_item_src_processed = train_data[train_pos_idx, 0]
      user_item_dst_processed = train_data[train_pos_idx, 1]
      edges_dict = {
          ("item", "iv", "view"): (item_view_src, item_view_dst),
          ("view", "vi", "item"): (item_view_dst, item_view_src),
          ("user", "ui", "item"): (
              user_item_src_processed,
              user_item_dst_processed,
          ),
          ("item", "iu", "user"): (
              user_item_dst_processed,
              user_item_src_processed,
          ),
          ("item", "ib", "brand"): (item_brand_src, item_brand_dst),
          ("brand", "bi", "item"): (item_brand_dst, item_brand_src),
          ("item", "ic", "category"): (
              item_category_src,
              item_category_dst,
          ),
          ("category", "ci", "item"): (
              item_category_dst,
              item_category_src,
          ),
      }
      nodes_dict = {
          "user": hg.num_nodes("user"),
          "item": hg.num_nodes("item"),
          "view": hg.num_nodes("view"),
          "brand": hg.num_nodes("brand"),
          "category": hg.num_nodes("category"),
      }
      hg_processed = dgl.heterograph(
          data_dict=edges_dict, num_nodes_dict=nodes_dict
      )
      print("Graph processed.")
  
      # save the processed data
      with open(os.path.join(root_path, "amazon_hg.pkl"), "wb") as file:
          pkl.dump(hg_processed, file)
      with open(
          os.path.join(root_path, "amazon_train.pkl"), "wb"
      ) as file:
          pkl.dump(train_data, file)
      with open(
          os.path.join(root_path, "amazon_test.pkl"), "wb"
      ) as file:
          pkl.dump(test_data, file)
      with open(
          os.path.join(root_path, "amazon_eval.pkl"), "wb"
      ) as file:
          pkl.dump(eval_data, file)
  
      return hg_processed, train_data, eval_data, test_data
  
file_path: dgl/examples/pytorch/TAHIN/data_loader.py
imports: import os
  import pickle
  import random
  import dgl
  import numpy
  import torch
  from torch.utils.data import DataLoader, Dataset
label_desc: Use image node_id 2 for calling a global function with example usage: process_amazon(root_path) and returns: hg_processed,  train_data,  eval_data,  test_data