onmt.Decoder

Unit to decode a sequence of output tokens.

 .      .      .             .
 |      |      |             |
h_1 => h_2 => h_3 => ... => h_n
 |      |      |             |
 .      .      .             .
 |      |      |             |
h_1 => h_2 => h_3 => ... => h_n
 |      |      |             |
 |      |      |             |
x_1    x_2    x_3           x_n

Inherits from onmt.Sequencer.

[src]

onmt.Decoder(inputNetwork, rnn, generator, inputFeed)

Construct a decoder layer.

Parameters:

  • inputNetwork - input nn module.
  • rnn - recurrent module, such as onmt.LSTM.
  • generator - optional, an output onmt.Generator.
  • inputFeed - bool, enable input feeding.

[src]

onmt.Decoder.load(pretrained)

Return a new Decoder using the serialized data pretrained.

[src]

onmt.Decoder:serialize()

Return data to serialize.

[src]

onmt.Decoder:maskPadding(sourceSizes, sourceLength, beamSize)

Mask padding means that the attention-layer is constrained to give zero-weight to padding. This is done by storing a reference to the softmax attention-layer.

Parameters:

[src]

onmt.Decoder:forwardOne(input, prevStates, context, prevOut, t)

Run one step of the decoder.

Parameters:

  • input - input to be passed to inputNetwork.
  • prevStates - stack of hidden states (batch x layers*model x rnnSize)
  • context - encoder output (batch x n x rnnSize)
  • prevOut - previous distribution (batch x #words)
  • t - current timestep

Returns:

  1. out - Top-layer hidden state.
  2. states - All states.

[src]

onmt.Decoder:forward(batch, encoderStates, context)

Compute all forward steps.

Parameters:

  • batch - a Batch object.
  • encoderStates - a batch of initial decoder states (optional) [0]
  • context - the context to apply attention to.

Returns: Table of top hidden state for each timestep.

[src]

onmt.Decoder:backward(batch, outputs, criterion)

Compute the backward update.

Parameters:

  • batch - a Batch object
  • outputs - expected outputs
  • criterion - a single target criterion object

Note: This code runs both the standard backward and criterion forward/backward. It returns both the gradInputs and the loss. --

[src]

onmt.Decoder:computeLoss(batch, encoderStates, context, criterion)

Compute the loss on a batch.

Parameters:

  • batch - a Batch to score.
  • encoderStates - initialization of decoder.
  • context - the attention context.
  • criterion - a pointwise criterion.

[src]

onmt.Decoder:computeScore(batch, encoderStates, context)

Compute the score of a batch.

Parameters:

  • batch - a Batch to score.
  • encoderStates - initialization of decoder.
  • context - the attention context.

Undocumented methods

* onmt.Decoder:resetPreallocation() * onmt.Decoder:forwardAndApply(batch, encoderStates, context, func)