Encoder

The Encoder is an instance of the pytorch nn.Module class. This part of the neural network takes the input sequences and produces the embedded outputs as well as the context_vector used by the DecoderAttention and DecoderEvent.

class context_builder.encoders.Encoder(*args: Any, **kwargs: Any)[source]
Encoder.__init__(embedding, hidden_size, num_layers=1, bidirectional=False, LSTM=False)[source]

Encoder part for encoding sequences.

Parameters:
  • embedding (nn.Embedding) – Embedding layer to use

  • hidden_size (int) – Size of hidden dimension

  • num_layers (int, default=1) – Number of recurrent layers to use

  • bidirectional (boolean, default=False) – If True, use bidirectional recurrent layer

  • LSTM (boolean, default=False) – If True, use LSTM instead of GRU

Forward

The forward() function takes the input sequences and produces the embedded outputs as well as the context_vector. This method is also called from the __call__ method, i.e. when the object is called directly.

Encoder.forward(input, hidden=None)[source]

Encode data

Parameters:
  • input (torch.Tensor) – Tensor to use as input

  • hidden (torch.Tensor) – Tensor to use as hidden input (for storing sequences)

Returns:

  • output (torch.Tensor) – Output tensor

  • hidden (torch.Tensor) – Hidden state to supply to next input