LineaREInteraction
- class LineaREInteraction(p, power_norm=False)[source]
Bases:
NormBasedInteraction
The LineaRE interaction described by [peng2020].
The interaction function is given as
\[\| \mathbf{w}_{r}^{h} \odot \mathbf{x}_{h} + \mathbf{b}_r - \mathbf{w}_{r}^{t} \odot \mathbf{x}_{t} \|\]where \(\mathbf{w}_{r}^{h}, \mathbf{b}_r, \mathbf{w}_{r}^{t} \in \mathbb{R}^d\) are relation-specific terms, and \(\mathbf{x}_{h}, \mathbf{x}_{t} \in \mathbb{R}\) the head and tail entity representation.
Note
the original paper only describes the interaction for \(L_1\) norm, but we extend it to the general \(L_p\) norm as well as its powered variant.
Note
this interaction is equivalent to
TripleREInteraction
without the u termInitialize the norm-based interaction function.
- Parameters:
p (
int
) – The norm used withtorch.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
func
(r_head, r_mid, r_tail, t[, p, power_norm])Evaluate the LineaRE interaction function.
Attributes Documentation
Methods Documentation
- func(r_head, r_mid, r_tail, t, p=2, power_norm=False)
Evaluate the LineaRE interaction function.
Note
the interaction is equivalent to TripleRE interaction without the u term.
- Parameters:
h (
FloatTensor
) – shape: (*batch_dims, rank, dim) The head representations.r_head (
FloatTensor
) – shape: (*batch_dims, rank, dim) The relation-specific head multiplicator representations.r_mid (
FloatTensor
) – shape: (*batch_dims, rank, dim) The relation representations.r_tail (
FloatTensor
) – shape: (*batch_dims, rank, dim) The relation-specific tail multiplicator representations.t (
FloatTensor
) – shape: (*batch_dims, rank, dim) The tail representations.p (
int
) – The p for the norm. cf.negative_norm_of_sum()
.power_norm (
bool
) – Whether to return the powered norm. cf.negative_norm_of_sum()
.
- Return type:
FloatTensor
- Returns:
shape: batch_dims The scores.