ERMLPEInteraction

class ERMLPEInteraction(embedding_dim: int = 256, input_dropout: float = 0.2, hidden_dim: int | None = None, hidden_dropout: float | None = None)[source]

Bases: Interaction[Tensor, Tensor, Tensor]

The stateful ER-MLP (E) interaction function.

This interaction uses a neural network-based approach similar to ER-MLP and with slight modifications. In ERMLPInteraction, the interaction is:

\[f(h, r, t) = \textbf{w}^{T} g(\textbf{W} [\textbf{h}; \textbf{r}; \textbf{t}])\]

whereas here it is:

\[f(h, r, t) = \textbf{t}^{T} f(\textbf{W} (g(\textbf{W} [\textbf{h}; \textbf{r}]))\]

including dropouts and batch-norms between each two hidden layers. Thus, ConvEInteraction can be seen as a special case of ERMLP (E).

Initialize the interaction module.

Parameters:
  • embedding_dim (int) – the embedding dimension of entities and relations

  • hidden_dim (int | None) – the hidden dimension of the MLP. Defaults to embedding_dim.

  • input_dropout (float) – the dropout applied before the first layer

  • hidden_dropout (float | None) – the dropout applied after the first layer

Methods Summary

forward(h, r, t)

Compute broadcasted triple scores given broadcasted representations for head, relation and tails.

Methods Documentation

forward(h: Tensor, r: Tensor, t: Tensor) Tensor[source]

Compute broadcasted triple scores given broadcasted representations for head, relation and tails.

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