CPInteraction

class CPInteraction(*args, **kwargs)[source]

Bases: Interaction[Tensor, Tensor, Tensor]

The Canonical Tensor Decomposition interaction as described [lacroix2018] (originally from [hitchcock1927]).

The interaction function is given as

\[\sum_{1 \leq i \leq k, 1 \leq j \leq d} \mathbf{h}_{i, j} \cdot \mathbf{r}_{i, j} \cdot \mathbf{t}_{i, j}\]

Note

For \(k=1\), this interaction is the same as DistMultInteraction. However, in contrast to DistMult, entities should have different representations for the head and the tail role.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Attributes Summary

entity_shape

The symbolic shapes for entity representations

relation_shape

The symbolic shapes for relation representations

Methods Summary

forward(h, r, t)

Evaluate the interaction function.

Attributes Documentation

entity_shape: Sequence[str] = ('kd', 'kd')

The symbolic shapes for entity representations

relation_shape: Sequence[str] = ('kd',)

The symbolic shapes for relation representations

Methods Documentation

forward(h: Tensor, r: Tensor, t: Tensor) Tensor[source]

Evaluate the interaction function.

See also

Interaction.forward for a detailed description about the generic batched form of the interaction function.

Parameters:
  • h (Tensor) – shape: (*batch_dims, k, d) The head representations.

  • r (Tensor) – shape: (*batch_dims, k, d) The relation representations.

  • t (Tensor) – shape: (*batch_dims, k, d) The tail representations.

Returns:

shape: batch_dims The scores.

Return type:

Tensor