docstr: Generates translations of a given source sentence.
  Args:
      models: List of FairseqEncoderDecoderModel objects. Each one must
          implement reorder_encoder_output() method to replicate encoder
          outputs.
      min/maxlen: The length of the generated output will be bounded by
          minlen and maxlen (not including the end-of-sentence marker).
      stop_early: Stop generation immediately after we finalize beam_size
          hypotheses, even though longer hypotheses might have better
          normalized scores.
      normalize_scores: Normalize scores by the length of the output.
      word_reward: add this value to score each token except EOS
          (an alternative method to len_penalty for encouraging longer
          output)
      model_weights: None or list of Python floats of the same length as
          `models` with ensemble interpolation weights.
      use_char_source: if True, encoder inputs consist of (src_tokens,
          src_lengths, char_inds, word_lengths)
      diverse_beam_groups: number of groups for Diverse Beam Search
          (-1 by default is vanilla beam search)
      diverse_beam_strength: strength of diversity penalty for Diverse
          Beam Search.
      diversity_sibling_gamma: The diversity rate of sibling rank (-0.0 by default
         to disable sibling rank penalty)
      sampling (bool, optional): sample outputs instead of beam search
          (default: False)
      sampling_topk (int, optional): only sample among the top-k choices
          at each step (default: -1)
      temperature (float, optional): temperature, where values
          >1.0 produce more uniform samples and values <1.0 produce
          sharper samples (default: 1.0)
docstr_tok: ["Generates","translations","of","a","given","source","sentence",".","Args",":","models",":","List","of","FairseqEncoderDecoderModel","objects",".","Each","one","must","implement","reorder_encoder_output","(",")","method","to","replicate","encoder","outputs",".","min\/maxlen",":","The","length","of","the","generated","output","will","be","bounded","by","minlen","and","maxlen","(","not","including","the","end-of-sentence","marker",")",".","stop_early",":","Stop","generation","immediately","after","we","finalize","beam_size","hypotheses",",","even","though","longer","hypotheses","might","have","better","normalized","scores",".","normalize_scores",":","Normalize","scores","by","the","length","of","the","output",".","word_reward",":","add","this","value","to","score","each","token","except","EOS","(","an","alternative","method","to","len_penalty","for","encouraging","longer","output",")","model_weights",":","None","or","list","of","Python","floats","of","the","same","length","as","`","models","`","with","ensemble","interpolation","weights",".","use_char_source",":","if","True",",","encoder","inputs","consist","of","(","src_tokens",",","src_lengths",",","char_inds",",","word_lengths",")","diverse_beam_groups",":","number","of","groups","for","Diverse","Beam","Search","(","-1","by","default","is","vanilla","beam","search",")","diverse_beam_strength",":","strength","of","diversity","penalty","for","Diverse","Beam","Search",".","diversity_sibling_gamma",":","The","diversity","rate","of","sibling","rank","(","-0.0","by","default","to","disable","sibling","rank","penalty",")","sampling","(","bool",",","optional",")",":","sample","outputs","instead","of","beam","search","(","default",":","False",")","sampling_topk","(","int",",","optional",")",":","only","sample","among","the","top-k","choices","at","each","step","(","default",":","-1",")","temperature","(","float",",","optional",")",":","temperature",",","where","values",">","1.0","produce","more","uniform","samples","and","values","<","1.0","produce","sharper","samples","(","default",":","1.0",")"]
code: def __init__(
      self,
      models,
      tgt_dict,
      beam_size=1,
      minlen=1,
      maxlen=None,
      stop_early=True,
      normalize_scores=True,
      len_penalty=0,
      unk_reward=0,
      lexicon_reward=0,
      retain_dropout=False,
      word_reward=0,
      model_weights=None,
      use_char_source=False,
      diverse_beam_groups=-1,
      diverse_beam_strength=0.5,
      diversity_sibling_gamma=0.0,
      sampling=False,
      sampling_topk=-1,
      temperature=1,
  ):
      """Generates translations of a given source sentence.
      Args:
          models: List of FairseqEncoderDecoderModel objects. Each one must
              implement reorder_encoder_output() method to replicate encoder
              outputs.
          min/maxlen: The length of the generated output will be bounded by
              minlen and maxlen (not including the end-of-sentence marker).
          stop_early: Stop generation immediately after we finalize beam_size
              hypotheses, even though longer hypotheses might have better
              normalized scores.
          normalize_scores: Normalize scores by the length of the output.
          word_reward: add this value to score each token except EOS
              (an alternative method to len_penalty for encouraging longer
              output)
          model_weights: None or list of Python floats of the same length as
              `models` with ensemble interpolation weights.
          use_char_source: if True, encoder inputs consist of (src_tokens,
              src_lengths, char_inds, word_lengths)
          diverse_beam_groups: number of groups for Diverse Beam Search
              (-1 by default is vanilla beam search)
          diverse_beam_strength: strength of diversity penalty for Diverse
              Beam Search.
          diversity_sibling_gamma: The diversity rate of sibling rank (-0.0 by default
             to disable sibling rank penalty)
          sampling (bool, optional): sample outputs instead of beam search
              (default: False)
          sampling_topk (int, optional): only sample among the top-k choices
              at each step (default: -1)
          temperature (float, optional): temperature, where values
              >1.0 produce more uniform samples and values <1.0 produce
              sharper samples (default: 1.0)
      """
      self.models = models
      self.pad = tgt_dict.pad()
      self.unk = tgt_dict.unk()
      self.eos = tgt_dict.eos()
      self.vocab_size = len(tgt_dict)
      self.beam_size = beam_size
      self.minlen = minlen
      max_decoder_len = min(
          m.max_decoder_positions() for m in self.models
      )
      self.maxlen = (
          max_decoder_len
          if maxlen is None
          else min(maxlen, max_decoder_len)
      )
      self.stop_early = stop_early
      self.normalize_scores = normalize_scores
      self.len_penalty = len_penalty
      self.unk_reward = unk_reward
      self.lexicon_reward = lexicon_reward
      self.lexicon_indices = tgt_dict.lexicon_indices_list()
      self.retain_dropout = retain_dropout
      self.temperature = temperature
      self.word_reward = word_reward
      if model_weights is not None:
          assert len(models) == len(model_weights)
          self.model_weights = model_weights
      else:
          self.model_weights = [1.0 / len(models)] * len(models)
      self.use_char_source = use_char_source
      assert (
          sampling_topk < 0 or sampling
      ), "--sampling-topk requires --sampling"
      assert temperature > 0, "--temperature must be greater than 0"
      if sampling:
          self.search = search.Sampling(tgt_dict, sampling_topk)
      elif diverse_beam_groups > 0:
          self.search = search.DiverseBeamSearch(
              tgt_dict, diverse_beam_groups, diverse_beam_strength
          )
      else:
          self.search = search.BeamSearch(tgt_dict)
      self.diversity_sibling_gamma = diversity_sibling_gamma
  
imports: import math
  from typing import List, Tuple
  import torch
  from fairseq import search, utils
  from fairseq.models import FairseqIncrementalDecoder
  from pytorch_translate import utils
  from torch import Tensor
label_desc: Use image node_id 1 to create a new SequenceGenerator object from inherited base classes: object with example: obj = SequenceGenerator(models, tgt_dict, beam_size, minlen, maxlen, stop_early, normalize_scores, len_penalty, unk_reward, lexicon_reward, retain_dropout, word_reward, model_weights, use_char_source, diverse_beam_groups, diverse_beam_strength, diversity_sibling_gamma, sampling, sampling_topk, temperature)