class_docstr: Custom decoder module for Transducer model.
  
  Args:
      odim: Output dimension.
      dec_arch: Decoder block architecture (type and parameters).
      input_layer: Input layer type.
      repeat_block: Number of times dec_arch is repeated.
      joint_activation_type: Type of activation for joint network.
      positional_encoding_type: Positional encoding type.
      positionwise_layer_type: Positionwise layer type.
      positionwise_activation_type: Positionwise activation type.
      input_layer_dropout_rate: Dropout rate for input layer.
      blank_id: Blank symbol ID.
class_docstr_tok: ["Custom","decoder","module","for","Transducer","model",".","Args",":","odim",":","Output","dimension",".","dec_arch",":","Decoder","block","architecture","(","type","and","parameters",")",".","input_layer",":","Input","layer","type",".","repeat_block",":","Number","of","times","dec_arch","is","repeated",".","joint_activation_type",":","Type","of","activation","for","joint","network",".","positional_encoding_type",":","Positional","encoding","type",".","positionwise_layer_type",":","Positionwise","layer","type",".","positionwise_activation_type",":","Positionwise","activation","type",".","input_layer_dropout_rate",":","Dropout","rate","for","input","layer",".","blank_id",":","Blank","symbol","ID","."]
docstr: One-step forward hypotheses.
  
  Args:
      hyps: Hypotheses.
      dec_states: Decoder hidden states. [N x (B, U, D_dec)]
      cache: Pairs of (h_dec, dec_states) for each label sequences. (keys)
      use_lm: Whether to compute label ID sequences for LM.
  
  Returns:
      dec_out: Decoder output sequences. (B, D_dec)
      dec_states: Decoder hidden states. [N x (B, U, D_dec)]
      lm_labels: Label ID sequences for LM. (B,)
docstr_tok: ["One-step","forward","hypotheses",".","Args",":","hyps",":","Hypotheses",".","dec_states",":","Decoder","hidden","states",".","[","N","x","(","B",",","U",",","D_dec",")","]","cache",":","Pairs","of","(","h_dec",",","dec_states",")","for","each","label","sequences",".","(","keys",")","use_lm",":","Whether","to","compute","label","ID","sequences","for","LM",".","Returns",":","dec_out",":","Decoder","output","sequences",".","(","B",",","D_dec",")","dec_states",":","Decoder","hidden","states",".","[","N","x","(","B",",","U",",","D_dec",")","]","lm_labels",":","Label","ID","sequences","for","LM",".","(","B",",",")"]
code: def batch_score(
      self,
      hyps: Union[List[Hypothesis], List[ExtendedHypothesis]],
      dec_states: List[Optional[torch.Tensor]],
      cache: Dict[str, Any],
      use_lm: bool,
  ) -> Tuple[torch.Tensor, List[Optional[torch.Tensor]], torch.Tensor]:
      """One-step forward hypotheses.
  
      Args:
          hyps: Hypotheses.
          dec_states: Decoder hidden states. [N x (B, U, D_dec)]
          cache: Pairs of (h_dec, dec_states) for each label sequences. (keys)
          use_lm: Whether to compute label ID sequences for LM.
  
      Returns:
          dec_out: Decoder output sequences. (B, D_dec)
          dec_states: Decoder hidden states. [N x (B, U, D_dec)]
          lm_labels: Label ID sequences for LM. (B,)
  
      """
      final_batch = len(hyps)
  
      process = []
      done = [None] * final_batch
  
      for i, hyp in enumerate(hyps):
          str_labels = "_".join(list(map(str, hyp.yseq)))
  
          if str_labels in cache:
              done[i] = cache[str_labels]
          else:
              process.append((str_labels, hyp.yseq, hyp.dec_state))
  
      if process:
          labels = pad_sequence([p[1] for p in process], self.blank_id)
          labels = torch.LongTensor(labels, device=self.device)
  
          p_dec_states = self.create_batch_states(
              self.init_state(),
              [p[2] for p in process],
              labels,
          )
  
          dec_out = self.embed(labels)
  
          dec_out_mask = (
              subsequent_mask(labels.size(-1))
              .unsqueeze_(0)
              .expand(len(process), -1, -1)
          )
  
          new_states = []
          for s, decoder in zip(p_dec_states, self.decoders):
              dec_out, dec_out_mask = decoder(
                  dec_out, dec_out_mask, cache=s
              )
              new_states.append(dec_out)
  
          dec_out = self.after_norm(dec_out[:, -1])
  
      j = 0
      for i in range(final_batch):
          if done[i] is None:
              state = self.select_state(new_states, j)
  
              done[i] = (dec_out[j], state)
              cache[process[j][0]] = (dec_out[j], state)
  
              j += 1
  
      dec_out = torch.stack([d[0] for d in done])
      dec_states = self.create_batch_states(
          dec_states, [d[1] for d in done], [[0] + h.yseq for h in hyps]
      )
  
      if use_lm:
          lm_labels = torch.LongTensor(
              [hyp.yseq[-1] for hyp in hyps], device=self.device
          )
  
          return dec_out, dec_states, lm_labels
  
      return dec_out, dec_states, None
  
file_path: espnet/espnet/nets/pytorch_backend/transducer/custom_decoder.py
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  from espnet.nets.pytorch_backend.transducer.blocks import build_blocks
  from espnet.nets.pytorch_backend.transducer.utils import check_batch_states, check_state, pad_sequence
  from espnet.nets.pytorch_backend.transformer.layer_norm import LayerNorm
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.transducer_decoder_interface import ExtendedHypothesis, Hypothesis, TransducerDecoderInterface
label_desc: Use image node_id 6 for calling the CustomDecoder obj's underlying member method code with example usage: obj.batch_score(hyps, dec_states, cache, use_lm) and returns: dec_out,  dec_states,  None, dec_out,  dec_states,  lm_labels