AttentionalRNNDecoder

class opennmt.decoders.AttentionalRNNDecoder(*args, **kwargs)[source]

A RNN decoder with attention.

Inherits from: opennmt.decoders.RNNDecoder

__init__(num_layers, num_units, bridge_class=None, attention_mechanism_class=None, cell_class=None, dropout=0.3, residual_connections=False, first_layer_attention=False, attention_layer_activation=<function tanh>, **kwargs)[source]

Initializes the decoder parameters.

Parameters
  • num_layers – The number of layers.

  • num_units – The number of units in each layer.

  • bridge – A opennmt.layers.Bridge to pass the encoder state to the decoder.

  • attention_mechanism_class – A class inheriting from tfa.seq2seq.AttentionMechanism. Defaults to tfa.seq2seq.LuongAttention.

  • cell_class – The inner cell class or a callable taking num_units as argument and returning a cell.

  • dropout – The probability to drop units in each layer output.

  • residual_connections – If True, each layer input will be added to its output.

  • first_layer_attention – If True, output attention after the first layer.

  • attention_layer_activation – The activation to produce the attentional hidden state. Defaults to tanh following Luong paper (equation (5) in https://arxiv.org/abs/1508.04025).

  • **kwargs – Additional layer arguments.

property support_alignment_history

Returns True if this decoder can return the attention as alignment history.

step(inputs, timestep, state=None, memory=None, memory_sequence_length=None, training=None)[source]

Runs one decoding step.

Parameters
  • inputs – The 2D decoder input.

  • timestep – The current decoding step.

  • state – The decoder state.

  • memory – Memory values to query.

  • memory_sequence_length – Memory values length.

  • training – Run in training mode.

Returns

A tuple with the decoder outputs, the decoder state, and the attention vector.

map_v1_weights(weights)[source]