class_docstr: :class:`transformers.BeamScorer` implementing standard beam search decoding.
  
  Adapted in part from `Facebook's XLM beam search code
  <https://github.com/facebookresearch/XLM/blob/9e6f6814d17be4fe5b15f2e6c43eb2b2d76daeb4/src/model/transformer.py#L529>`__.
  
  Reference for the diverse beam search algorithm and implementation `Ashwin Kalyan's DBS implementation
  <https://github.com/ashwinkalyan/dbs/blob/master/dbs/beam_utils.lua>`__
  
  Args:
      batch_size (:obj:`int`):
          Batch Size of :obj:`input_ids` for which standard beam search decoding is run in parallel.
      max_length (:obj:`int`):
          The maximum length of the sequence to be generated.
      num_beams (:obj:`int`):
          Number of beams for beam search.
      device (:obj:`torch.device`):
          Defines the device type (*e.g.*, :obj:`"cpu"` or :obj:`"cuda"`) on which this instance of
          :obj:`BeamSearchScorer` will be allocated.
      length_penalty (:obj:`float`, `optional`, defaults to 1.0):
          Exponential penalty to the length. 1.0 means no penalty. Set to values < 1.0 in order to encourage the
          model to generate shorter sequences, to a value > 1.0 in order to encourage the model to produce longer
          sequences.
      do_early_stopping (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether to stop the beam search when at least ``num_beams`` sentences are finished per batch or not.
      num_beam_hyps_to_keep (:obj:`int`, `optional`, defaults to 1):
          The number of beam hypotheses that shall be returned upon calling
          :meth:`~transformer.BeamSearchScorer.finalize`.
      num_beam_groups (:obj:`int`):
          Number of groups to divide :obj:`num_beams` into in order to ensure diversity among different groups of
          beams. See `this paper <https://arxiv.org/pdf/1610.02424.pdf>`__ for more details.
class_docstr_tok: [":","class",":","`","transformers.BeamScorer","`","implementing","standard","beam","search","decoding",".","Adapted","in","part","from","`","Facebook","'s","XLM","beam","search","code","<","https",":","\/\/github.com\/facebookresearch\/XLM\/blob\/9e6f6814d17be4fe5b15f2e6c43eb2b2d76daeb4\/src\/model\/transformer.py","#","L529",">","`","__",".","Reference","for","the","diverse","beam","search","algorithm","and","implementation","`","Ashwin","Kalyan","'s","DBS","implementation","<","https",":","\/\/github.com\/ashwinkalyan\/dbs\/blob\/master\/dbs\/beam_utils.lua",">","`","__","Args",":","batch_size","(",":","obj",":","`","int","`",")",":","Batch","Size","of",":","obj",":","`","input_ids","`","for","which","standard","beam","search","decoding","is","run","in","parallel",".","max_length","(",":","obj",":","`","int","`",")",":","The","maximum","length","of","the","sequence","to","be","generated",".","num_beams","(",":","obj",":","`","int","`",")",":","Number","of","beams","for","beam","search",".","device","(",":","obj",":","`","torch.device","`",")",":","Defines","the","device","type","(","*","e.g",".","*",",",":","obj",":","`","``","cpu","''","`","or",":","obj",":","`","``","cuda","''","`",")","on","which","this","instance","of",":","obj",":","`","BeamSearchScorer","`","will","be","allocated",".","length_penalty","(",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to","1.0",")",":","Exponential","penalty","to","the","length",".","1.0","means","no","penalty",".","Set","to","values","<","1.0","in","order","to","encourage","the","model","to","generate","shorter","sequences",",","to","a","value",">","1.0","in","order","to","encourage","the","model","to","produce","longer","sequences",".","do_early_stopping","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","Whether","to","stop","the","beam","search","when","at","least","``","num_beams","``","sentences","are","finished","per","batch","or","not",".","num_beam_hyps_to_keep","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to","1",")",":","The","number","of","beam","hypotheses","that","shall","be","returned","upon","calling",":","meth",":","`","~transformer.BeamSearchScorer.finalize","`",".","num_beam_groups","(",":","obj",":","`","int","`",")",":","Number","of","groups","to","divide",":","obj",":","`","num_beams","`","into","in","order","to","ensure","diversity","among","different","groups","of","beams",".","See","`","this","paper","<","https",":","\/\/arxiv.org\/pdf\/1610.02424.pdf",">","`","__","for","more","details","."]
code: def is_done(self) -> bool:
      return self._done.all()
  
imports: from abc import ABC, abstractmethod
  from collections import UserDict
  from typing import Optional, Tuple
  from .file_utils import add_start_docstrings
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP.core.log import logger
label_desc: Use image node_id 2 for calling the BeamSearchScorer obj's underlying member method code with example usage: obj.is_done() and returns: self