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 with y 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 and y where each element from x is reduced with the correspond element from y.

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 reduced tf.Tensor only.

abstract reduce(inputs)[source]

See opennmt.layers.Reducer.call().

abstract reduce_sequence(inputs, sequence_lengths)[source]

See opennmt.layers.Reducer.call().