class_docstr: Inference engine subclass to run inference with ctranslate2.
  
  Args:
      opt: inference options
class_docstr_tok: ["Inference","engine","subclass","to","run","inference","with","ctranslate2",".","Args",":","opt",":","inference","options"]
code: def translate_batch(self, batch, opt):
      input_tokens = []
      for i in range(batch["src"].size()[0]):
          start_ids = batch["src"][i, :, 0].cpu().numpy().tolist()
          _input_tokens = [
              self.vocabs["src"].lookup_index(id)
              for id in start_ids
              if id
              != self.vocabs["src"].lookup_token(DefaultTokens.PAD)
          ]
          input_tokens.append(_input_tokens)
      if opt.model_task == ModelTask.LANGUAGE_MODEL:
          translated_batch = self.translator.generate_batch(
              start_tokens=input_tokens,
              batch_type=(
                  "examples" if opt.batch_type == "sents" else "tokens"
              ),
              max_batch_size=opt.batch_size,
              beam_size=opt.beam_size,
              num_hypotheses=opt.n_best,
              max_length=opt.max_length,
              return_scores=True,
              include_prompt_in_result=False,
              sampling_topk=opt.random_sampling_topk,
              sampling_topp=opt.random_sampling_topp,
              sampling_temperature=opt.random_sampling_temp,
          )
          preds = [
              [
                  self.transform.apply_reverse(tokens)
                  for tokens in out.sequences
              ]
              for out in translated_batch
          ]
          scores = [out.scores for out in translated_batch]
      elif opt.model_task == ModelTask.SEQ2SEQ:
          translated_batch = self.translator.translate_batch(
              input_tokens,
              batch_type=(
                  "examples" if opt.batch_type == "sents" else "tokens"
              ),
              max_batch_size=opt.batch_size,
              beam_size=opt.beam_size,
              num_hypotheses=opt.n_best,
              max_decoding_length=opt.max_length,
              return_scores=True,
              sampling_topk=opt.random_sampling_topk,
              sampling_topp=opt.random_sampling_topp,
              sampling_temperature=opt.random_sampling_temp,
          )
          preds = [
              [
                  self.transform.apply_reverse(tokens)
                  for tokens in out.hypotheses
              ]
              for out in translated_batch
          ]
          scores = [out.scores for out in translated_batch]
  
      return scores, preds
  
imports: import json
  from onmt.constants import CorpusTask, DefaultTokens, ModelTask
  from onmt.inputters.dynamic_iterator import build_dynamic_dataset_iter
  from onmt.utils.distributed import ErrorHandler, spawned_infer
  from onmt.utils.logging import init_logger
  from onmt.transforms import get_transforms_cls, make_transforms, TransformPipe
label_desc: Use image node_id 2 for calling the InferenceEngineCT2 obj's underlying member method code with example usage: obj.translate_batch(batch, opt) and returns: scores,  preds