ERMLPInteraction
- class ERMLPInteraction(embedding_dim: int, hidden_dim: int | None = None, activation: str | ~torch.nn.modules.module.Module | type[~torch.nn.modules.module.Module] | None = <class 'torch.nn.modules.activation.ReLU'>, activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None)[source]
Bases:
Interaction
[Tensor
,Tensor
,Tensor
]The ER-MLP stateful interaction function.
ER-MLP uses a multi-layer perceptron based approach with a single hidden layer. The \(d\)-dimensional representations of head entity, relation, and tail entity are concatenated and passed to the hidden layer. The output-layer consists of a single neuron that computes the plausibility score:
\[f(\mathbf{h}, \mathbf{r}, \mathbf{t}) = \mathbf{w}^{T} g(\mathbf{W} [\mathbf{h}; \mathbf{r}; \mathbf{t}]),\]where \(\textbf{W} \in \mathbb{R}^{k \times 3d}\) represents the weight matrix of the hidden layer, \(\textbf{w} \in \mathbb{R}^{k}\), the weights of the output layer, and \(g\) denotes an activation function such as the hyperbolic tangent.
Initialize the interaction module.
- Parameters:
embedding_dim (int) – The embedding vector dimension for entities and relations.
hidden_dim (int | None) – The hidden dimension of the MLP. Defaults to embedding_dim.
activation (HintOrType[nn.Module]) – The activation function or a hint thereof.
activation_kwargs (OptionalKwargs) – Additional keyword-based parameters passed to the activation’s constructor, if the activation is not pre-instantiated.
Note
The parameter pair
(activation, activation_kwargs)
is used forclass_resolver.contrib.torch.activation_resolver
An explanation of resolvers and how to use them is given in https://class-resolver.readthedocs.io/en/latest/.
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Reset parameters the interaction function may have.
Methods Documentation