TransEInteraction
- class TransEInteraction(p: int, power_norm: bool = False)[source]
Bases:
NormBasedInteraction
[Tensor
,Tensor
,Tensor
]The state-less norm-based TransE interaction function.
TransE models relations as a translation from head to tail entities in \(\textbf{e}\):
\[\textbf{e}_h + \textbf{e}_r \approx \textbf{e}_t\]This equation is rearranged and the \(l_p\) norm is applied to create the TransE interaction function.
\[f(h, r, t) = - \|\textbf{e}_h + \textbf{e}_r - \textbf{e}_t\|_{p}\]While this formulation is computationally efficient, it inherently cannot model one-to-many, many-to-one, and many-to-many relationships. For triples \((h,r,t_1), (h,r,t_2) \in \mathcal{K}\) where \(t_1 \neq t_2\), the model adapts the embeddings in order to ensure \(\textbf{e}_h + \textbf{e}_r \approx \textbf{e}_{t_1}\) and \(\textbf{e}_h + \textbf{e}_r \approx \textbf{e}_{t_2}\) which results in \(\textbf{e}_{t_1} \approx \textbf{e}_{t_2}\).
Initialize the norm-based interaction function.
- Parameters:
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.
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Methods Documentation