class_docstr: Select next tokens randomly from the top k possible next tokens.
  
  The ``scores`` attribute's lists are the score, after applying temperature,
  of the final prediction (either EOS or the final token in the event
  that ``max_length`` is reached)
  
  Args:
      pad (int): See base.
      bos (int): See base.
      eos (int): See base.
      unk (int): See base.
      start (int): See base.
      n_best (int): Don't stop until at least this many beams have
          reached EOS.
      batch_size (int): See base.
      global_scorer (onmt.translate.GNMTGlobalScorer): Scorer instance.
      min_length (int): See base.
      max_length (int): See base.
      ban_unk_token (Boolean): See base.
      block_ngram_repeat (int): See base.
      exclusion_tokens (set[int]): See base.
      return_attention (bool): See base.
      max_length (int): See base.
      sampling_temp (float): See
          :func:`~onmt.translate.greedy_search.sample_with_temperature()`.
      keep_topk (int): See
          :func:`~onmt.translate.greedy_search.sample_with_temperature()`.
      keep_topp (float): See
          :func:`~onmt.translate.greedy_search.sample_with_temperature()`.
      beam_size (int): Number of beams to use.
class_docstr_tok: ["Select","next","tokens","randomly","from","the","top","k","possible","next","tokens",".","The","``","scores","``","attribute","'s","lists","are","the","score",",","after","applying","temperature",",","of","the","final","prediction","(","either","EOS","or","the","final","token","in","the","event","that","``","max_length","``","is","reached",")","Args",":","pad","(","int",")",":","See","base",".","bos","(","int",")",":","See","base",".","eos","(","int",")",":","See","base",".","unk","(","int",")",":","See","base",".","start","(","int",")",":","See","base",".","n_best","(","int",")",":","Do","n't","stop","until","at","least","this","many","beams","have","reached","EOS",".","batch_size","(","int",")",":","See","base",".","global_scorer","(","onmt.translate.GNMTGlobalScorer",")",":","Scorer","instance",".","min_length","(","int",")",":","See","base",".","max_length","(","int",")",":","See","base",".","ban_unk_token","(","Boolean",")",":","See","base",".","block_ngram_repeat","(","int",")",":","See","base",".","exclusion_tokens","(","set","[","int","]",")",":","See","base",".","return_attention","(","bool",")",":","See","base",".","max_length","(","int",")",":","See","base",".","sampling_temp","(","float",")",":","See",":","func",":","`","~onmt.translate.greedy_search.sample_with_temperature","(",")","`",".","keep_topk","(","int",")",":","See",":","func",":","`","~onmt.translate.greedy_search.sample_with_temperature","(",")","`",".","keep_topp","(","float",")",":","See",":","func",":","`","~onmt.translate.greedy_search.sample_with_temperature","(",")","`",".","beam_size","(","int",")",":","Number","of","beams","to","use","."]
docstr: Finalize scores and predictions.
docstr_tok: ["Finalize","scores","and","predictions","."]
code: def update_finished(self):
      """Finalize scores and predictions."""
      # shape: (sum(~ self.is_finished), 1)
      step = len(self)
      non_finished_batch = [
          b for b, fin in enumerate(self.is_finished_list) if not fin[0]
      ]
      length_penalty = self.global_scorer.length_penalty(
          step, alpha=self.global_scorer.alpha
      )
      for b in [
          i for i, fin in enumerate(self.is_finished_list) if fin[0]
      ]:
          b_orig = self.original_batch_idx[b]
          score = self.beams_scores[b, 0] / length_penalty
          pred = self.alive_seq[b, 1:]
          attention = (
              self.alive_attn[
                  b,
                  :,
                  : self.src_len[b],
              ]
              if self.alive_attn is not None
              else []
          )
          self.hypotheses[b_orig].append((score, pred, attention))
      self.done = len(non_finished_batch) == 0
      if self.done:
          for b in range(self.batch_size):
              best_hyp = sorted(
                  self.hypotheses[b], key=lambda x: x[0], reverse=True
              )[: self.n_best]
              for score, pred, attn in best_hyp:
                  self.scores[b].append(score)
                  self.predictions[b].append(pred)
                  self.attention[b].append(attn)
          return
      self.select_indices = torch.tensor(
          non_finished_batch, device=self.alive_seq.device
      )
      self.alive_seq = self.alive_seq[self.select_indices]
      self.beams_scores = self.beams_scores[self.select_indices]
      self.src_len = self.src_len[self.select_indices]
      if self.alive_attn is not None:
          self.alive_attn = self.alive_attn[self.select_indices]
      self.original_batch_idx = self.original_batch_idx[
          self.select_indices
      ]
      self.maybe_update_target_prefix(self.select_indices)
  
imports: import torch
  from torch.nn.functional import softmax
  from onmt.translate.decode_strategy import DecodeStrategy
label_desc: Use image node_id 8 for calling the GreedySearch obj's underlying member method code with example usage: obj.update_finished() without return types