TransRInteraction

class TransRInteraction(p: int, power_norm: bool = True, max_projection_norm: float = 1.0)[source]

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

The state-less norm-based TransR interaction function.

It is given by

\[-\|c(\mathbf{M}_{r}\mathbf{h}) + \mathbf{r} - c(\mathbf{M}_{r}\mathbf{t})\|_{2}^2\]

for head and tail entity representations \(\mathbf{h}, \mathbf{t} \in \mathbb{R}^d\), relation representation \(\mathbf{r} \in \mathbb{R}^k\), and a relation-specific projection matrix \(\mathbf{M}_r \in \mathbb{R}^{k \times d}\). \(c\) enforces the constraint \(\|\cdot\| \leq 1\), cf. pykeen.utils.clamp_norm().

Note

pykeen.models.TransR additionally also enforces \(\|\cdot\| \leq 1\) on all embeddings.

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.

  • max_projection_norm (float) – The maximum norm to be clamped after projection.

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] = ('e', 'de')

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, k) and (*batch_dims, d, k) The relation representations.

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

Returns:

shape: batch_dims The scores.

Return type:

Tensor