class_docstr: A basic negative sampler.
  
  This negative sampler that corrupts positive triples $(h,r,t) \in \mathcal{K}$ by replacing either $h$, $r$ or $t$
  based on the chosen corruption scheme. The corruption scheme can contain $h$, $r$ and $t$ or any subset of these.
  
  Steps:
  
  1. Randomly (uniformly) determine whether $h$, $r$ or $t$ shall be corrupted for a positive triple
     $(h,r,t) \in \mathcal{K}$.
  2. Randomly (uniformly) sample an entity $e \in \mathcal{E}$ or relation $r' \in \mathcal{R}$ for selection to
     corrupt the triple.
  
     - If $h$ was selected before, the corrupted triple is $(e,r,t)$
     - If $r$ was selected before, the corrupted triple is $(h,r',t)$
     - If $t$ was selected before, the corrupted triple is $(h,r,e)$
  3. If ``filtered`` is set to ``True``, all proposed corrupted triples that also exist as
     actual positive triples $(h,r,t) \in \mathcal{K}$ will be removed.
class_docstr_tok: ["A","basic","negative","sampler",".","This","negative","sampler","that","corrupts","positive","triples","$","(","h",",","r",",","t",")","\\in","\\mathcal","{","K","}","$","by","replacing","either","$","h","$",",","$","r","$","or","$","t","$","based","on","the","chosen","corruption","scheme",".","The","corruption","scheme","can","contain","$","h","$",",","$","r","$","and","$","t","$","or","any","subset","of","these",".","Steps",":","1",".","Randomly","(","uniformly",")","determine","whether","$","h","$",",","$","r","$","or","$","t","$","shall","be","corrupted","for","a","positive","triple","$","(","h",",","r",",","t",")","\\in","\\mathcal","{","K","}","$",".","2",".","Randomly","(","uniformly",")","sample","an","entity","$","e","\\in","\\mathcal","{","E","}","$","or","relation","$","r","'","\\in","\\mathcal","{","R","}","$","for","selection","to","corrupt","the","triple",".","-","If","$","h","$","was","selected","before",",","the","corrupted","triple","is","$","(","e",",","r",",","t",")","$","-","If","$","r","$","was","selected","before",",","the","corrupted","triple","is","$","(","h",",","r","'",",","t",")","$","-","If","$","t","$","was","selected","before",",","the","corrupted","triple","is","$","(","h",",","r",",","e",")","$","3",".","If","``","filtered","``","is","set","to","``","True","``",",","all","proposed","corrupted","triples","that","also","exist","as","actual","positive","triples","$","(","h",",","r",",","t",")","\\in","\\mathcal","{","K","}","$","will","be","removed","."]
code: def corrupt_batch(
      self, positive_batch: torch.LongTensor
  ) -> torch.LongTensor:  # noqa: D102
      batch_shape = positive_batch.shape[:-1]
  
      # clone positive batch for corruption (.repeat_interleave creates a copy)
      negative_batch = positive_batch.view(-1, 3).repeat_interleave(
          self.num_negs_per_pos, dim=0
      )
  
      # Bind the total number of negatives to sample in this batch
      total_num_negatives = negative_batch.shape[0]
  
      # Equally corrupt all sides
      split_idx = int(
          math.ceil(total_num_negatives / len(self._corruption_indices))
      )
  
      # Do not detach, as no gradients should flow into the indices.
      for index, start in zip(
          self._corruption_indices,
          range(0, total_num_negatives, split_idx),
      ):
          stop = min(start + split_idx, total_num_negatives)
          random_replacement_(
              batch=negative_batch,
              index=index,
              selection=slice(start, stop),
              size=stop - start,
              max_index=self.num_relations
              if index == 1
              else self.num_entities,
          )
  
      return negative_batch.view(*batch_shape, self.num_negs_per_pos, 3)
  
file_path: pykeen/src/pykeen/sampling/basic_negative_sampler.py
imports: import math
  from typing import Collection, Optional
  import torch
  from .negative_sampler import NegativeSampler
  from ..constants import LABEL_HEAD, LABEL_TAIL, TARGET_TO_INDEX
  from ..typing import Target
label_desc: Use image node_id 2 for calling the BasicNegativeSampler obj's underlying member method code with example usage: obj.corrupt_batch(positive_batch) and returns: negative_batch