class_docstr: Generation beam search.
  
  Note that the attributes list is not exhaustive. Rather, it highlights
  tensors to document their shape. (Since the state variables' "batch"
  size decreases as beams finish, we denote this axis with a B rather than
  ``batch_size``).
  
  Args:
      beam_size (int): Number of beams to use (see base ``parallel_paths``).
      batch_size (int): See base.
      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.
      global_scorer (onmt.translate.GNMTGlobalScorer): Scorer instance.
      min_length (int): See base.
      max_length (int): See base.
      return_attention (bool): See base.
      block_ngram_repeat (int): See base.
      exclusion_tokens (set[int]): See base.
  
  Attributes:
      _batch_offset (LongTensor): Shape ``(B,)``.
      _beam_offset (LongTensor): Shape ``(batch_size x beam_size,)``.
      alive_seq (LongTensor): See base.
      topk_log_probs (FloatTensor): Shape ``(B, beam_size,)``. These
          are the scores used for the topk operation.
      src_len (LongTensor): Lengths of encodings. Used for
          masking attentions.
      select_indices (LongTensor or NoneType): Shape
          ``(B x beam_size,)``. This is just a flat view of the
          ``_batch_index``.
      topk_scores (FloatTensor): Shape
          ``(B, beam_size)``. These are the
          scores a sequence will receive if it finishes.
      topk_ids (LongTensor): Shape ``(B, beam_size)``. These are the
          word indices of the topk predictions.
      _batch_index (LongTensor): Shape ``(B, beam_size)``.
      _prev_penalty (FloatTensor or NoneType): Shape
          ``(B, beam_size)``. Initialized to ``None``.
      _coverage (FloatTensor or NoneType): Shape
          ``(1, B x beam_size, inp_seq_len)``.
      hypotheses (list[list[Tuple[Tensor]]]): Contains a tuple
          of score (float), sequence (long), and attention (float or None).
class_docstr_tok: ["Generation","beam","search",".","Note","that","the","attributes","list","is","not","exhaustive",".","Rather",",","it","highlights","tensors","to","document","their","shape",".","(","Since","the","state","variables","'","``","batch","''","size","decreases","as","beams","finish",",","we","denote","this","axis","with","a","B","rather","than","``","batch_size","``",")",".","Args",":","beam_size","(","int",")",":","Number","of","beams","to","use","(","see","base","``","parallel_paths","``",")",".","batch_size","(","int",")",":","See","base",".","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",".","global_scorer","(","onmt.translate.GNMTGlobalScorer",")",":","Scorer","instance",".","min_length","(","int",")",":","See","base",".","max_length","(","int",")",":","See","base",".","return_attention","(","bool",")",":","See","base",".","block_ngram_repeat","(","int",")",":","See","base",".","exclusion_tokens","(","set","[","int","]",")",":","See","base",".","Attributes",":","_batch_offset","(","LongTensor",")",":","Shape","``","(","B",",",")","``",".","_beam_offset","(","LongTensor",")",":","Shape","``","(","batch_size","x","beam_size",",",")","``",".","alive_seq","(","LongTensor",")",":","See","base",".","topk_log_probs","(","FloatTensor",")",":","Shape","``","(","B",",","beam_size",",",")","``",".","These","are","the","scores","used","for","the","topk","operation",".","src_len","(","LongTensor",")",":","Lengths","of","encodings",".","Used","for","masking","attentions",".","select_indices","(","LongTensor","or","NoneType",")",":","Shape","``","(","B","x","beam_size",",",")","``",".","This","is","just","a","flat","view","of","the","``","_batch_index","``",".","topk_scores","(","FloatTensor",")",":","Shape","``","(","B",",","beam_size",")","``",".","These","are","the","scores","a","sequence","will","receive","if","it","finishes",".","topk_ids","(","LongTensor",")",":","Shape","``","(","B",",","beam_size",")","``",".","These","are","the","word","indices","of","the","topk","predictions",".","_batch_index","(","LongTensor",")",":","Shape","``","(","B",",","beam_size",")","``",".","_prev_penalty","(","FloatTensor","or","NoneType",")",":","Shape","``","(","B",",","beam_size",")","``",".","Initialized","to","``","None","``",".","_coverage","(","FloatTensor","or","NoneType",")",":","Shape","``","(","1",",","B","x","beam_size",",","inp_seq_len",")","``",".","hypotheses","(","list","[","list","[","Tuple","[","Tensor","]","]","]",")",":","Contains","a","tuple","of","score","(","float",")",",","sequence","(","long",")",",","and","attention","(","float","or","None",")","."]
code: def beams_non_finished(
      self, i, topk_scores_list, predictions, attention, step
  ):
      # using lists instead of tensors for topk_scores and is_finished make things faster
      if any(self.is_finished_list[i]):
          b = self._batch_offset[i]
          # Store finished hypotheses for this example in the batch.
          for j in [
              k for k, fin in enumerate(self.is_finished_list[i]) if fin
          ]:  # Beam level: finished beam j in example i of batch
              if self.ratio > 0:
                  s = topk_scores_list[i][j] / (step + 1)
                  self.best_scores[b] = max(s, self.best_scores[b])
              self.hypotheses[b].append(
                  (
                      topk_scores_list[i][j],
                      predictions[i, j, 1:],  # Ignore start_token.
                      attention[i, j, :, : self.src_len[i]]
                      if attention is not None
                      else None,
                  )
              )
  
          # End condition is the top beam finished and we can return
          # n_best hypotheses.
          if self.ratio > 0:
              pred_len = self.src_len[i] * self.ratio
              finish_flag = (
                  (topk_scores_list[i][0] / pred_len)
                  <= self.best_scores[b]
              ) or all(self.is_finished_list[i])
          else:
              # early stop when top beam is finished
              finish_flag = self.is_finished_list[i][0]
  
          if finish_flag and len(self.hypotheses[b]) >= self.n_best:
              self.hypotheses[b] = sorted(
                  self.hypotheses[b], key=lambda x: x[0], reverse=True
              )
              for score, pred, attn in self.hypotheses[b][
                  : self.n_best
              ]:
                  self.scores[b].append(score)
                  self.predictions[b].append(
                      pred
                  )  # ``(batch, n_best,)``
                  self.attention[b].append(
                      attn if attn is not None else []
                  )
              return False
          else:
              return True
      else:
          return True
  
imports: import torch
  from onmt.translate import penalties
  from onmt.translate.decode_strategy import DecodeStrategy
  import warnings
label_desc: Use image node_id 8 for calling the BeamSearchBase obj's underlying member method code with example usage: obj.beams_non_finished(i, topk_scores_list, predictions, attention, step) and returns: True, False, True