class_docstr: Translate a batch of sentences with a saved model.
  
  Args:
      model (onmt.modules.NMTModel): NMT model to use for translation
      vocabs (dict[str, Vocab]): A dict
          mapping each side's Vocab.
      gpu (int): GPU device. Set to negative for no GPU.
      n_best (int): How many beams to wait for.
      min_length (int): See
          :class:`onmt.translate.decode_strategy.DecodeStrategy`.
      max_length (int): See
          :class:`onmt.translate.decode_strategy.DecodeStrategy`.
      beam_size (int): Number of beams.
      random_sampling_topk (int): See
          :class:`onmt.translate.greedy_search.GreedySearch`.
      random_sampling_temp (float): See
          :class:`onmt.translate.greedy_search.GreedySearch`.
      stepwise_penalty (bool): Whether coverage penalty is applied every step
          or not.
      dump_beam (bool): Debugging option.
      block_ngram_repeat (int): See
          :class:`onmt.translate.decode_strategy.DecodeStrategy`.
      ignore_when_blocking (set or frozenset): See
          :class:`onmt.translate.decode_strategy.DecodeStrategy`.
      replace_unk (bool): Replace unknown token.
      tgt_file_prefix (bool): Force the predictions begin with provided -tgt.
      data_type (str): Source data type.
      verbose (bool): Print/log every translation.
      report_time (bool): Print/log total time/frequency.
      copy_attn (bool): Use copy attention.
      global_scorer (onmt.translate.GNMTGlobalScorer): Translation
          scoring/reranking object.
      out_file (TextIO or codecs.StreamReaderWriter): Output file.
      report_score (bool) : Whether to report scores
      logger (logging.Logger or NoneType): Logger.
class_docstr_tok: ["Translate","a","batch","of","sentences","with","a","saved","model",".","Args",":","model","(","onmt.modules.NMTModel",")",":","NMT","model","to","use","for","translation","vocabs","(","dict","[","str",",","Vocab","]",")",":","A","dict","mapping","each","side","'s","Vocab",".","gpu","(","int",")",":","GPU","device",".","Set","to","negative","for","no","GPU",".","n_best","(","int",")",":","How","many","beams","to","wait","for",".","min_length","(","int",")",":","See",":","class",":","`","onmt.translate.decode_strategy.DecodeStrategy","`",".","max_length","(","int",")",":","See",":","class",":","`","onmt.translate.decode_strategy.DecodeStrategy","`",".","beam_size","(","int",")",":","Number","of","beams",".","random_sampling_topk","(","int",")",":","See",":","class",":","`","onmt.translate.greedy_search.GreedySearch","`",".","random_sampling_temp","(","float",")",":","See",":","class",":","`","onmt.translate.greedy_search.GreedySearch","`",".","stepwise_penalty","(","bool",")",":","Whether","coverage","penalty","is","applied","every","step","or","not",".","dump_beam","(","bool",")",":","Debugging","option",".","block_ngram_repeat","(","int",")",":","See",":","class",":","`","onmt.translate.decode_strategy.DecodeStrategy","`",".","ignore_when_blocking","(","set","or","frozenset",")",":","See",":","class",":","`","onmt.translate.decode_strategy.DecodeStrategy","`",".","replace_unk","(","bool",")",":","Replace","unknown","token",".","tgt_file_prefix","(","bool",")",":","Force","the","predictions","begin","with","provided","-tgt",".","data_type","(","str",")",":","Source","data","type",".","verbose","(","bool",")",":","Print\/log","every","translation",".","report_time","(","bool",")",":","Print\/log","total","time\/frequency",".","copy_attn","(","bool",")",":","Use","copy","attention",".","global_scorer","(","onmt.translate.GNMTGlobalScorer",")",":","Translation","scoring\/reranking","object",".","out_file","(","TextIO","or","codecs.StreamReaderWriter",")",":","Output","file",".","report_score","(","bool",")",":","Whether","to","report","scores","logger","(","logging.Logger","or","NoneType",")",":","Logger","."]
code: def __init__(
      self,
      model,
      vocabs,
      gpu=-1,
      n_best=1,
      min_length=0,
      max_length=100,
      max_length_ratio=1.5,
      ratio=0.0,
      beam_size=30,
      random_sampling_topk=0,
      random_sampling_topp=0.0,
      random_sampling_temp=1.0,
      stepwise_penalty=None,
      dump_beam=False,
      block_ngram_repeat=0,
      ignore_when_blocking=frozenset(),
      replace_unk=False,
      ban_unk_token=False,
      tgt_file_prefix=False,
      phrase_table="",
      data_type="text",
      verbose=False,
      report_time=False,
      copy_attn=False,
      global_scorer=None,
      out_file=None,
      report_align=False,
      gold_align=False,
      report_score=True,
      logger=None,
      seed=-1,
      with_score=False,
  ):
      self.model = model
      self.vocabs = vocabs
      self._tgt_vocab = vocabs["tgt"]
      self._tgt_eos_idx = vocabs["tgt"].lookup_token(DefaultTokens.EOS)
      self._tgt_pad_idx = vocabs["tgt"].lookup_token(DefaultTokens.PAD)
      self._tgt_bos_idx = vocabs["tgt"].lookup_token(DefaultTokens.BOS)
      self._tgt_unk_idx = vocabs["tgt"].lookup_token(DefaultTokens.UNK)
      self._tgt_sep_idx = vocabs["tgt"].lookup_token(DefaultTokens.SEP)
      self._tgt_start_with = vocabs["tgt"].lookup_token(
          vocabs["decoder_start_token"]
      )
      self._tgt_vocab_len = len(self._tgt_vocab)
  
      self._gpu = gpu
      self._use_cuda = gpu > -1
      self._dev = (
          torch.device("cuda", self._gpu)
          if self._use_cuda
          else torch.device("cpu")
      )
  
      self.n_best = n_best
      self.max_length = max_length
      self.max_length_ratio = max_length_ratio
  
      self.beam_size = beam_size
      self.random_sampling_temp = random_sampling_temp
      self.sample_from_topk = random_sampling_topk
      self.sample_from_topp = random_sampling_topp
  
      self.min_length = min_length
      self.ban_unk_token = ban_unk_token
      self.ratio = ratio
      self.stepwise_penalty = stepwise_penalty
      self.dump_beam = dump_beam
      self.block_ngram_repeat = block_ngram_repeat
      self.ignore_when_blocking = ignore_when_blocking
      self._exclusion_idxs = {
          self._tgt_vocab[t] for t in self.ignore_when_blocking
      }
      self.replace_unk = replace_unk
      if self.replace_unk and not self.model.decoder.attentional:
          raise ValueError(
              "replace_unk requires an attentional decoder."
          )
      self.tgt_file_prefix = tgt_file_prefix
      self.phrase_table = phrase_table
      self.data_type = data_type
      self.verbose = verbose
      self.report_time = report_time
  
      self.copy_attn = copy_attn
  
      self.global_scorer = global_scorer
      if (
          self.global_scorer.has_cov_pen
          and not self.model.decoder.attentional
      ):
          raise ValueError(
              "Coverage penalty requires an attentional decoder."
          )
      self.out_file = out_file
      self.report_align = report_align
      self.gold_align = gold_align
      self.report_score = report_score
      self.logger = logger
  
      self.use_filter_pred = False
      self._filter_pred = None
  
      # for debugging
      self.beam_trace = self.dump_beam != ""
      self.beam_accum = None
      if self.beam_trace:
          self.beam_accum = {
              "predicted_ids": [],
              "beam_parent_ids": [],
              "scores": [],
              "log_probs": [],
          }
  
      set_random_seed(seed, self._use_cuda)
      self.with_score = with_score
  
imports: import torch
  from torch.nn.functional import log_softmax
  from torch.nn.utils.rnn import pad_sequence
  import codecs
  from time import time
  from math import exp
  from itertools import count, zip_longest
  from copy import deepcopy
  import onmt.model_builder
  import onmt.decoders.ensemble
  from onmt.constants import DefaultTokens
  from onmt.translate.beam_search import BeamSearch, BeamSearchLM
  from onmt.translate.greedy_search import GreedySearch, GreedySearchLM
  from onmt.utils.misc import tile, set_random_seed, report_matrix
  from onmt.utils.alignment import extract_alignment, build_align_pharaoh
  from onmt.modules.copy_generator import collapse_copy_scores
  from onmt.constants import ModelTask
  from onmt.transforms import TransformPipe
label_desc: Use image node_id 1 to create a new Inference object from inherited base classes: object with example: obj = Inference(model, vocabs, gpu, n_best, min_length, max_length, max_length_ratio, ratio, beam_size, random_sampling_topk, random_sampling_topp, random_sampling_temp, stepwise_penalty, dump_beam, block_ngram_repeat, ignore_when_blocking, replace_unk, ban_unk_token, tgt_file_prefix, phrase_table, data_type, verbose, report_time, copy_attn, global_scorer, out_file, report_align, gold_align, report_score, logger, seed, with_score)