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.

cell A layer that implements the tf.keras.layers.AbstractRNNCell interface.
beam_width Python integer, the number of beams.
output_layer (Optional) An instance of tf.keras.layers.Layer, i.e., 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.
reorder_tensor_arrays If True, TensorArrays' elements within the cell state will be reordered according to the beam search path. If the TensorArray can be reordered, the stacked form will be returned. Otherwise, the TensorArray will be returned as is. Set this flag to False if the cell state contains TensorArrays that are not amenable to reordering.
**kwargs Dict, other keyword arguments for parent class.



tracks_own_finished The BeamSearchDecoder shuffles its beams and their finished state.

For this reason, it conflicts with the dynamic_decode function's tracking of finished states. Setting this property to true avoids early stopping of decoding due to mismanagement of the finished state in dynamic_decode.



View source

Finalize and return the predicted_ids.

outputs An instance of BeamSearchDecoderOutput.
final_state An instance of BeamSearchDecoderState. Passed through to the output.
sequence_lengths An int64 tensor shaped [batch_size, beam_width]. The sequence lengths determined for each beam during decode. NOTE These are ignored; the updated sequence lengths are stored in final_state.lengths.

outputs An instance of FinalBeamSearchDecoderOutput where the predicted_ids are the result of calling _gather_tree.
final_state The same input instance of BeamSearchDecoderState.


View source

Perform a decoding step.

time scalar int32 tensor.
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 dropout or recurrent_dropout is used.
name Name scope for any created operations.

(outputs, next_state, next_inputs, finished).