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=<opennmt.layers.position.PositionEmbedder object>)[source]

Bases: opennmt.encoders.encoder.Encoder

An encoder that applies a convolution over the input sequence as described in https://arxiv.org/abs/1611.02344.

__init__(num_layers, num_units, kernel_size=3, dropout=0.3, position_encoder=<opennmt.layers.position.PositionEmbedder object>)[source]

Initializes the parameters of the encoder.

Parameters:
  • 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.

Parameters:
  • 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.
Returns:

A tuple (outputs, state, sequence_length).