PairREInteraction

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

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

The state-less norm-based PairRE interaction function.

It is given by

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

where \(\mathbf{h}, \mathbf{r}_h, \mathbf{r}_t, \mathbf{t} \in \mathbb{R}\) are representations for head entity, relation-specific head projection, relation-specific tail projection, and tail entity, respectively.

Note

pykeen.models.PairRE additionally enforces \(\|\mathbf{h}\| = \|\mathbf{t}\| = 1\).

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

relation_shape

The symbolic shapes for relation representations

Methods Summary

forward(h, r, t)

Evaluate the interaction function.

Attributes Documentation

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

The symbolic shapes for relation representations

Methods Documentation

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

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

Returns:

shape: batch_dims The scores.

Return type:

Tensor