NodePiece
- class NodePiece(*, triples_factory: ~pykeen.triples.triples_factory.CoreTriplesFactory, num_tokens: int | ~collections.abc.Sequence[int] = 2, tokenizers: str | ~pykeen.nn.node_piece.tokenization.Tokenizer | type[~pykeen.nn.node_piece.tokenization.Tokenizer] | None | ~collections.abc.Sequence[str | ~pykeen.nn.node_piece.tokenization.Tokenizer | type[~pykeen.nn.node_piece.tokenization.Tokenizer] | None] = None, tokenizers_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None | ~collections.abc.Sequence[~collections.abc.Mapping[str, ~typing.Any] | None] = None, embedding_dim: int = 64, interaction: str | ~pykeen.nn.modules.Interaction | type[~pykeen.nn.modules.Interaction] | None = <class 'pykeen.nn.modules.DistMultInteraction'>, aggregation: str | ~collections.abc.Callable[[~torch.Tensor, int], ~torch.Tensor] | None = None, entity_initializer: str | ~collections.abc.Callable[[~torch.Tensor], ~torch.Tensor] | None = None, entity_normalizer: str | ~collections.abc.Callable[[~torch.Tensor], ~torch.Tensor] | None = None, entity_constrainer: str | ~collections.abc.Callable[[~torch.Tensor], ~torch.Tensor] | None = None, entity_regularizer: str | ~pykeen.regularizers.Regularizer | None = None, relation_initializer: str | ~collections.abc.Callable[[~torch.Tensor], ~torch.Tensor] | None = None, relation_normalizer: str | ~collections.abc.Callable[[~torch.Tensor], ~torch.Tensor] | None = None, relation_constrainer: str | ~collections.abc.Callable[[~torch.Tensor], ~torch.Tensor] | None = None, relation_regularizer: str | ~pykeen.regularizers.Regularizer | None = None, **kwargs)[source]
Bases:
ERModel
[Tensor
,Tensor
,Tensor
]A wrapper which combines an interaction function with NodePiece entity representations from [galkin2021].
This model uses the
pykeen.nn.NodePieceRepresentation
instead of a typicalpykeen.nn.representation.Embedding
to more efficiently store representations.Initialize the model.
- Parameters:
triples_factory (CoreTriplesFactory) – the triples factory. Must have create_inverse_triples set to True.
num_tokens (int | Sequence[int]) – the number of relations to use to represent each entity, cf.
pykeen.nn.NodePieceRepresentation
.tokenizers (str | Tokenizer | type[Tokenizer] | None | Sequence[str | Tokenizer | type[Tokenizer] | None]) – the tokenizer to use, cf. pykeen.nn.node_piece.tokenizer_resolver.
tokenizers_kwargs (Mapping[str, Any] | None | Sequence[Mapping[str, Any] | None]) – additional keyword-based parameters passed to the tokenizer upon construction.
embedding_dim (int) – the embedding dimension. Only used if embedding_specification is not given.
interaction (str | Interaction | type[Interaction] | None) – the interaction module, or a hint for it.
aggregation (str | Callable[[Tensor, int], Tensor] | None) –
aggregation of multiple token representations to a single entity representation. By default, this uses
torch.mean()
. If a string is provided, the module assumes that this refers to a top-level torch function, e.g. “mean” fortorch.mean()
, or “sum” for func:torch.sum. An aggregation can also have trainable parameters, .e.g.,MLP(mean(MLP(tokens)))
(cf. DeepSets from [zaheer2017]). In this case, the module has to be created outside of this component.Moreover, we support providing “mlp” as a shortcut to use the MLP aggregation version from [galkin2021].
We could also have aggregations which result in differently shapes output, e.g. a concatenation of all token embeddings resulting in shape
(num_tokens * d,)
. In this case, shape must be provided.The aggregation takes two arguments: the (batched) tensor of token representations, in shape
(*, num_tokens, *dt)
, and the index along which to aggregate.entity_initializer (str | Callable[[Tensor], Tensor] | None) – a hint for initializing anchor embeddings
entity_normalizer (str | Callable[[Tensor], Tensor] | None) – a hint for normalizing anchor embeddings
entity_constrainer (str | Callable[[Tensor], Tensor] | None) – a hint for constraining anchor embeddings
entity_regularizer (str | Regularizer | None) – a hint for regularizing anchor embeddings
relation_initializer (str | Callable[[Tensor], Tensor] | None) – a hint for initializing relation embeddings
relation_normalizer (str | Callable[[Tensor], Tensor] | None) – a hint for normalizing relation embeddings
relation_constrainer (str | Callable[[Tensor], Tensor] | None) – a hint for constraining relation embeddings
relation_regularizer (str | Regularizer | None) – a hint for regularizing relation embeddings
kwargs – additional keyword-based arguments passed to
ERModel.__init__()
- Raises:
ValueError – if the triples factory does not create inverse triples
Attributes Summary
The default strategy for optimizing the model's hyper-parameters
Attributes Documentation