class_docstr: BeamSearchDecoderMixin contains the common methods for
  BeamSearchDecoder.
  
  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.
docstr: Finalize and return the predicted_ids.
  
  Args:
    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`.
  
  Returns:
    outputs: An instance of `FinalBeamSearchDecoderOutput` where the
      predicted_ids are the result of calling _gather_tree.
    final_state: The same input instance of `BeamSearchDecoderState`.
docstr_tok: ["Finalize","and","return","the","predicted_ids",".","Args",":","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","`",".","Returns",":","outputs",":","An","instance","of","`","FinalBeamSearchDecoderOutput","`","where","the","predicted_ids","are","the","result","of","calling","_gather_tree",".","final_state",":","The","same","input","instance","of","`","BeamSearchDecoderState","`","."]
code: def finalize(self, outputs, final_state, sequence_lengths):
      """Finalize and return the predicted_ids.
  
      Args:
        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`.
  
      Returns:
        outputs: An instance of `FinalBeamSearchDecoderOutput` where the
          predicted_ids are the result of calling _gather_tree.
        final_state: The same input instance of `BeamSearchDecoderState`.
      """
      del sequence_lengths
      # Get max_sequence_length across all beams for each batch.
      max_sequence_lengths = tf.cast(
          tf.reduce_max(final_state.lengths, axis=1), tf.int32
      )
      predicted_ids = gather_tree(
          outputs.predicted_ids,
          outputs.parent_ids,
          max_sequence_lengths=max_sequence_lengths,
          end_token=self._end_token,
      )
      if self._reorder_tensor_arrays:
          final_state = final_state._replace(
              cell_state=tf.nest.map_structure(
                  lambda t: self._maybe_sort_array_beams(
                      t, outputs.parent_ids, final_state.lengths
                  ),
                  final_state.cell_state,
              )
          )
      outputs = FinalBeamSearchDecoderOutput(
          beam_search_decoder_output=outputs,
          predicted_ids=predicted_ids,
      )
      return outputs, final_state
  
imports: import collections
  import numpy
  import tensorflow
  from tensorflow_addons import options
  from tensorflow_addons.seq2seq import attention_wrapper
  from tensorflow_addons.seq2seq import decoder
  from tensorflow_addons.utils import keras_utils
  from tensorflow_addons.utils.resource_loader import LazySO
  from tensorflow_addons.utils.types import FloatTensorLike, TensorLike, Number
  from typeguard import typechecked
  from typing import Callable, Optional
label_desc: Use image node_id 6 for calling the BeamSearchDecoderMixin obj's underlying member method code with example usage: obj.finalize(outputs, final_state, sequence_lengths) and returns: outputs,  final_state