class_docstr: E2E module.
  
  :param int idim: dimension of inputs
  :param int odim: dimension of outputs
  :param Namespace args: argument Namespace containing options
docstr: Translate input speech.
  
  :param ndnarray x: input acoustic feature (B, T, D) or (T, D)
  :param Namespace trans_args: argment Namespace contraining options
  :param list char_list: list of characters
  :return: N-best decoding results
  :rtype: list
code: def translate(
      self,
      x,
      trans_args,
      char_list=None,
  ):
      """Translate input speech.
  
      :param ndnarray x: input acoustic feature (B, T, D) or (T, D)
      :param Namespace trans_args: argment Namespace contraining options
      :param list char_list: list of characters
      :return: N-best decoding results
      :rtype: list
      """
      # preprate sos
      if getattr(trans_args, "tgt_lang", False):
          if self.replace_sos:
              y = char_list.index(trans_args.tgt_lang)
      else:
          y = self.sos
      logging.info("<sos> index: " + str(y))
      logging.info("<sos> mark: " + char_list[y])
      logging.info("input lengths: " + str(x.shape[0]))
  
      enc_output = self.encode(x).unsqueeze(0)
  
      h = enc_output
  
      logging.info("encoder output lengths: " + str(h.size(1)))
      # search parms
      beam = trans_args.beam_size
      penalty = trans_args.penalty
  
      if trans_args.maxlenratio == 0:
          maxlen = h.size(1)
      else:
          # maxlen >= 1
          maxlen = max(1, int(trans_args.maxlenratio * h.size(1)))
      minlen = int(trans_args.minlenratio * h.size(1))
      logging.info("max output length: " + str(maxlen))
      logging.info("min output length: " + str(minlen))
  
      # initialize hypothesis
      hyp = {"score": 0.0, "yseq": [y]}
      hyps = [hyp]
      ended_hyps = []
  
      for i in range(maxlen):
          logging.debug("position " + str(i))
  
          # batchfy
          ys = h.new_zeros((len(hyps), i + 1), dtype=torch.int64)
          for j, hyp in enumerate(hyps):
              ys[j, :] = torch.tensor(hyp["yseq"])
          ys_mask = subsequent_mask(i + 1).unsqueeze(0).to(h.device)
  
          local_scores = self.decoder.forward_one_step(
              ys, ys_mask, h.repeat([len(hyps), 1, 1])
          )[0]
  
          hyps_best_kept = []
          for j, hyp in enumerate(hyps):
              local_best_scores, local_best_ids = torch.topk(
                  local_scores[j : j + 1], beam, dim=1
              )
  
              for j in range(beam):
                  new_hyp = {}
                  new_hyp["score"] = hyp["score"] + float(
                      local_best_scores[0, j]
                  )
                  new_hyp["yseq"] = [0] * (1 + len(hyp["yseq"]))
                  new_hyp["yseq"][: len(hyp["yseq"])] = hyp["yseq"]
                  new_hyp["yseq"][len(hyp["yseq"])] = int(
                      local_best_ids[0, j]
                  )
                  # will be (2 x beam) hyps at most
                  hyps_best_kept.append(new_hyp)
  
              hyps_best_kept = sorted(
                  hyps_best_kept, key=lambda x: x["score"], reverse=True
              )[:beam]
  
          # sort and get nbest
          hyps = hyps_best_kept
          logging.debug("number of pruned hypothes: " + str(len(hyps)))
          if char_list is not None:
              logging.debug(
                  "best hypo: "
                  + "".join(
                      [char_list[int(x)] for x in hyps[0]["yseq"][1:]]
                  )
              )
  
          # add eos in the final loop to avoid that there are no ended hyps
          if i == maxlen - 1:
              logging.info(
                  "adding <eos> in the last position in the loop"
              )
              for hyp in hyps:
                  hyp["yseq"].append(self.eos)
  
          # add ended hypothes to a final list, and removed them from current hypothes
          # (this will be a probmlem, number of hyps < beam)
          remained_hyps = []
          for hyp in hyps:
              if hyp["yseq"][-1] == self.eos:
                  # only store the sequence that has more than minlen outputs
                  # also add penalty
                  if len(hyp["yseq"]) > minlen:
                      hyp["score"] += (i + 1) * penalty
                      ended_hyps.append(hyp)
              else:
                  remained_hyps.append(hyp)
  
          # end detection
          if (
              end_detect(ended_hyps, i)
              and trans_args.maxlenratio == 0.0
          ):
              logging.info("end detected at %d", i)
              break
  
          hyps = remained_hyps
          if len(hyps) > 0:
              logging.debug("remeined hypothes: " + str(len(hyps)))
          else:
              logging.info("no hypothesis. Finish decoding.")
              break
  
          if char_list is not None:
              for hyp in hyps:
                  logging.debug(
                      "hypo: "
                      + "".join(
                          [char_list[int(x)] for x in hyp["yseq"][1:]]
                      )
                  )
  
          logging.debug(
              "number of ended hypothes: " + str(len(ended_hyps))
          )
  
      nbest_hyps = sorted(
          ended_hyps, key=lambda x: x["score"], reverse=True
      )[: min(len(ended_hyps), trans_args.nbest)]
  
      # check number of hypotheis
      if len(nbest_hyps) == 0:
          logging.warning(
              "there is no N-best results, perform translation "
              "again with smaller minlenratio."
          )
          # should copy becasuse Namespace will be overwritten globally
          trans_args = Namespace(**vars(trans_args))
          trans_args.minlenratio = max(
              0.0, trans_args.minlenratio - 0.1
          )
          return self.translate(x, trans_args, char_list)
  
      logging.info(
          "total log probability: " + str(nbest_hyps[0]["score"])
      )
      logging.info(
          "normalized log probability: "
          + str(nbest_hyps[0]["score"] / len(nbest_hyps[0]["yseq"]))
      )
      return nbest_hyps
  
imports: import logging
  import math
  from argparse import Namespace
  import numpy
  import torch
  from espnet.nets.e2e_asr_common import ErrorCalculator
  from espnet.nets.e2e_asr_common import end_detect
  from espnet.nets.e2e_mt_common import ErrorCalculator
  from espnet.nets.pytorch_backend.ctc import CTC
  from espnet.nets.pytorch_backend.e2e_asr import CTC_LOSS_THRESHOLD
  from espnet.nets.pytorch_backend.e2e_st import Reporter
  from espnet.nets.pytorch_backend.nets_utils import get_subsample, make_non_pad_mask, pad_list, th_accuracy
  from espnet.nets.pytorch_backend.transformer.add_sos_eos import add_sos_eos
  from espnet.nets.pytorch_backend.transformer.argument import add_arguments_transformer_common
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.decoder import Decoder
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.initializer import initialize
  from espnet.nets.pytorch_backend.transformer.label_smoothing_loss import LabelSmoothingLoss
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask, target_mask
  from espnet.nets.pytorch_backend.transformer.plot import PlotAttentionReport
  from espnet.nets.st_interface import STInterface
  from espnet.utils.fill_missing_args import fill_missing_args
label_desc: Use image node_id 11 for calling the E2E obj's underlying member method code with example usage: obj.translate(x, trans_args, char_list) and returns: nbest_hyps, self