tf.contrib.seq2seq.dynamic_rnn_decoder(cell, decoder_fn, inputs=None, sequence_length=None, parallel_iterations=None, swap_memory=False, time_major=False, scope=None, name=None)
Dynamic RNN decoder for a sequence-to-sequence model specified by RNNCell and decoder function.
dynamic_rnn_decoder is similar to the
as the decoder does not make any assumptions of sequence length and batch
size of the input.
dynamic_rnn_decoder has two modes: training or inference and expects
the user to create seperate functions for each.
Under both training and inference, both
decoder_fn are expected,
cell performs computation at every timestep using
decoder_fn allows modeling of early stopping, output, state, and next
input and context.
When training the user is expected to supply
inputs. At every time step a
slice of the supplied input is fed to the
decoder_fn, which modifies and
returns the input for the next time step.
sequence_length is needed at training time, i.e., when
inputs is not
None, for dynamic unrolling. At test time, when
inputs is None,
sequence_length is not needed.
inputs is expected to be
None and the input is inferred
solely from the
cell: An instance of RNNCell.
decoder_fn: A function that takes time, cell state, cell input, cell output and context state. It returns a early stopping vector, cell state, next input, cell output and context state. Examples of decoder_fn can be found in the decoder_fn.py folder.
inputs: The inputs for decoding (embedded format).
time_major == False(default), this must be a
[batch_size, max_time, ...].
time_major == True, this must be a
[max_time, batch_size, ...].
The input to
cellat each time step will be a
sequence_length: (optional) An int32/int64 vector sized
inputsis not None and
sequence_lengthis None it is inferred from the
inputsas the maximal possible sequence length.
parallel_iterations: (Default: 32). The number of iterations to run in parallel. Those operations which do not have any temporal dependency and can be run in parallel, will be. This parameter trades off time for space. Values >> 1 use more memory but take less time, while smaller values use less memory but computations take longer.
swap_memory: Transparently swap the tensors produced in forward inference but needed for back prop from GPU to CPU. This allows training RNNs which would typically not fit on a single GPU, with very minimal (or no) performance penalty.
time_major: The shape format of the
outputsTensors. If true, these
Tensorsmust be shaped
[max_time, batch_size, depth]. If false, these
Tensorsmust be shaped
[batch_size, max_time, depth]. Using
time_major = Trueis a bit more efficient because it avoids transposes at the beginning and end of the RNN calculation. However, most TensorFlow data is batch-major, so by default this function accepts input and emits output in batch-major form.
scope: VariableScope for the
raw_rnn; defaults to None.
name: NameScope for the decoder; defaults to "dynamic_rnn_decoder"
A tuple (outputs, final_state, final_context_state) where:
outputs: the RNN output 'Tensor'. If time_major == False (default), this will be a `Tensor` shaped: `[batch_size, max_time, cell.output_size]`. If time_major == True, this will be a `Tensor` shaped: `[max_time, batch_size, cell.output_size]`. final_state: The final state and will be shaped `[batch_size, cell.state_size]`. final_context_state: The context state returned by the final call to decoder_fn. This is useful if the context state maintains internal data which is required after the graph is run. For example, one way to diversify the inference output is to use a stochastic decoder_fn, in which case one would want to store the decoded outputs, not just the RNN outputs. This can be done by maintaining a TensorArray in context_state and storing the decoded output of each iteration therein.
ValueError: if inputs is not None and has less than three dimensions.