KG2EInteraction

class KG2EInteraction(similarity=None, exact=True)[source]

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

A stateful module for the KG2E interaction function.

Initialize the interaction module.

Parameters:
  • similarity (Optional[str]) – the distribution similarity to use. Defaults to KL divergence.

  • exact (bool) – whether to compute the exact similarity, or leave out constant terms

Attributes Summary

entity_shape

The symbolic shapes for entity representations

relation_shape

The symbolic shapes for relation representations

Methods Summary

func(h_var, r_mean, r_var, t_mean, t_var[, ...])

Evaluate the KG2E interaction function.

Attributes Documentation

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

The symbolic shapes for entity representations

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

The symbolic shapes for relation representations

Methods Documentation

func(h_var, r_mean, r_var, t_mean, t_var, similarity='KL', exact=True)

Evaluate the KG2E interaction function.

Parameters:
  • h_mean (FloatTensor) – shape: (*batch_dims, d) The head entity distribution mean.

  • h_var (FloatTensor) – shape: (*batch_dims, d) The head entity distribution variance.

  • r_mean (FloatTensor) – shape: (*batch_dims, d) The relation distribution mean.

  • r_var (FloatTensor) – shape: (*batch_dims, d) The relation distribution variance.

  • t_mean (FloatTensor) – shape: (*batch_dims, d) The tail entity distribution mean.

  • t_var (FloatTensor) – shape: (*batch_dims, d) The tail entity distribution variance.

  • similarity (str) – The similarity measures for gaussian distributions. From {“KL”, “EL”}.

  • exact (bool) – Whether to leave out constants to accelerate similarity computation.

Return type:

FloatTensor

Returns:

shape: batch_dims The scores.