class_docstr: Tokenize entities by representing them as a bag of relations.
class_docstr_tok: ["Tokenize","entities","by","representing","them","as","a","bag","of","relations","."]
code: def __call__(
      self,
      mapped_triples: MappedTriples,
      num_tokens: int,
      num_entities: int,
      num_relations: int,
  ) -> Tuple[int, torch.LongTensor]:  # noqa: D102
      # tokenize: represent entities by bag of relations
      h, r, t = mapped_triples.t()
  
      # collect candidates
      e2r = defaultdict(set)
      for e, r_ in (
          torch.cat(
              [
                  torch.stack([h, r], dim=1),
                  torch.stack([t, r + num_relations], dim=1),
              ],
              dim=0,
          )
          .unique(dim=0)
          .tolist()
      ):
          e2r[e].add(r_)
  
      # randomly sample without replacement num_tokens relations for each entity
      return 2 * num_relations + 1, random_sample_no_replacement(
          pool=e2r, num_tokens=num_tokens, num_entities=num_entities
      )
  
imports: import logging
  import pathlib
  from abc import abstractmethod
  from collections import defaultdict
  from typing import Collection, Mapping, Optional, Tuple
  import more_itertools
  import numpy
  import torch
  from class_resolver import ClassResolver, HintOrType, OptionalKwargs
  from .anchor_search import AnchorSearcher, anchor_searcher_resolver
  from .anchor_selection import AnchorSelection, anchor_selection_resolver
  from .loader import PrecomputedTokenizerLoader, precomputed_tokenizer_loader_resolver
  from .utils import prepare_edges_for_metis, random_sample_no_replacement
  from ...constants import PYKEEN_MODULE
  from ...typing import DeviceHint, MappedTriples
  from ...utils import format_relative_comparison, get_edge_index, resolve_device
label_desc: Use image node_id 1 for calling the RelationTokenizer obj's underlying member method code with example usage: obj.__call__(mapped_triples, num_tokens, num_entities, num_relations) and returns: unknown,  random_sample_no_replacement