code: def construct_kg_graph(rel_list) -> Dict[str, Dict[str, List[str]]]:
      """construct a kg graph with reverse link.
  
      Args:
        rel_list: KG edge list, in the format of <s, r, t> triplets.
  
      Returns:
  
      """
      kg_graph = {}
      kg_rel = {}
      for se, r, te in tqdm.tqdm(rel_list):
          if se == te:
              continue
          if se not in kg_graph:
              kg_graph[se] = {}
          if te not in kg_graph[se]:
              kg_graph[se][te] = []
          if r not in kg_graph[se][te]:
              kg_graph[se][te].append(r)
  
          if r not in kg_rel:
              kg_rel[r] = {}
          if te not in kg_rel[r]:
              kg_rel[r][te] = 0
          kg_rel[r][te] += 1
  
      for se, r, te in tqdm.tqdm(rel_list):
          if se == te or kg_rel[r][te] >= MAX_REL_PER_ENTITY:
              continue
          if te not in kg_graph:
              kg_graph[te] = {}
          if se not in kg_graph[te]:
              kg_graph[te][se] = []
          if r + "_R" not in kg_graph[te][se]:
              kg_graph[te][se].append(r + "_R")
  
      return kg_graph
  
file_path: scenic/scenic/projects/knowledge_visual_language/data/wikidata/data_util.py
imports: import json
  from typing import Any, Dict, List
  import matplotlib.pyplot
  import networkx
  import numpy
  import tqdm
  import tensorflow
  from tf.io import gfile
label_desc: Use image node_id 1 for calling a global function with example usage: construct_kg_graph(rel_list) and returns: kg_graph