class_docstr: E2E module.
  
  :param int idim: dimension of inputs
  :param int odim: dimension of outputs
  :param Namespace args: argument Namespace containing options
class_docstr_tok: ["E2E","module",".",":","param","int","idim",":","dimension","of","inputs",":","param","int","odim",":","dimension","of","outputs",":","param","Namespace","args",":","argument","Namespace","containing","options"]
docstr: Recognize input speech of each speaker.
  
  :param ndnarray enc_output: encoder outputs (B, T, D) or (T, D)
  :param Namespace recog_args: argment Namespace contraining options
  :param list char_list: list of characters
  :param torch.nn.Module rnnlm: language model module
  :return: N-best decoding results
  :rtype: list
docstr_tok: ["Recognize","input","speech","of","each","speaker",".",":","param","ndnarray","enc_output",":","encoder","outputs","(","B",",","T",",","D",")","or","(","T",",","D",")",":","param","Namespace","recog_args",":","argment","Namespace","contraining","options",":","param","list","char_list",":","list","of","characters",":","param","torch.nn.Module","rnnlm",":","language","model","module",":","return",":","N-best","decoding","results",":","rtype",":","list"]
code: def recog(
      self,
      enc_output,
      recog_args,
      char_list=None,
      rnnlm=None,
      use_jit=False,
  ):
      """Recognize input speech of each speaker.
  
      :param ndnarray enc_output: encoder outputs (B, T, D) or (T, D)
      :param Namespace recog_args: argment Namespace contraining options
      :param list char_list: list of characters
      :param torch.nn.Module rnnlm: language model module
      :return: N-best decoding results
      :rtype: list
      """
      if recog_args.ctc_weight > 0.0:
          lpz = self.ctc.log_softmax(enc_output)
          lpz = lpz.squeeze(0)
      else:
          lpz = None
  
      h = enc_output.squeeze(0)
  
      logging.info("input lengths: " + str(h.size(0)))
      # search parms
      beam = recog_args.beam_size
      penalty = recog_args.penalty
      ctc_weight = recog_args.ctc_weight
  
      # preprare sos
      y = self.sos
      vy = h.new_zeros(1).long()
  
      if recog_args.maxlenratio == 0:
          maxlen = h.shape[0]
      else:
          # maxlen >= 1
          maxlen = max(1, int(recog_args.maxlenratio * h.size(0)))
      minlen = int(recog_args.minlenratio * h.size(0))
      logging.info("max output length: " + str(maxlen))
      logging.info("min output length: " + str(minlen))
  
      # initialize hypothesis
      if rnnlm:
          hyp = {"score": 0.0, "yseq": [y], "rnnlm_prev": None}
      else:
          hyp = {"score": 0.0, "yseq": [y]}
      if lpz is not None:
          ctc_prefix_score = CTCPrefixScore(
              lpz.detach().numpy(), 0, self.eos, numpy
          )
          hyp["ctc_state_prev"] = ctc_prefix_score.initial_state()
          hyp["ctc_score_prev"] = 0.0
          if ctc_weight != 1.0:
              # pre-pruning based on attention scores
              ctc_beam = min(
                  lpz.shape[-1], int(beam * CTC_SCORING_RATIO)
              )
          else:
              ctc_beam = lpz.shape[-1]
      hyps = [hyp]
      ended_hyps = []
  
      traced_decoder = None
      for i in range(maxlen):
          logging.debug("position " + str(i))
  
          hyps_best_kept = []
          for hyp in hyps:
              vy[0] = hyp["yseq"][i]
  
              # get nbest local scores and their ids
              ys_mask = subsequent_mask(i + 1).unsqueeze(0)
              ys = torch.tensor(hyp["yseq"]).unsqueeze(0)
              # FIXME: jit does not match non-jit result
              if use_jit:
                  if traced_decoder is None:
                      traced_decoder = torch.jit.trace(
                          self.decoder.forward_one_step,
                          (ys, ys_mask, enc_output),
                      )
                  local_att_scores = traced_decoder(
                      ys, ys_mask, enc_output
                  )[0]
              else:
                  local_att_scores = self.decoder.forward_one_step(
                      ys, ys_mask, enc_output
                  )[0]
  
              if rnnlm:
                  rnnlm_state, local_lm_scores = rnnlm.predict(
                      hyp["rnnlm_prev"], vy
                  )
                  local_scores = (
                      local_att_scores
                      + recog_args.lm_weight * local_lm_scores
                  )
              else:
                  local_scores = local_att_scores
  
              if lpz is not None:
                  local_best_scores, local_best_ids = torch.topk(
                      local_att_scores, ctc_beam, dim=1
                  )
                  ctc_scores, ctc_states = ctc_prefix_score(
                      hyp["yseq"],
                      local_best_ids[0],
                      hyp["ctc_state_prev"],
                  )
                  local_scores = (1.0 - ctc_weight) * local_att_scores[
                      :, local_best_ids[0]
                  ] + ctc_weight * torch.from_numpy(
                      ctc_scores - hyp["ctc_score_prev"]
                  )
                  if rnnlm:
                      local_scores += (
                          recog_args.lm_weight
                          * local_lm_scores[:, local_best_ids[0]]
                      )
                  local_best_scores, joint_best_ids = torch.topk(
                      local_scores, beam, dim=1
                  )
                  local_best_ids = local_best_ids[:, joint_best_ids[0]]
              else:
                  local_best_scores, local_best_ids = torch.topk(
                      local_scores, 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]
                  )
                  if rnnlm:
                      new_hyp["rnnlm_prev"] = rnnlm_state
                  if lpz is not None:
                      new_hyp["ctc_state_prev"] = ctc_states[
                          joint_best_ids[0, j]
                      ]
                      new_hyp["ctc_score_prev"] = ctc_scores[
                          joint_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
                      if (
                          rnnlm
                      ):  # Word LM needs to add final <eos> score
                          hyp[
                              "score"
                          ] += recog_args.lm_weight * rnnlm.final(
                              hyp["rnnlm_prev"]
                          )
                      ended_hyps.append(hyp)
              else:
                  remained_hyps.append(hyp)
  
          # end detection
  
          if (
              end_detect(ended_hyps, i)
              and recog_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), recog_args.nbest)]
  
      # check number of hypotheis
      if len(nbest_hyps) == 0:
          logging.warning(
              "there is no N-best results, perform recognition "
              "again with smaller minlenratio."
          )
          # should copy becasuse Namespace will be overwritten globally
          recog_args = Namespace(**vars(recog_args))
          recog_args.minlenratio = max(
              0.0, recog_args.minlenratio - 0.1
          )
          return self.recog(enc_output, recog_args, char_list, rnnlm)
  
      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.asr_interface import ASRInterface
  from espnet.nets.ctc_prefix_score import CTCPrefixScore
  from espnet.nets.e2e_asr_common import end_detect
  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_asr_mix import E2E
  from espnet.nets.pytorch_backend.e2e_asr_mix import PIT
  from espnet.nets.pytorch_backend.e2e_asr_transformer import E2E
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, th_accuracy
  from espnet.nets.pytorch_backend.rnn.decoders import CTC_SCORING_RATIO
  from espnet.nets.pytorch_backend.transformer.add_sos_eos import add_sos_eos
  from espnet.nets.pytorch_backend.transformer.encoder_mix import EncoderMix
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask, target_mask
label_desc: Use image node_id 6 for calling the E2E obj's underlying member method code with example usage: obj.recog(enc_output, recog_args, char_list, rnnlm, use_jit) and returns: nbest_hyps, self