Reducer
- class opennmt.layers.Reducer(*args, **kwargs)[source]
Base class for reducers.
Inherits from:
keras.src.engine.base_layer.Layer
Extended by:
- zip_and_reduce(x, y)[source]
Zips the
x
withy
structures together and reduces all elements. If the structures are nested, they will be flattened first.- Parameters
x – The first structure.
y – The second structure.
- Returns
The same structure as
x
andy
where each element fromx
is reduced with the correspond element fromy
.- Raises
ValueError – if the two structures are not the same.
- call(inputs, sequence_length=None)[source]
Reduces all input elements.
- Parameters
inputs – A list of
tf.Tensor
.sequence_length – The length of each input, if reducing sequences.
- Returns
If
sequence_length
is set, a tuple(reduced_input, reduced_length)
, otherwise a reducedtf.Tensor
only.