CombinedRepresentation
- class CombinedRepresentation(max_id: int | None, shape: int | Sequence[int] | None = None, unique: bool | None = None, base: str | Representation | type[Representation] | None | Sequence[str | Representation | type[Representation] | None] = None, base_kwargs: Mapping[str, Any] | None | Sequence[Mapping[str, Any] | None] = None, combination: str | Combination | type[Combination] | None = None, combination_kwargs: Mapping[str, Any] | None = None, **kwargs)[source]
Bases:
Representation
Combined representation.
It has a sequence of base representations, each providing a representation for each index. A combination is used to combine the multiple representations for the same index into a single one.
Example usage:
"""Example for using WikidataTextRepresentation.""" from pykeen.datasets import get_dataset from pykeen.models import ERModel from pykeen.nn import WikidataTextRepresentation from pykeen.pipeline import pipeline dataset = get_dataset(dataset="codexsmall") entity_representations = WikidataTextRepresentation.from_dataset( dataset=dataset, encoder="transformer", ) result = pipeline( dataset=dataset, model=ERModel, model_kwargs=dict( interaction="distmult", entity_representations=entity_representations, relation_representation_kwargs=dict( shape=entity_representations.shape, ), ), )
Initialize the representation.
- Parameters:
max_id (int) – The number of representations. If None, it will be inferred from the base representations.
shape (tuple[int, ...]) – The shape of an individual representation.
unique (bool | None) –
Whether to optimize for calculating representations for same indices only once. This is only useful if the calculation of representations is significantly more expensive than an index-based lookup and duplicate indices are expected, e.g., when using negative sampling and large batch sizes. If None it is inferred from the base representations.
Warning
When using this optimization you may encounter unexpected results for stochastic operations, e.g.,
torch.nn.Dropout
.base (Sequence[Representation]) – The base representations, or hints thereof.
base_kwargs (OneOrManyOptionalKwargs) – Keyword-based parameters for the instantiation of base representations.
combination (Combination) – The combination, or a hint thereof.
combination_kwargs (OptionalKwargs) – Additional keyword-based parameters used to instantiate the combination.
kwargs – Additional keyword-based parameters passed to
pykeen.nn.representation.Representation
.
- Raises:
ValueError – If the max_id of the base representations are not all the same
MaxIDMismatchError – if the
max_id
was given explicitly and does not match the bases’max_id
Note
2 resolvers are used in this function.
The parameter pair
(combination, combination_kwargs)
is used forpykeen.nn.combination.combination_resolver
The parameter pair
(base, base_kwargs)
is used forpykeen.nn.representation_resolver
An explanation of resolvers and how to use them is given in https://class-resolver.readthedocs.io/en/latest/.