MuREInteraction
- class MuREInteraction(p, power_norm=False)[source]
Bases:
NormBasedInteraction
[Tuple
[FloatTensor
,FloatTensor
,FloatTensor
],Tuple
[FloatTensor
,FloatTensor
],Tuple
[FloatTensor
,FloatTensor
,FloatTensor
]]A stateful module for the MuRE interaction function from [balazevic2019b].
Initialize 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 entity representations
The symbolic shapes for relation representations
Methods Summary
func
(b_h, r_vec, r_mat, t, b_t[, p, power_norm])Evaluate the MuRE interaction function from [balazevic2019b].
Attributes Documentation
Methods Documentation
- func(b_h, r_vec, r_mat, t, b_t, p=2, power_norm=False)
Evaluate the MuRE interaction function from [balazevic2019b].
\[-\|Rh + r - t\| + b_h + b_t\]- Parameters:
h (
FloatTensor
) – shape: (*batch_dims, dim) The head representations.b_h (
FloatTensor
) – shape: batch_dims The head entity bias.r_vec (
FloatTensor
) – shape: (*batch_dims, dim) The relation vector.r_mat (
FloatTensor
) – shape: (*batch_dims, dim,) The diagonal relation matrix.t (
FloatTensor
) – shape: (*batch_dims, dim) The tail representations.b_t (
FloatTensor
) – shape: batch_dims The tail entity bias.p (
Union
[int
,float
,str
]) – The parameter p for selecting the norm, cf.torch.linalg.vector_norm()
.power_norm (
bool
) – Whether to return the powered norm instead.
- Return type:
FloatTensor
- Returns:
shape: batch_dims The scores.