ConvEncoder

class opennmt.encoders.ConvEncoder(*args, **kwargs)[source]

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

Inherits from: opennmt.encoders.Encoder

__init__(num_layers_a, num_layers_c, num_units, kernel_size=3, dropout=0.3, position_encoder_class=<class 'opennmt.layers.position.PositionEmbedder'>)[source]

Initializes the parameters of the encoder.

Parameters
  • num_layers_a – The number of layers in CNN-a.

  • num_layers_c – The number of layers in CNN-c.

  • num_units – The number of output filters.

  • kernel_size – The kernel size.

  • dropout – The probability to drop units from the inputs.

  • position_encoder_class – The opennmt.layers.PositionEncoder class to use for position encoding (or a callable that returns an instance).

call(inputs, sequence_length=None, training=None)[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]\).

  • training – Run in training mode.

Returns

A tuple (outputs, state, sequence_length).