ParallelEncoder
- class opennmt.encoders.ParallelEncoder(*args, **kwargs)[source]
An encoder that encodes its input with several encoders and reduces the outputs and states together. Additional layers can be applied on each encoder output and on the combined output (e.g. to layer normalize each encoder output).
If the input is a single
tf.Tensor, the same input will be encoded by every encoders. Otherwise, when the input is a Python sequence (e.g. the non reduced output of aopennmt.inputters.ParallelInputter), each encoder will encode its corresponding input in the sequence.See for example “Multi-Columnn Encoder” in https://arxiv.org/abs/1804.09849.
Inherits from:
opennmt.encoders.Encoder- __init__(encoders, outputs_reducer=None, states_reducer=None, outputs_layer_fn=None, combined_output_layer_fn=None)[source]
Initializes the parameters of the encoder.
- Parameters
encoders – A list of
opennmt.encoders.Encoderor a single one, in which case the same encoder is applied to each input.outputs_reducer – A
opennmt.layers.Reducerto merge all outputs. IfNone, defaults toopennmt.layers.JoinReducer.states_reducer – A
opennmt.layers.Reducerto merge all states. IfNone, defaults toopennmt.layers.JoinReducer.outputs_layer_fn – A callable or list of callables applied to the encoders outputs If it is a single callable, it is applied on each encoder output. Otherwise, the
ith callable is applied on encoderioutput.combined_output_layer_fn – A callable to apply on the combined output (i.e. the output of
outputs_reducer).
- Raises
ValueError – if
outputs_layer_fnis a list with a size not equal to the number of encoders.