class_docstr: Beam search which keeps completed hypotheses in the beam.
  
  This is an alternative beam search implementation which is more similar to
  some of the beam search implementations in the literature (cf. Nematus,
  Blocks, tensor2tensor, TF NMT tutorial...). This implementation keeps
  completed hypotheses as active hypotheses in the next time step. Thus, they
  will keep competing against longer hypotheses. Beam search terminates if all
  active hypotheses are completed (i.e. end with EOS).
  
  Experiments have shown that this implementation and the main implementation
  in `beam_search.py` produce almost the same translations. We're leaving this
  under research/ because experimentation did not show a noticeable difference
  in translation quality from the existing implementation.
class_docstr_tok: ["Beam","search","which","keeps","completed","hypotheses","in","the","beam",".","This","is","an","alternative","beam","search","implementation","which","is","more","similar","to","some","of","the","beam","search","implementations","in","the","literature","(","cf",".","Nematus",",","Blocks",",","tensor2tensor",",","TF","NMT","tutorial","...",")",".","This","implementation","keeps","completed","hypotheses","as","active","hypotheses","in","the","next","time","step",".","Thus",",","they","will","keep","competing","against","longer","hypotheses",".","Beam","search","terminates","if","all","active","hypotheses","are","completed","(","i.e",".","end","with","EOS",")",".","Experiments","have","shown","that","this","implementation","and","the","main","implementation","in","`","beam_search.py","`","produce","almost","the","same","translations",".","We","'re","leaving","this","under","research\/","because","experimentation","did","not","show","a","noticeable","difference","in","translation","quality","from","the","existing","implementation","."]
code: def build_hypos_fast(
      self, hypo_tokens, cand_scores_list, attn_list, cand_beams_list
  ):
      bsz, beam_size, maxlen = hypo_tokens.size()
      seqlens = maxlen - torch.sum(
          hypo_tokens <= self.eos, dim=2
      )  # eos and pad
      all_hypos = []
      dummy_alignment = torch.LongTensor([1, 2, 3])
      for batch_idx in range(bsz):
          hypos = []
          for i in range(beam_size):
              seqlen = seqlens[batch_idx, i]
              hypos.append(
                  {
                      "tokens": hypo_tokens[
                          batch_idx, i, 1 : seqlen + 2
                      ],
                      "score": cand_scores_list[-1][batch_idx, i],
                      "attention": None,
                      "alignment": dummy_alignment,
                      "positional_scores": None,
                  }
              )
          all_hypos.append(hypos)
      return all_hypos
  
file_path: translate/pytorch_translate/research/beam_search/competing_completed.py
imports: import math
  import torch
  from fairseq.models import FairseqIncrementalDecoder
  from pytorch_translate.beam_decode import SequenceGenerator
label_desc: Use image node_id 3 for calling the CompetingCompletedSequenceGenerator obj's underlying member method code with example usage: obj.build_hypos_fast(hypo_tokens, cand_scores_list, attn_list, cand_beams_list) and returns: all_hypos