|View source on GitHub|
BeamSearchDecoderMixin contains the common methods for
It is expected to be used a base class for concrete BeamSearchDecoder. Since this is a mixin class, it is expected to be used together with other class as base.
__init__( cell, beam_width, output_layer=None, length_penalty_weight=0.0, coverage_penalty_weight=0.0, reorder_tensor_arrays=True, **kwargs )
Initialize the BeamSearchDecoderMixin.
beam_width: Python integer, the number of beams.
output_layer: (Optional) An instance of
tf.keras.layers.Dense. Optional layer to apply to the RNN output prior to storing the result or sampling.
length_penalty_weight: Float weight to penalize length. Disabled with 0.0.
coverage_penalty_weight: Float weight to penalize the coverage of source sentence. Disabled with 0.0.
TensorArrays' elements within the cell state will be reordered according to the beam search path. If the
TensorArraycan be reordered, the stacked form will be returned. Otherwise, the
TensorArraywill be returned as is. Set this flag to
Falseif the cell state contains
TensorArrays that are not amenable to reordering.
**kwargs: Dict, other keyword arguments for parent class.
cellis not an instance of
output_layeris not an instance of
The BeamSearchDecoder shuffles its beams and their finished state.
For this reason, it conflicts with the
tracking of finished states. Setting this property to true avoids
early stopping of decoding due to mismanagement of the finished state
finalize( outputs, final_state, sequence_lengths )
Finalize and return the predicted_ids.
outputs: An instance of BeamSearchDecoderOutput.
final_state: An instance of BeamSearchDecoderState. Passed through to the output.
[batch_size, beam_width]. The sequence lengths determined for each beam during decode. NOTE These are ignored; the updated sequence lengths are stored in
outputs: An instance of
FinalBeamSearchDecoderOutputwhere the predicted_ids are the result of calling _gather_tree.
final_state: The same input instance of
step( time, inputs, state, training=None, name=None )
Perform a decoding step.
inputs: A (structure of) input tensors.
state: A (structure of) state tensors and TensorArrays.
training: Python boolean. Indicates whether the layer should behave in training mode or in inference mode. Only relevant when
name: Name scope for any created operations.
(outputs, next_state, next_inputs, finished).