class_docstr: Implementation of knowledge graph interface in pglke.
  
  Args:
      triplets (dict):
          Triplet data of knowledge graphs with keys 'train', 'valid' and 'test'.
      num_ents (int, optional):
          Number of entities in a knowledge graph.
          If not provided, it will be inferred from triplets.
      num_rels (int, optional):
          Number of relations in a knowledge graph.
          If not provided, it will be inferred from triplets.
      ent_feat (np.ndarray, optional):
          Entity features, which have consistent order with entity ids.
      rel_feat (np.ndarray, optional):
          Relation features, which have consistent order with relation ids.
docstr: Get valid head entities for a pair of (tail, relation) in KGs.
  
  Return:
      dict: The dictionary of valid heads for all existing tail-relation pairs.
docstr_tok: ["Get","valid","head","entities","for","a","pair","of","(","tail",",","relation",")","in","KGs",".","Return",":","dict",":","The","dictionary","of","valid","heads","for","all","existing","tail-relation","pairs","."]
code: def true_heads_for_tail_rel(self):
      """
      Get valid head entities for a pair of (tail, relation) in KGs.
  
      Return:
          dict: The dictionary of valid heads for all existing tail-relation pairs.
      """
      true_pairs = defaultdict(set)
      for h, r, t in self.triplets:
          true_pairs[(t, r)].add(h)
      for k, v in true_pairs.items():
          true_pairs[k] = np.array(list(v), dtype="int32")
      return true_pairs
  
imports: import os
  import json
  from collections import defaultdict
  import numpy
label_desc: Use image node_id 8 for calling the TriGraph obj's underlying member method code with example usage: obj.true_heads_for_tail_rel() and returns: true_pairs