MuREInteraction

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

Bases: NormBasedInteraction[tuple[Tensor, Tensor], tuple[Tensor, Tensor], tuple[Tensor, Tensor]]

The norm-based MuRE interaction function from [balazevic2019b].

For \(\mathbf{h}, \mathbf{r}, \mathbf{R}, \mathbf{t} \in \mathbb{R}^d\), and \(b_h, b_t \in \mathbb{R}\), it is given by

\[-\|\mathbf{R} \odot \mathbf{h} + \mathbf{r} - \mathbf{t}\| + b_h + b_t\]

where \(\mathbf{h}, \mathbf{r}, \mathbf{t}\) are head entity, relation, and tail entity embedding vectors, \(\mathbf{R}\) is a diagonal relation matrix, and \(b_h, b_t\) are head and tail entity biases.

Note

This module implements a slightly more generic function, where the norm \(\| \cdot \|_p\) can be chosen, as well as a variant which uses \(\| \cdot \|_p^p\), cf. NormBasedInteraction.

Initialize the norm-based interaction function.

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

entity_shape

The symbolic shapes for entity representations

relation_shape

The symbolic shapes for relation representations

Methods Summary

forward(h, r, t)

Evaluate the interaction function.

Attributes Documentation

entity_shape: Sequence[str] = ('d', '', '')

The symbolic shapes for entity representations

relation_shape: Sequence[str] = ('d', 'd')

The symbolic shapes for relation representations

Methods Documentation

forward(h: tuple[Tensor, Tensor], r: tuple[Tensor, Tensor], t: tuple[Tensor, 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 (tuple[Tensor, Tensor]) – shape: (*batch_dims, d) and (*batch_dims) The head representations.

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

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

Returns:

shape: batch_dims The scores.

Return type:

Tensor