TripleREInteraction
- class TripleREInteraction(u=1.0, p=1, power_norm=False)[source]
Bases:
pykeen.nn.modules.NormBasedInteraction
[torch.FloatTensor
,Tuple
[torch.FloatTensor
,torch.FloatTensor
,torch.FloatTensor
],torch.FloatTensor
]A stateful module for the TripleRE interaction function.
Initialize the module.
- Parameters
u (
Optional
[float
]) – the relation factor offset. can be set to None to disable it.kwargs – additional keyword-based arguments passed to
NormBasedInteraction
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.
\[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.
- Parameters
h (
FloatTensor
) – shape: (batch_size, num_heads, 1, 1, rank, dim) The head representations.r_head (
FloatTensor
) – shape: (batch_size, 1, num_relations, 1, rank, dim) The relation-specific head multiplicator representations.r_mid (
FloatTensor
) – shape: (batch_size, 1, num_relations, 1, rank, dim) The relation representations.r_tail (
FloatTensor
) – shape: (batch_size, 1, num_relations, 1, rank, dim) The relation-specific tail multiplicator representations.t (
FloatTensor
) – shape: (batch_size, 1, 1, num_tails, 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_size, num_heads, num_relations, num_tails) The scores.