PositionEncoder

class opennmt.layers.PositionEncoder(*args, **kwargs)[source]

Base class for position encoders.

Inherits from: keras.src.engine.base_layer.Layer

Extended by:

__init__(reducer=None, **kwargs)[source]

Initializes the position encoder.

Parameters
call(inputs, position=None)[source]

Add position encodings to inputs.

Parameters
  • inputs – The inputs to encode.

  • position – The single position to encode, to use when this layer is called step by step.

Returns

A tf.Tensor whose shape depends on the configured reducer.