PositionEmbedder

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

Encodes position with a lookup table.

Inherits from: opennmt.layers.PositionEncoder

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

Initializes the position encoder.

Parameters
  • maximum_position – The maximum position to embed. Positions greater than this value will be set to maximum_position.

  • reducer – A opennmt.layers.Reducer to merge inputs and position encodings. Defaults to opennmt.layers.SumReducer.

  • **kwargs – Additional layer keyword arguments.

build(input_shape)[source]

Creates the variables of the layer (for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call. It is invoked automatically before the first execution of call().

This is typically used to create the weights of Layer subclasses (at the discretion of the subclass implementer).

Parameters

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).