ConvEInteraction

class ConvEInteraction(input_channels=None, output_channels=32, embedding_height=None, embedding_width=None, kernel_width=3, kernel_height=None, input_dropout=0.2, feature_map_dropout=0.2, output_dropout=0.3, embedding_dim=200, apply_batch_normalization=True)[source]

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

A stateful module for the ConvE interaction function.

Initialize the interaction module.

Parameters:
  • input_channels (Optional[int]) – the number of input channels for the convolution operation. Can be inferred from other parameters, cf. _calculate_missing_shape_information().

  • output_channels (int) – the number of input channels for the convolution operation

  • embedding_height (Optional[int]) – the height of the “image” after reshaping the concatenated head and relation embedding. Can be inferred from other parameters, cf. _calculate_missing_shape_information().

  • embedding_width (Optional[int]) – the width of the “image” after reshaping the concatenated head and relation embedding. Can be inferred from other parameters, cf. _calculate_missing_shape_information().

  • kernel_width (int) – the width of the convolution kernel

  • kernel_height (Optional[int]) – the height of the convolution kernel. Defaults to kernel_width

  • input_dropout (float) – the dropout applied before the convolution

  • feature_map_dropout (float) – the dropout applied after the convolution

  • output_dropout (float) – the dropout applied after the linear projection

  • embedding_dim (int) – the embedding dimension of entities and relations

  • apply_batch_normalization (bool) – whether to apply batch normalization

Attributes Summary

tail_entity_shape

Methods Summary

func(r, t, t_bias, input_channels, ...)

Evaluate the ConvE interaction function.

Attributes Documentation

tail_entity_shape = ('d', '')

Methods Documentation

func(r, t, t_bias, input_channels, embedding_height, embedding_width, hr2d, hr1d)

Evaluate the ConvE interaction function.

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

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

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

  • t_bias (FloatTensor) – shape: (*batch_dims) The tail entity bias.

  • input_channels (int) – The number of input channels.

  • embedding_height (int) – The height of the reshaped embedding.

  • embedding_width (int) – The width of the reshaped embedding.

  • hr2d (Module) – The first module, transforming the 2D stacked head-relation “image”.

  • hr1d (Module) – The second module, transforming the 1D flattened output of the 2D module.

Return type:

FloatTensor

Returns:

shape: batch_dims The scores.