RotatEInteraction

class RotatEInteraction(p: int = 2, power_norm: bool = False)[source]

Bases: NormBasedInteraction[Tensor, Tensor, Tensor]

The RotatE interaction function proposed by [sun2019].

RotatE operates on complex-valued entity and relation representations, i.e., \(\mathbf{e}_i, \mathbf{r}_i \in \mathbb{C}^d\).

The interaction function is given by

\[\| \mathbf{h} \odot \mathbf{r} - \mathbf{t} \|\]

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 with an even last dimension holding interleaved pairs of real and imaginary parts, i.e., a real tensor of shape (*, 2 * d) is interpreted as a complex tensor of shape (*, d), cf. ensure_complex().

Initialize the interaction module.

See also

The parameter p and power_norm are directly passed to NormBasedInteraction.

Parameters:
  • 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.

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