UMInteraction

class UMInteraction(p: int, power_norm: bool = True)[source]

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

The Unstructured Model (UM) interaction function.

UM calculates the score as the negative distance between head and tail entities:

\[-\|\textbf{h} - \textbf{t}\|_p^2\]

It is appropriate for networks with a single relationship type that is undirected.

Warning

In UM, neither the relations nor the directionality are considered, so it can’t distinguish between them. However, it may serve as a baseline for comparison against relation-aware models.

Initialize the norm-based interaction function.

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

relation_shape

The symbolic shapes for relation representations

Methods Summary

forward(h, r, t)

Evaluate the interaction function.

Attributes Documentation

relation_shape: Sequence[str] = ()

The symbolic shapes for relation representations

Methods Documentation

forward(h: Tensor, r: tuple[()], 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[()]) – No relation representations.

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

Returns:

shape: batch_dims The scores.

Return type:

Tensor