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

  Args:
    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_log_probs: log probs 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 finished seq in curr_seq to large negative
  # values
  curr_scores = _apply_negative_infinity_mask(curr_scores, curr_finished)
  return compute_topk_scores_and_seq(curr_seq, curr_scores, curr_log_probs,
                                     curr_finished, beam_size, batch_size)
Given sequences and scores, will gather the top k=beam size sequences.

  Args:
    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_log_probs: log probs 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