TransHInteraction
- class TransHInteraction(p: int, power_norm: bool = False)[source]
Bases:
NormBasedInteraction
[Tensor
,tuple
[Tensor
,Tensor
],Tensor
]The norm-based TransH interaction function.
This model extends
TransEInteraction
by applying the translation from head to tail entity in a relation-specific hyperplane in order to address its inability to model one-to-many, many-to-one, and many-to-many relations.In TransH, each relation is represented by a hyperplane, or more specifically a normal vector of this hyperplane \(\mathbf{r}_{w} \in \mathbb{R}^d\) and a vector \(\mathbf{r}_{d} \in \mathbb{R}^d\) that lies in the hyperplane. To obtain a plausibility score, the head representation \(\mathbf{h} \in \mathbb{R}^d\), and the tail embedding \(\mathbf{t} \in \mathbb{R}^d\) are first projected onto the relation-specific hyperplane:
\[ \begin{align}\begin{aligned}\mathbf{h}_{r} = \mathbf{h} - \mathbf{r}_{w}^T \mathbf{h} \mathbf{r}_w\\\mathbf{t}_{r} = \mathbf{t} - \mathbf{r}_{w}^T \mathbf{t} \mathbf{r}_w\end{aligned}\end{align} \]Then, the projected representations are used to compute the score as in
TransEInteraction
:\[-\|\textbf{h}_{r} + \textbf{r}_d - \textbf{t}_{r}\|_{p}^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.
Attributes Summary
The symbolic shapes for relation representations
Methods Summary
forward
(h, r, t)Evaluate the interaction function.
Attributes Documentation
Methods Documentation