opennmt.encoders.conv_encoder module

Define convolution-based encoders.

class opennmt.encoders.conv_encoder.ConvEncoder(num_layers, num_units, kernel_size=3, dropout=0.3, position_encoder=)[source]

Bases: opennmt.encoders.encoder.Encoder

An encoder that applies a convolution over the input sequence as described in

__init__(num_layers, num_units, kernel_size=3, dropout=0.3, position_encoder=)[source]

Initializes the parameters of the encoder.

  • num_layers – The number of convolutional layers.
  • num_units – The number of output filters.
  • kernel_size – The kernel size.
  • dropout – The probability to drop units from the inputs.
  • position_encoder – The opennmt.layers.position.PositionEncoder to apply on inputs or None.
encode(inputs, sequence_length=None, mode='train')[source]

Encodes an input sequence.

  • inputs – The inputs to encode of shape \([B, T, ...]\).
  • sequence_length – The length of each input with shape \([B]\).
  • mode – A tf.estimator.ModeKeys mode.

A tuple (outputs, state, sequence_length).