CrossEInteraction
- class CrossEInteraction(embedding_dim: int = 50, combination_activation: str | ~torch.nn.modules.module.Module | type[~torch.nn.modules.module.Module] | None = <class 'torch.nn.modules.activation.Tanh'>, combination_activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, combination_dropout: float | None = 0.5)[source]
Bases:
Interaction
[Tensor
,tuple
[Tensor
,Tensor
],Tensor
]The stateful interaction function of CrossE.
The interaction function is given by
\[\textit{drop}( \textit{act}( \mathbf{c}_r \odot \mathbf{h} + \mathbf{c}_r \odot \mathbf{h} \odot \mathbf{r} + \mathbf{b}) ) )^T \mathbf{t}\]where \(\mathbf{h}, \mathbf{c}_r, \mathbf{r}, \mathbf{t} \in \mathbb{R}^d\) is the head embedding, the relation interaction vector, the relation embedding, and the tail embedding, respectively. \(\mathbf{b} \in \mathbb{R}^d\) is a global bias vector (which makes this interaction function stateful). \(\textit{drop}\) denotes dropout, and \(\textit{act}\) is the activation function.
Note
The CrossE paper describes an additional sigmoid activation as part of the interaction function. Since using a log-likelihood loss can cause numerical problems (due to explicitly calling sigmoid before log), we do not use it in our implementation, but opt for the numerically stable variant. However, the model itself has an option
predict_with_sigmoid
, which can be used to force the use of sigmoid during inference. This can also affect rank-based scoring, since limited numerical precision can lead to exactly equal scores for multiple choices. The definition of a rank is not clear in this case, and there are several competing ways to break ties. See Understanding the Evaluation for more information.Instantiate the interaction module.
- Parameters:
embedding_dim (int) – The embedding dimension.
combination_activation (HintOrType[nn.Module]) – The combination activation function.
combination_activation_kwargs (Mapping[str, Any] | None) – Additional keyword-based arguments passed to the constructor of the combination activation function (if not already instantiated).
combination_dropout (float | None) – An optional dropout applied after the combination and before the dot product similarity.
Note
The parameter pair
(combination_activation, combination_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/.
Attributes Summary
The symbolic shapes for relation representations
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Attributes Documentation
Methods Documentation