TripleREInteraction
- class TripleREInteraction(u: float | None = 1.0, p: int = 1, power_norm: bool = False)[source]
Bases:
NormBasedInteraction
[Tensor
,tuple
[Tensor
,Tensor
,Tensor
],Tensor
]The TripleRE interaction function from [yu2021].
It is given by
\[\mathbf{h} \odot (\mathbf{r}_h + u) - \mathbf{t} \odot (\mathbf{r}_t + u) + \mathbf{r}\]with head entity, relation and tail entity representations \(\mathbf{h}, \mathbf{r}, \mathbf{t} \in \mathbb{R}^d\), relation specific head and tail multipliers \(\mathbf{r}_h, \mathbf{r}_t \in \mathbb{R}^d\), and a scalar relation factor offset \(u \in \mathbb{R}\).
Note
This interaction is equivalent to
LineaREInteraction
except the \(u\) term. The \(u\) is only non-zero for the version 2 from the paper.Note
For equivalence to the paper version, h and t should be normalized to unit Euclidean length, and p and power_norm be kept at their default values.
Initialize the module.
See also
The parameter
p
andpower_norm
are directly passed toNormBasedInteraction
.- Parameters:
u (float | None) – The relation factor offset. Can be set to None (or 0) to disable it.
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
The symbolic shapes for relation representations
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Attributes Documentation
Methods Documentation