ComplExInteraction

class ComplExInteraction(*args, **kwargs)[source]

Bases: Interaction[Tensor, Tensor, Tensor]

The ComplEx interaction proposed by [trouillon2016].

ComplEx operates on complex-valued entity and relation representations, i.e., \(\mathbf{e}_i, \mathbf{r}_i \in \mathbb{C}^d\) and calculates the plausibility score via the Hadamard product:

\[f(h,r,t) = Re(\left\langle \mathbf{e}_h, \mathbf{r}_r, \bar{\mathbf{e}}_t\right\rangle)\]

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(\mathbf{x})\) and \(Im(\mathbf{x})\) denote the real and imaginary parts of the complex valued vector \(\mathbf{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/

Note

this method generally expects all tensors to be of complex datatype, i.e., torch.is_complex(x) to evaluate to True. However, for backwards compatibility and convenience in use, you can also pass real tensors whose shape is compliant with torch.view_as_complex(), cf. pykeen.utils.ensure_complex().

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Attributes Summary

is_complex

whether the interaction is defined on complex input

Methods Summary

forward(h, r, t)

Evaluate the interaction function.

Attributes Documentation

is_complex: ClassVar[bool] = True

whether the interaction is defined on complex input

Methods Documentation

forward(h: Tensor, r: Tensor, t: Tensor) Tensor[source]

Evaluate the interaction function.

See also

Interaction.forward for a detailed description about the generic batched form of the interaction function.

Parameters:
  • h (Tensor) – shape: (*batch_dims, d) The head representations.

  • r (Tensor) – shape: (*batch_dims, d) The relation representations.

  • t (Tensor) – shape: (*batch_dims, d) The tail representations.

Returns:

shape: batch_dims The scores.

Return type:

Tensor