- class opennmt.encoders.SequentialEncoder(*args, **kwargs)
An encoder that executes multiple encoders sequentially with optional transition layers.
See for example “Cascaded Encoder” in https://arxiv.org/abs/1804.09849.
- __init__(encoders, states_reducer=<opennmt.layers.reducer.JoinReducer object>, transition_layer_fn=None)
Initializes the parameters of the encoder.
encoders – A list of
states_reducer – A
opennmt.layers.Reducerto 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
ith callable will be applied between encoders
i + 1.
ValueError – if
transition_layer_fnis a list with a size not equal to the number of encoder transitions
len(encoders) - 1.
- call(inputs, sequence_length=None, training=None)
Encodes an input sequence.
inputs – The inputs to encode of shape \([B, T, ...]\).
sequence_length – The length of each input with shape \([B]\).
training – Run in training mode.
(outputs, state, sequence_length).