TripleREInteraction
- class TripleREInteraction(u=1.0, p=1, power_norm=False)[source]
Bases:
NormBasedInteraction
[FloatTensor
,Tuple
[FloatTensor
,FloatTensor
,FloatTensor
],FloatTensor
]A stateful module for the TripleRE interaction function from [yu2021].
\[score(h, (r_h, r, r_t), t) = h * (r_h + u) - t * (r_t + u) + r\]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.
Note
this interaction is equivalent to
LineaREInteraction
except the u termInitialize the module.
- Parameters:
u (
Optional
[float
]) – the relation factor offset. can be set to None to disable it.p (
int
) – The norm used withtorch.linalg.vector_norm()
. Defaults to 1 for TripleRE.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. Defaults to False for TripleRE.
Attributes Summary
The symbolic shapes for relation representations
Methods Summary
func
(r_head, r_mid, r_tail, t[, u, p, ...])Evaluate the TripleRE interaction function.
Attributes Documentation
Methods Documentation
- func(r_head, r_mid, r_tail, t, u=None, p=2, power_norm=False)
Evaluate the TripleRE interaction function.
See also
pykeen.nn.modules.TripleREInteraction
for the stateful interaction module- 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.u (
Optional
[float
]) – the relation factor offset. If u is not None or 0, this corresponds to TripleREv2.p (
int
) – The p for the norm. cf.torch.linalg.vector_norm()
.power_norm (
bool
) – Whether to return the powered norm.
- Return type:
FloatTensor
- Returns:
shape: batch_dims The scores.