docstr: Translate a batch of sentences.
docstr_tok: ["Translate","a","batch","of","sentences","."]
code: def translate_batch(self, batch, attn_debug):
      """Translate a batch of sentences."""
      if self.max_length_ratio > 0:
          max_length = int(
              min(
                  self.max_length,
                  batch["src"].size(1) * self.max_length_ratio + 5,
              )
          )
      else:
          max_length = self.max_length
      with torch.no_grad():
          if self.sample_from_topk != 0 or self.sample_from_topp != 0:
              decode_strategy = GreedySearch(
                  pad=self._tgt_pad_idx,
                  bos=self._tgt_bos_idx,
                  eos=self._tgt_eos_idx,
                  unk=self._tgt_unk_idx,
                  start=self._tgt_start_with,
                  n_best=self.n_best,
                  batch_size=len(batch["srclen"]),
                  global_scorer=self.global_scorer,
                  min_length=self.min_length,
                  max_length=max_length,
                  block_ngram_repeat=self.block_ngram_repeat,
                  exclusion_tokens=self._exclusion_idxs,
                  return_attention=attn_debug or self.replace_unk,
                  sampling_temp=self.random_sampling_temp,
                  keep_topk=self.sample_from_topk,
                  keep_topp=self.sample_from_topp,
                  beam_size=self.beam_size,
                  ban_unk_token=self.ban_unk_token,
              )
          else:
              # TODO: support these blacklisted features
              assert not self.dump_beam
              decode_strategy = BeamSearch(
                  self.beam_size,
                  batch_size=len(batch["srclen"]),
                  pad=self._tgt_pad_idx,
                  bos=self._tgt_bos_idx,
                  eos=self._tgt_eos_idx,
                  unk=self._tgt_unk_idx,
                  start=self._tgt_start_with,
                  n_best=self.n_best,
                  global_scorer=self.global_scorer,
                  min_length=self.min_length,
                  max_length=max_length,
                  return_attention=attn_debug or self.replace_unk,
                  block_ngram_repeat=self.block_ngram_repeat,
                  exclusion_tokens=self._exclusion_idxs,
                  stepwise_penalty=self.stepwise_penalty,
                  ratio=self.ratio,
                  ban_unk_token=self.ban_unk_token,
              )
          return self._translate_batch_with_strategy(
              batch, decode_strategy
          )
  
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 3 for calling the Translator obj's underlying member method code with example usage: obj.translate_batch(batch, attn_debug) and returns: self