TrainingDecoder

class paddle.fluid.contrib.decoder.beam_search_decoder. TrainingDecoder ( state_cell, name=None ) [source]

A decoder that can only be used for training. The decoder could be initialized with a StateCell object. The computation within the RNN cell could be defined with decoder’s block.

Parameters
  • state_cell (StateCell) – A StateCell object that handles the input and state variables.

  • name (str) – The name of this decoder. Default None.

Returns

The initialized TrainingDecoder object.

Return type

TrainingDecoder

Examples

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/decoder/beam_search_decoder.py:docstring of paddle.fluid.contrib.decoder.beam_search_decoder.TrainingDecoder, line 16)

Error in “code-block” directive: maximum 1 argument(s) allowed, 18 supplied.

.. code-block:: python
  decoder = TrainingDecoder(state_cell)
  with decoder.block():
      current_word = decoder.step_input(trg_embedding)
      decoder.state_cell.compute_state(inputs={'x': current_word})
      current_score = layers.fc(input=decoder.state_cell.get_state('h'),
                                size=32,
                                act='softmax')
      decoder.state_cell.update_states()
      decoder.output(current_score)

block ( )

block

Define the behavior of the decoder for each RNN time step.

step_input ( x )

step_input

Set the input variable as a step input to the RNN cell. For example, in machine translation, each time step we read one word from the target sentences, then the target sentence is a step input to the RNN cell.

Parameters

x (Variable) – the variable to be used as step input.

Returns

The variable as input of current step.

Return type

Variable

Examples: .. code-block:: python

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/decoder/beam_search_decoder.py:docstring of paddle.fluid.contrib.decoder.beam_search_decoder.TrainingDecoder.step_input, line 13)

Unexpected indentation.

current_word = decoder.step_input(trg_embedding)

static_input ( x )

static_input

Set the input variable as a static input of RNN cell. In contrast to step input, this variable will be used as a whole within the RNN decode loop and will not be scattered into time steps.

Parameters

x (Variable) – the variable to be used as static input.

Returns

The variable as input of current step.

Return type

Variable

Examples: .. code-block:: python

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/decoder/beam_search_decoder.py:docstring of paddle.fluid.contrib.decoder.beam_search_decoder.TrainingDecoder.static_input, line 13)

Unexpected indentation.

encoder_vec = decoder.static_input(encoded_vector)

output ( *outputs )

output

Set the output variable of the RNN cell.

Parameters

*outputs (Variables) – a series of variables that treated as output of the RNN cell.

Examples: .. code-block:: python

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/decoder/beam_search_decoder.py:docstring of paddle.fluid.contrib.decoder.beam_search_decoder.TrainingDecoder.output, line 9)

Unexpected indentation.

out = fluid.layers.fc(input=h,

size=32, bias_attr=True, act=’softmax’)

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/decoder/beam_search_decoder.py:docstring of paddle.fluid.contrib.decoder.beam_search_decoder.TrainingDecoder.output, line 13)

Definition list ends without a blank line; unexpected unindent.

decoder.output(out)