CPInteraction

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

Bases: FunctionalInteraction[FloatTensor, FloatTensor, FloatTensor]

An implementation of the CP interaction as described [lacroix2018] (originally from [hitchcock1927]).

Note

For \(k=1\), this interaction is the same as DistMult (but consider the note below).

Note

For equivalence to CP, entities should have different representations for head & tail role. This is different to DistMult.

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

func(r, t)

Evaluate the Canonical Tensor Decomposition interaction function.

Attributes Documentation

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

The symbolic shapes for entity representations

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

The symbolic shapes for relation representations

Methods Documentation

func(r, t)

Evaluate the Canonical Tensor Decomposition interaction function.

Parameters:
  • h (FloatTensor) – shape: (*batch_dims, rank, dim) The head representations.

  • r (FloatTensor) – shape: (*batch_dims, rank, dim) The relation representations.

  • t (FloatTensor) – shape: (*batch_dims, rank, dim) The tail representations.

Return type:

FloatTensor

Returns:

shape: batch_dims The scores.