PairRE
- class PairRE(embedding_dim: int = 200, p: int = 1, power_norm: bool = False, entity_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function uniform_>, entity_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, entity_normalizer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function normalize>, entity_normalizer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, relation_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function uniform_>, relation_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, **kwargs)[source]
Bases:
ERModel
[Tensor
,tuple
[Tensor
,Tensor
],Tensor
]An implementation of PairRE from [chao2020].
This model represents entities as \(d\)-dimensional vectors, and relations by a pair of \(d\)-dimensional vectors, all stored in an
Embedding
matrix. Moreover, it enforces unit length for the entity embeddings.The representations are then passed to the
PairREInteraction
function to obtain scores.Initialize the model.
- Parameters:
embedding_dim (int) – The entity embedding dimension \(d\).
p (int) – The norm used with
torch.linalg.vector_norm()
. Typically is 1 or 2.power_norm (bool) – Whether to use the p-th power of the \(L_p\) norm. It has the advantage of being differentiable around 0, and numerically more stable.
entity_initializer (str | Callable[[Tensor], Tensor] | None) – Entity initializer function. Defaults to
torch.nn.init.uniform_()
entity_initializer_kwargs (Mapping[str, Any] | None) – Keyword arguments to be used when calling the entity initializer
entity_normalizer (str | Callable[[Tensor], Tensor] | None) – Entity normalizer function. Defaults to
torch.nn.functional.normalize()
entity_normalizer_kwargs (Mapping[str, Any] | None) – Keyword arguments to be used when calling the entity normalizer
relation_initializer (str | Callable[[Tensor], Tensor] | None) – Relation initializer function. Defaults to
torch.nn.init.uniform_()
relation_initializer_kwargs (Mapping[str, Any] | None) – Keyword arguments to be used when calling the relation initializer
kwargs – Remaining keyword arguments passed through to
ERModel
.
Attributes Summary
The default entity normalizer parameters The entity representations are normalized to L2 unit length cf.
The default strategy for optimizing the model's hyper-parameters
The default parameters for the default loss function class
Attributes Documentation
- default_entity_normalizer_kwargs: ClassVar[Mapping[str, Any]] = {'dim': -1, 'p': 2}
The default entity normalizer parameters The entity representations are normalized to L2 unit length cf. https://github.com/alipay/KnowledgeGraphEmbeddingsViaPairedRelationVectors_PairRE/blob/0a95bcd54759207984c670af92ceefa19dd248ad/biokg/model.py#L232-L240 # noqa: E501