class_docstr: Basic implementation of node piece decomposition [galkin2021]_.
  
  .. math ::
      x_e = agg(\{T[t] \mid t \in tokens(e) \})
  
  where $T$ are token representations, $tokens$ selects a fixed number of $k$ tokens for each entity, and $agg$ is
  an aggregation function, which aggregates the individual token representations to a single entity representation.
  
  ---
  name: NodePiece
  citation:
      author: Galkin
      year: 2021
      link: https://arxiv.org/abs/2106.12144
      github: https://github.com/migalkin/NodePiece
class_docstr_tok: ["Basic","implementation","of","node","piece","decomposition","[","galkin2021","]","_",".","..","math",":",":","x_e","=","agg","(","\\","{","T","[","t","]","\\mid","t","\\in","tokens","(","e",")","\\","}",")","where","$","T","$","are","token","representations",",","$","tokens","$","selects","a","fixed","number","of","$","k","$","tokens","for","each","entity",",","and","$","agg","$","is","an","aggregation","function",",","which","aggregates","the","individual","token","representations","to","a","single","entity","representation",".","--","-","name",":","NodePiece","citation",":","author",":","Galkin","year",":","2021","link",":","https",":","\/\/arxiv.org\/abs\/2106.12144","github",":","https",":","\/\/github.com\/migalkin\/NodePiece"]
docstr: Estimate the diversity of the tokens via their hashes.
  
  :return:
      A ratio information tuple
  
  Tokenization strategies might produce exactly the same hashes for
  several nodes depending on the graph structure and tokenization
  parameters. Same hashes will result in same node representations
  and, hence, might inhibit the downstream performance.
  This function comes handy when you need to estimate the diversity
  of built node hashes under a certain tokenization strategy - ideally,
  you'd want every node to have a unique hash.
  The function computes how many node hashes are unique in each
  representation and overall (if we concat all of them in a single row).
  1.0 means that all nodes have unique hashes.
  
  Example usage:
  
  .. code-block::
  
      from pykeen.model import NodePiece
  
      model = NodePiece(
          triples_factory=dataset.training,
          tokenizers=["AnchorTokenizer", "RelationTokenizer"],
          num_tokens=[20, 12],
          embedding_dim=64,
          interaction="rotate",
          relation_constrainer="complex_normalize",
          entity_initializer="xavier_uniform_",
      )
      print(model.entity_representations[0].estimate_diversity())
  
  .. seealso:: https://github.com/pykeen/pykeen/pull/896
docstr_tok: ["Estimate","the","diversity","of","the","tokens","via","their","hashes",".",":","return",":","A","ratio","information","tuple","Tokenization","strategies","might","produce","exactly","the","same","hashes","for","several","nodes","depending","on","the","graph","structure","and","tokenization","parameters",".","Same","hashes","will","result","in","same","node","representations","and",",","hence",",","might","inhibit","the","downstream","performance",".","This","function","comes","handy","when","you","need","to","estimate","the","diversity","of","built","node","hashes","under","a","certain","tokenization","strategy","-","ideally",",","you","'d","want","every","node","to","have","a","unique","hash",".","The","function","computes","how","many","node","hashes","are","unique","in","each","representation","and","overall","(","if","we","concat","all","of","them","in","a","single","row",")",".","1.0","means","that","all","nodes","have","unique","hashes",".","Example","usage",":","..","code-block",":",":","from","pykeen.model","import","NodePiece","model","=","NodePiece","(","triples_factory=dataset.training",",","tokenizers=","[","``","AnchorTokenizer","''",",","``","RelationTokenizer","''","]",",","num_tokens=","[","20",",","12","]",",","embedding_dim=64",",","interaction=","''","rotate","''",",","relation_constrainer=","''","complex_normalize","''",",","entity_initializer=","''","xavier_uniform_","''",",",")","print","(","model.entity_representations","[","0","]",".estimate_diversity","(",")",")","..","seealso",":",":","https",":","\/\/github.com\/pykeen\/pykeen\/pull\/896"]
code: def estimate_diversity(self) -> HashDiversityInfo:
      """
      Estimate the diversity of the tokens via their hashes.
  
      :return:
          A ratio information tuple
  
      Tokenization strategies might produce exactly the same hashes for
      several nodes depending on the graph structure and tokenization
      parameters. Same hashes will result in same node representations
      and, hence, might inhibit the downstream performance.
      This function comes handy when you need to estimate the diversity
      of built node hashes under a certain tokenization strategy - ideally,
      you'd want every node to have a unique hash.
      The function computes how many node hashes are unique in each
      representation and overall (if we concat all of them in a single row).
      1.0 means that all nodes have unique hashes.
  
      Example usage:
  
      .. code-block::
  
          from pykeen.model import NodePiece
  
          model = NodePiece(
              triples_factory=dataset.training,
              tokenizers=["AnchorTokenizer", "RelationTokenizer"],
              num_tokens=[20, 12],
              embedding_dim=64,
              interaction="rotate",
              relation_constrainer="complex_normalize",
              entity_initializer="xavier_uniform_",
          )
          print(model.entity_representations[0].estimate_diversity())
  
      .. seealso:: https://github.com/pykeen/pykeen/pull/896
      """
      # unique hashes per representation
      uniques_per_representation = [
          tokens.assignment.unique(dim=0).shape[0] / self.max_id
          for tokens in self.base
      ]
  
      # unique hashes if we concatenate all representations together
      unnormalized_uniques_total = torch.unique(
          torch.cat(
              [tokens.assignment for tokens in self.base], dim=-1
          ),
          dim=0,
      ).shape[0]
      return HashDiversityInfo(
          uniques_per_representation=uniques_per_representation,
          uniques_total=unnormalized_uniques_total / self.max_id,
      )
  
imports: import logging
  import pathlib
  from typing import Callable, Iterable, List, NamedTuple, Optional, Union
  import torch
  from class_resolver import HintOrType, OneOrManyHintOrType, OneOrManyOptionalKwargs, OptionalKwargs
  from docdata import parse_docdata
  from .tokenization import Tokenizer, tokenizer_resolver
  from ..combination import ConcatAggregationCombination
  from ..perceptron import ConcatMLP
  from ..representation import CombinedRepresentation, Representation
  from ..utils import ShapeError
  from ...triples import CoreTriplesFactory
  from ...typing import MappedTriples, OneOrSequence
  from ...utils import broadcast_upgrade_to_sequences
label_desc: Use image node_id 2 for calling the NodePieceRepresentation obj's underlying member method code with example usage: obj.estimate_diversity() and returns: HashDiversityInfo