DecodeHelper

class paddle.fluid.layers.DecodeHelper[source]

DecodeHelper is the base class for any helper instance used in BasicDecoder. It provides interface to implement sampling and produce inputs for the next time step in dynamic decoding.

initialize()

DecodeHelper initialization to produce inputs for the first decoding step and give the initial status telling whether each sequence in the batch is finished. It is the partial of the initialization of BasicDecoder.

Returns

A tuple( (initial_inputs, initial_finished) ). initial_inputs is a (possibly nested structure of) tensor variable[s], and the tensor’s shape is [batch_size, …]. initial_finished is a bool tensor with shape [batch_size].

Return type

tuple

sample(time, outputs, states)

Perform sampling with some strategies according to outputs. It is the partial of BasicDecoder.step.

Parameters
  • time (Variable) – An int64 tensor with shape [1] provided by the caller, representing the current time step number of decoding.

  • outputs (Variable) – A tensor variable. Usually it’s data type is float32 or float64, and it’s shape is [batch_size, vocabulary_size], representing the predicted logits of current step. It is same as outputs returned by BasicDecoder.output_fn(BasicDecoder.cell.call()).

  • states (Variable) – A (possibly nested structure of) tensor variable[s]. It is same as new_states returned by BasicDecoder.cell.call().

Returns

An int64 tensor representing the sampled ids.

Return type

Variable

next_inputs(time, outputs, states, sample_ids)

Produce the inputs and states for next time step and give status telling whether each minibatch entry is finished. It is called after sample in BasicDecoder.step. It is the partial of BasicDecoder.step.

Parameters
  • time (Variable) – An int64 tensor with shape [1] provided by the caller, representing the current time step number of decoding.

  • outputs (Variable) – A tensor variable. Usually it’s data type is float32 or float64, and it’s shape is [batch_size, vocabulary_size], representing the predicted logits of current step. It is same as outputs returned by BasicDecoder.output_fn(BasicDecoder.cell.call()).

  • states (Variable) – A (possibly nested structure of) tensor variable[s]. It is same as new_states returned by BasicDecoder.cell.call().

  • sample_ids (Variable) – A (possibly nested structure of) tensor variable[s]. It is same as sample_ids returned by sample().

Returns

A tuple( (finished, next_inputs, next_states) ). next_inputs and next_states both are a (possibly nested structure of) tensor variable[s], and the structure, shape and data type of next_states must be same as the input argument states. finished is a bool tensor with shape [batch_size].

Return type

tuple