opennmt.encoders.mean_encoder module

Define a minimal encoder.

class opennmt.encoders.mean_encoder.MeanEncoder(trainable=True, name=None, dtype=None, **kwargs)[source]

Bases: opennmt.encoders.encoder.Encoder

A simple encoder that takes the mean of its inputs.

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).