class_docstr: Dataset for knowledge graphs
  
  Args:
      triplets (list of tuples or 2D numpy.ndarray):
          The collection of training triplets (h, r, t) with shape [num_triplets, 3].
      num_ents (int):
          The number of entities in the knowledge graph.
      args (argparse.Namespace):
          Arguments of negative sampling, including:
          - neg_sample_size (int): Number of negative samples for each triplet.
          - neg_sample_type (str): The strategy used for negative sampling.
              'batch': sampling from current batch.
              'full': sampling from all entities.
              'chunk': triplets are divided into X chunks and each chunk shares
                  a group of negative samples sampled from all entities.
          - filter_sample (bool): Whether filter out existing triplets.
      filter_dict (dict, optional):
          Dictionary of existing triplets, in the form of
          {'head': {(t, r):set(h)}, 'tail': {(h, r):set(t)}}.
          Default to None.
      shared_path (dict, optional):
          Dictionary of shared embeddings' path for embedding prefetch
          in the form of {'ent': ent_path, 'rel': rel_path}.
          Default to None.
class_docstr_tok: ["Dataset","for","knowledge","graphs","Args",":","triplets","(","list","of","tuples","or","2D","numpy.ndarray",")",":","The","collection","of","training","triplets","(","h",",","r",",","t",")","with","shape","[","num_triplets",",","3","]",".","num_ents","(","int",")",":","The","number","of","entities","in","the","knowledge","graph",".","args","(","argparse.Namespace",")",":","Arguments","of","negative","sampling",",","including",":","-","neg_sample_size","(","int",")",":","Number","of","negative","samples","for","each","triplet",".","-","neg_sample_type","(","str",")",":","The","strategy","used","for","negative","sampling",".","'batch","'",":","sampling","from","current","batch",".","'full","'",":","sampling","from","all","entities",".","'chunk","'",":","triplets","are","divided","into","X","chunks","and","each","chunk","shares","a","group","of","negative","samples","sampled","from","all","entities",".","-","filter_sample","(","bool",")",":","Whether","filter","out","existing","triplets",".","filter_dict","(","dict",",","optional",")",":","Dictionary","of","existing","triplets",",","in","the","form","of","{","'head","'",":","{","(","t",",","r",")",":","set","(","h",")","}",",","'tail","'",":","{","(","h",",","r",")",":","set","(","t",")","}","}",".","Default","to","None",".","shared_path","(","dict",",","optional",")",":","Dictionary","of","shared","embeddings","'","path","for","embedding","prefetch","in","the","form","of","{","'ent","'",":","ent_path",",","'rel","'",":","rel_path","}",".","Default","to","None","."]
code: def __init__(
      self, triplets, num_ents, args, filter_dict=None, shared_path=None
  ):
      shared_ent_path = (
          shared_path.get("ent", None)
          if shared_path is not None
          else None
      )
      shared_rel_path = (
          shared_path.get("rel", None)
          if shared_path is not None
          else None
      )
  
      self._triplets = triplets
      self._num_ents = num_ents
      self._neg_sample_size = args.neg_sample_size
      self._neg_sample_type = args.neg_sample_type
      self._sample_weight = args.weighted_loss
      if self._sample_weight is True:
          assert filter_dict is not None
          assert "head" in filter_dict
          assert "tail" in filter_dict
          self._filter_dict = filter_dict
      else:
          self._filter_dict = {"head": None, "tail": None}
  
      self._filter_sample = args.filter_sample
      if self._filter_sample is True:
          raise NotImplementedError(
              "sampling with positive triplets "
              "filtered is not implemented!"
          )
  
      self._step = 0
  
      self._ent_embedding = None
      self._rel_embedding = None
      if shared_ent_path is not None:
          self._ent_embedding = np.load(shared_ent_path, mmap_mode="r+")
      if shared_rel_path is not None:
          self._rel_embedding = np.load(shared_rel_path, mmap_mode="r+")
  
imports: import os
  import numpy
  from numpy.random import default_rng
  import paddle
  from paddle.io import Dataset
  from paddle.io import DataLoader, DistributedBatchSampler
  from utils import timer_wrapper
label_desc: Use image node_id 1 to create a new KGDataset object from inherited base classes: Dataset with example: obj = KGDataset(triplets, num_ents, args, filter_dict, shared_path)