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","."]
docstr: Create weights for samples.
          
docstr_tok: ["Create","weights","for","samples","."]
code: def create_sample_weight(self, head, rel, tail):
      """Create weights for samples."""
      assert self._filter_dict is not None, (
          "Can not "
          "create weights of samples as filter dictionary is not given!"
      )
      weights = max(
          len(self._filter_dict["head"][(head, rel)])
          + len(self._filter_dict["tail"][(tail, rel)]),
          1.0,
      )
      weights = np.sqrt(1.0 / weights)
      return weights
  
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 6 for calling the KGDataset obj's underlying member method code with example usage: obj.create_sample_weight(head, rel, tail) and returns: weights