onmt.Beam

Class for maintaining statistics of each step. A beam mainly consists of a list of tokens tokens and a state state. tokens[t] stores a flat tensor of size batchSize * beamSize representing the tokens at step t, while state can be either a tensor with first dimension size batchSize * beamSize, or an iterable object containing several such tensors.

[src]

onmt.Beam(token, state, batchSize)

Constructor. We allow users to either specify all initial hypotheses by passing in token and state with first dimension batchSize * beamSize such that there are beamSize initial hypotheses for every sequence in the batch and pass in the number of sequences batchSize, or only specify one hypothesis per sequence by passing token and state with first dimension batchSize, and then onmt.translate.BeamSearcher will pad with auxiliary hypotheses with scores -inf such that each sequence starts with beamSize hypotheses as in the former case.

Parameters:

  • token - tensor of size (batchSize, vocabSize) (if start with one initial hypothesis per sequence) or (batchSize * beamSize, vocabSize) (if start with beamSize initial hypotheses per sequence), or a list of such tensors.
  • state - an iterable object, where the contained tensors should have the same first dimension as token.
  • batchSize - optional, number of sentences. Only necessary if start with beamSize hypotheses per sequence. [token:size(1)]

[src]

onmt.Beam:getTokens()

Returns:

  • tokens - a list of tokens. Note that the start-of-sequence symbols are also included. tokens[t] stores the tokens at step t, which is a tensor of size batchSize * beamSize.

[src]

onmt.Beam:getState()

Returns:

  • state - an abstract iterable object as passed by constructor. Every tensor inside the state has first dimension batchSize * beamSize

[src]

onmt.Beam:getScores()

Returns:

  • scores - a flat tensor storing the total scores for each batch. It is of size batchSize * beamSize.

[src]

onmt.Beam:getBackPointer()

Returns:

  • backPointer - a flat tensor storing the backpointers for each batch. It is of size batchSize * beamSize

[src]

onmt.Beam:getRemaining()

Returns the number of unfinished sequences. The finished sequences will be removed from batch.

Returns:

  • remaining - the number of unfinished sequences.

[src]

onmt.Beam:remaining2Orig(remainingId)

Since finished sequences are being removed from the batch, this function provides a way to convert the remaining batch id to the original batch id.

[src]

onmt.Beam:orig2Remaining(origId)

Since finished sequences are being removed from the batch, this function provides a way to convert the original batch id to the remaining batch id.

[src]

onmt.Beam:setState(state)

Set state.

[src]

onmt.Beam:setScores(scores)

Set scores.

[src]

onmt.Beam:setBackPointer(backPointer)

Set backPointer.