class_docstr: :class:`KGSampler` is used to sample negative entities in a knowledge graph.
  
  Args:
      dataset (Dataset): The knowledge graph dataset, which contains triplets in a knowledge graph.
      distribution (str, optional): Distribution of the negative entities. Defaults to 'uniform'.
class_docstr_tok: [":","class",":","`","KGSampler","`","is","used","to","sample","negative","entities","in","a","knowledge","graph",".","Args",":","dataset","(","Dataset",")",":","The","knowledge","graph","dataset",",","which","contains","triplets","in","a","knowledge","graph",".","distribution","(","str",",","optional",")",":","Distribution","of","the","negative","entities",".","Defaults","to","'uniform","'","."]
docstr: Sampling by head_entity_ids.
  
  Args:
      head_entity_ids (numpy.ndarray or list): Input head_entity_ids.
      num (int, optional): Number of sampled entity_ids for each head_entity_id. Defaults to ``1``.
  
  Returns:
      torch.tensor: Sampled entity_ids.
      entity_ids[0], entity_ids[len(head_entity_ids)], entity_ids[len(head_entity_ids) * 2], ...,
      entity_id[len(head_entity_ids) * (num - 1)] is sampled for head_entity_ids[0];
      entity_ids[1], entity_ids[len(head_entity_ids) + 1], entity_ids[len(head_entity_ids) * 2 + 1], ...,
      entity_id[len(head_entity_ids) * (num - 1) + 1] is sampled for head_entity_ids[1]; ...; and so on.
docstr_tok: ["Sampling","by","head_entity_ids",".","Args",":","head_entity_ids","(","numpy.ndarray","or","list",")",":","Input","head_entity_ids",".","num","(","int",",","optional",")",":","Number","of","sampled","entity_ids","for","each","head_entity_id",".","Defaults","to","``","1","``",".","Returns",":","torch.tensor",":","Sampled","entity_ids",".","entity_ids","[","0","]",",","entity_ids","[","len","(","head_entity_ids",")","]",",","entity_ids","[","len","(","head_entity_ids",")","*","2","]",",","...",",","entity_id","[","len","(","head_entity_ids",")","*","(","num","-","1",")","]","is","sampled","for","head_entity_ids","[","0","]",";","entity_ids","[","1","]",",","entity_ids","[","len","(","head_entity_ids",")","+","1","]",",","entity_ids","[","len","(","head_entity_ids",")","*","2","+","1","]",",","...",",","entity_id","[","len","(","head_entity_ids",")","*","(","num","-","1",")","+","1","]","is","sampled","for","head_entity_ids","[","1","]",";","...",";","and","so","on","."]
code: def sample_by_entity_ids(self, head_entity_ids, num=1):
      """Sampling by head_entity_ids.
  
      Args:
          head_entity_ids (numpy.ndarray or list): Input head_entity_ids.
          num (int, optional): Number of sampled entity_ids for each head_entity_id. Defaults to ``1``.
  
      Returns:
          torch.tensor: Sampled entity_ids.
          entity_ids[0], entity_ids[len(head_entity_ids)], entity_ids[len(head_entity_ids) * 2], ...,
          entity_id[len(head_entity_ids) * (num - 1)] is sampled for head_entity_ids[0];
          entity_ids[1], entity_ids[len(head_entity_ids) + 1], entity_ids[len(head_entity_ids) * 2 + 1], ...,
          entity_id[len(head_entity_ids) * (num - 1) + 1] is sampled for head_entity_ids[1]; ...; and so on.
      """
      try:
          return self.sample_by_key_ids(head_entity_ids, num)
      except IndexError:
          for head_entity_id in head_entity_ids:
              if head_entity_id not in self.head_entities:
                  raise ValueError(
                      f"head_entity_id [{head_entity_id}] not exist."
                  )
  
imports: import copy
  import numpy
  from numpy.random import sample
  import torch
  from collections import Counter
label_desc: Use image node_id 5 for calling the KGSampler obj's underlying member method code with example usage: obj.sample_by_entity_ids(head_entity_ids, num) and returns: self