ComplEx
- class ComplEx(*, embedding_dim=200, entity_initializer=<function normal_>, relation_initializer=<function normal_>, regularizer=<class 'pykeen.regularizers.LpRegularizer'>, regularizer_kwargs=None, **kwargs)[source]
Bases:
pykeen.models.nbase.ERModel
An implementation of ComplEx [trouillon2016].
ComplEx is an extension of
pykeen.models.DistMult
that uses complex valued representations for the entities and relations. Entities and relations are represented as vectors \(\textbf{e}_i, \textbf{r}_i \in \mathbb{C}^d\), and the plausibility score is computed using the Hadamard product:\[f(h,r,t) = Re(\mathbf{e}_h\odot\mathbf{r}_r\odot\bar{\mathbf{e}}_t)\]Which expands to:
\[f(h,r,t) = \left\langle Re(\mathbf{e}_h),Re(\mathbf{r}_r),Re(\mathbf{e}_t)\right\rangle + \left\langle Im(\mathbf{e}_h),Re(\mathbf{r}_r),Im(\mathbf{e}_t)\right\rangle + \left\langle Re(\mathbf{e}_h),Im(\mathbf{r}_r),Im(\mathbf{e}_t)\right\rangle - \left\langle Im(\mathbf{e}_h),Im(\mathbf{r}_r),Re(\mathbf{e}_t)\right\rangle\]where \(Re(\textbf{x})\) and \(Im(\textbf{x})\) denote the real and imaginary parts of the complex valued vector \(\textbf{x}\). Because the Hadamard product is not commutative in the complex space, ComplEx can model anti-symmetric relations in contrast to DistMult.
See also
Official implementation: https://github.com/ttrouill/complex/
Initialize ComplEx.
- Parameters
embedding_dim (
int
) – The embedding dimensionality of the entity embeddings.entity_initializer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – Entity initializer function. Defaults totorch.nn.init.normal_()
relation_initializer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – Relation initializer function. Defaults totorch.nn.init.normal_()
regularizer (
Union
[str
,Regularizer
,Type
[Regularizer
],None
]) – the regularizer to apply.regularizer_kwargs (
Optional
[Mapping
[str
,Any
]]) – additional keyword arguments passed to the regularizer. Defaults to ComplEx.regularizer_default_kwargs.kwargs – Remaining keyword arguments to forward to
pykeen.models.EntityRelationEmbeddingModel
Attributes Summary
The default strategy for optimizing the model's hyper-parameters
The default parameters for the default loss function class
The LP settings used by [trouillon2016] for ComplEx.
Attributes Documentation
- hpo_default: ClassVar[Mapping[str, Any]] = {'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}}
The default strategy for optimizing the model’s hyper-parameters
- loss_default_kwargs: ClassVar[Mapping[str, Any]] = {'reduction': 'mean'}
The default parameters for the default loss function class
- regularizer_default_kwargs: ClassVar[Mapping[str, Any]] = {'normalize': True, 'p': 2.0, 'weight': 0.01}
The LP settings used by [trouillon2016] for ComplEx.