ERMLPEInteraction

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

Bases: FunctionalInteraction[FloatTensor, FloatTensor, FloatTensor]

A stateful module for the ER-MLP (E) interaction function.

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

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

whereas in ER-MLP (E) the interaction 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, the ConvE interaction 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 (Optional[int]) – the hidden dimension of the MLP. Defaults to embedding_dim.

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

  • hidden_dropout (Optional[float]) – the dropout applied after the first layer

Methods Summary

func(r, t, mlp)

Evaluate the ER-MLPE interaction function.

Methods Documentation

func(r, t, mlp)

Evaluate the ER-MLPE interaction function.

Parameters:
  • h (FloatTensor) – shape: (*batch_dims, dim) The head representations.

  • r (FloatTensor) – shape: (*batch_dims, dim) The relation representations.

  • t (FloatTensor) – shape: (*batch_dims, dim) The tail representations.

  • mlp (Module) – The MLP.

Return type:

FloatTensor

Returns:

shape: batch_dims The scores.