def _grow_finished(finished_seq, finished_scores, finished_flags, curr_seq,
                   curr_scores, curr_finished, batch_size, beam_size):
  """Given sequences and scores, will gather the top k=beam size sequences.

  Args:
    finished_seq: Current finished sequences.
      [batch_size, beam_size, decode_length + 1]
    finished_scores: scores for each of these sequences.
      [batch_size, beam_size]
    finished_flags: finished bools for each of these sequences.
      [batch_size, beam_size]
    curr_seq: current topk sequence that has been grown by one position.
      [batch_size, beam_size, decode_length + 1]
    curr_scores: scores for each of these sequences. [batch_size, beam_size]
    curr_finished: Finished flags for each of these sequences.
      [batch_size, beam_size]
    batch_size: Integer specifying batch size.
    beam_size: Integer specifying beam size.
  Returns:
    Tuple of
      (Topk sequences based on scores,
       log probs of these sequences,
       Finished flags of these sequences)
  """
  # Set the scores of the unfinished seq in curr_seq to large negative values.
  curr_scores = _apply_negative_infinity_mask(curr_scores,
                                              tf.logical_not(curr_finished))

  # concatenating the sequences and scores along beam axis
  curr_finished_seq = tf.concat([finished_seq, curr_seq], axis=1)
  curr_finished_scores = tf.concat([finished_scores, curr_scores], axis=1)
  curr_finished_flags = tf.concat([finished_flags, curr_finished], axis=1)
  return compute_topk_scores_and_seq(curr_finished_seq, curr_finished_scores,
                                     curr_finished_scores, curr_finished_flags,
                                     beam_size, batch_size)
Given sequences and scores, will gather the top k=beam size sequences.

  Args:
    finished_seq: Current finished sequences.
      [batch_size, beam_size, decode_length + 1]
    finished_scores: scores for each of these sequences.
      [batch_size, beam_size]
    finished_flags: finished bools for each of these sequences.
      [batch_size, beam_size]
    curr_seq: current topk sequence that has been grown by one position.
      [batch_size, beam_size, decode_length + 1]
    curr_scores: scores for each of these sequences. [batch_size, beam_size]
    curr_finished: Finished flags for each of these sequences.
      [batch_size, beam_size]
    batch_size: Integer specifying batch size.
    beam_size: Integer specifying beam size.
  Returns:
    Tuple of
      (Topk sequences based on scores,
       log probs of these sequences,
       Finished flags of these sequences)
  
language/xsp/model/beam_search.py