SequentialEncoder

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

An encoder that executes multiple encoders sequentially with optional transition layers.

See for example “Cascaded Encoder” in https://arxiv.org/abs/1804.09849.

Inherits from: opennmt.encoders.Encoder

Extended by:

__init__(encoders, states_reducer=<opennmt.layers.reducer.JoinReducer object>, transition_layer_fn=None)[source]

Initializes the parameters of the encoder.

Parameters
  • encoders – A list of opennmt.encoders.Encoder.

  • states_reducer – A opennmt.layers.Reducer to merge all states.

  • transition_layer_fn – A callable or list of callables applied to the output of an encoder before passing it as input to the next. If it is a single callable, it is applied between every encoders. Otherwise, the i th callable will be applied between encoders i and i + 1.

Raises

ValueError – if transition_layer_fn is a list with a size not equal to the number of encoder transitions len(encoders) - 1.

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