NTNInteraction

class NTNInteraction(activation=None, activation_kwargs=None)[source]

Bases: FunctionalInteraction[FloatTensor, Tuple[FloatTensor, FloatTensor, FloatTensor, FloatTensor, FloatTensor], FloatTensor]

A stateful module for the NTN interaction function.

Initialize NTN with the given non-linear activation function.

Parameters:
  • activation (Union[str, Module, Type[Module], None]) – A non-linear activation function. Defaults to the hyperbolic tangent torch.nn.Tanh if None, otherwise uses the pykeen.utils.activation_resolver for lookup.

  • activation_kwargs (Optional[Mapping[str, Any]]) – If the activation is passed as a class, these keyword arguments are used during its instantiation.

Attributes Summary

relation_shape

The symbolic shapes for relation representations

Methods Summary

func(t, w, vh, vt, b, u, activation)

Evaluate the NTN interaction function.

Attributes Documentation

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

The symbolic shapes for relation representations

Methods Documentation

func(t, w, vh, vt, b, u, activation)

Evaluate the NTN interaction function.

\[f(h,r,t) = u_r^T act(h W_r t + V_r h + V_r' t + b_r)\]
Parameters:
  • h (FloatTensor) – shape: (*batch_dims, dim) The head representations.

  • w (FloatTensor) – shape: (*batch_dims, k, dim, dim) The relation specific transformation matrix W_r.

  • vh (FloatTensor) – shape: (*batch_dims, k, dim) The head transformation matrix V_h.

  • vt (FloatTensor) – shape: (*batch_dims, k, dim) The tail transformation matrix V_h.

  • b (FloatTensor) – shape: (*batch_dims, k) The relation specific offset b_r.

  • u (FloatTensor) – shape: (*batch_dims, k) The relation specific final linear transformation b_r.

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

  • activation (Module) – The activation function.

Return type:

FloatTensor

Returns:

shape: batch_dims The scores.