class_docstr: [`BeamScorer`] implementing constrained beam search decoding.
  
  
  Args:
      batch_size (`int`):
          Batch Size of `input_ids` for which standard beam search decoding is run in parallel.
      num_beams (`int`):
          Number of beams for beam search.
      constraints (`List[Constraint]`):
          A list of positive constraints represented as `Constraint` objects that must be fulfilled in the generation
          output. For more information, the documentation of [`Constraint`] should be read.
      device (`torch.device`):
          Defines the device type (*e.g.*, `"cpu"` or `"cuda"`) on which this instance of `BeamSearchScorer` will be
          allocated.
      length_penalty (`float`, *optional*, defaults to 1.0):
          Exponential penalty to the length that is used with beam-based generation. It is applied as an exponent to
          the sequence length, which in turn is used to divide the score of the sequence. Since the score is the log
          likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences, while
          `length_penalty` < 0.0 encourages shorter sequences.
      do_early_stopping (`bool` or `str`, *optional*, defaults to `False`):
          Controls the stopping condition for beam-based methods, like beam-search. It accepts the following values:
          `True`, where the generation stops as soon as there are `num_beams` complete candidates; `False`, where an
          heuristic is applied and the generation stops when is it very unlikely to find better candidates;
          `"never"`, where the beam search procedure only stops when there cannot be better candidates (canonical
          beam search algorithm).
      num_beam_hyps_to_keep (`int`, *optional*, defaults to 1):
          The number of beam hypotheses that shall be returned upon calling
          [`~transformers.BeamSearchScorer.finalize`].
      num_beam_groups (`int`, *optional*, defaults to 1):
          Number of groups to divide `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.
      max_length (`int`, *optional*):
          The maximum length of the sequence to be generated.
class_docstr_tok: ["[","`","BeamScorer","`","]","implementing","constrained","beam","search","decoding",".","Args",":","batch_size","(","`","int","`",")",":","Batch","Size","of","`","input_ids","`","for","which","standard","beam","search","decoding","is","run","in","parallel",".","num_beams","(","`","int","`",")",":","Number","of","beams","for","beam","search",".","constraints","(","`","List","[","Constraint","]","`",")",":","A","list","of","positive","constraints","represented","as","`","Constraint","`","objects","that","must","be","fulfilled","in","the","generation","output",".","For","more","information",",","the","documentation","of","[","`","Constraint","`","]","should","be","read",".","device","(","`","torch.device","`",")",":","Defines","the","device","type","(","*","e.g",".","*",",","`","``","cpu","''","`","or","`","``","cuda","''","`",")","on","which","this","instance","of","`","BeamSearchScorer","`","will","be","allocated",".","length_penalty","(","`","float","`",",","*","optional","*",",","defaults","to","1.0",")",":","Exponential","penalty","to","the","length","that","is","used","with","beam-based","generation",".","It","is","applied","as","an","exponent","to","the","sequence","length",",","which","in","turn","is","used","to","divide","the","score","of","the","sequence",".","Since","the","score","is","the","log","likelihood","of","the","sequence","(","i.e",".","negative",")",",","`","length_penalty","`",">","0.0","promotes","longer","sequences",",","while","`","length_penalty","`","<","0.0","encourages","shorter","sequences",".","do_early_stopping","(","`","bool","`","or","`","str","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Controls","the","stopping","condition","for","beam-based","methods",",","like","beam-search",".","It","accepts","the","following","values",":","`","True","`",",","where","the","generation","stops","as","soon","as","there","are","`","num_beams","`","complete","candidates",";","`","False","`",",","where","an","heuristic","is","applied","and","the","generation","stops","when","is","it","very","unlikely","to","find","better","candidates",";","`","``","never","''","`",",","where","the","beam","search","procedure","only","stops","when","there","can","not","be","better","candidates","(","canonical","beam","search","algorithm",")",".","num_beam_hyps_to_keep","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","number","of","beam","hypotheses","that","shall","be","returned","upon","calling","[","`","~transformers.BeamSearchScorer.finalize","`","]",".","num_beam_groups","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","Number","of","groups","to","divide","`","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",".","max_length","(","`","int","`",",","*","optional","*",")",":","The","maximum","length","of","the","sequence","to","be","generated","."]
code: def make_constraint_states(self, n):
      return [
          ConstraintListState(
              [constraint.copy() for constraint in self.constraints]
          )
          for _ in range(n)
      ]
  
imports: from abc import ABC, abstractmethod
  from collections import UserDict
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from ..utils import add_start_docstrings
  from .beam_constraints import Constraint, ConstraintListState
label_desc: Use image node_id 3 for calling the ConstrainedBeamSearchScorer obj's underlying member method code with example usage: obj.make_constraint_states(n) and returns: unknown