class_docstr: Decoder module
  
  :param int eprojs: encoder projection units
  :param int odim: dimension of outputs
  :param str dtype: gru or lstm
  :param int dlayers: decoder layers
  :param int dunits: decoder units
  :param int sos: start of sequence symbol id
  :param int eos: end of sequence symbol id
  :param torch.nn.Module att: attention module
  :param int verbose: verbose level
  :param list char_list: list of character strings
  :param ndarray labeldist: distribution of label smoothing
  :param float lsm_weight: label smoothing weight
  :param float sampling_probability: scheduled sampling probability
  :param float dropout: dropout rate
  :param float context_residual: if True, use context vector for token generation
  :param float replace_sos: use for multilingual (speech/text) translation
class_docstr_tok: ["Decoder","module",":","param","int","eprojs",":","encoder","projection","units",":","param","int","odim",":","dimension","of","outputs",":","param","str","dtype",":","gru","or","lstm",":","param","int","dlayers",":","decoder","layers",":","param","int","dunits",":","decoder","units",":","param","int","sos",":","start","of","sequence","symbol","id",":","param","int","eos",":","end","of","sequence","symbol","id",":","param","torch.nn.Module","att",":","attention","module",":","param","int","verbose",":","verbose","level",":","param","list","char_list",":","list","of","character","strings",":","param","ndarray","labeldist",":","distribution","of","label","smoothing",":","param","float","lsm_weight",":","label","smoothing","weight",":","param","float","sampling_probability",":","scheduled","sampling","probability",":","param","float","dropout",":","dropout","rate",":","param","float","context_residual",":","if","True",",","use","context","vector","for","token","generation",":","param","float","replace_sos",":","use","for","multilingual","(","speech\/text",")","translation"]
docstr: Calculate all of attentions
  
  :param torch.Tensor hs_pad: batch of padded hidden state sequences
                              (B, Tmax, D)
                              in multi-encoder case, list of torch.Tensor,
                              [(B, Tmax_1, D), (B, Tmax_2, D), ..., ] ]
  :param torch.Tensor hlen: batch of lengths of hidden state sequences (B)
                              [in multi-encoder case, list of torch.Tensor,
                              [(B), (B), ..., ]
  :param torch.Tensor ys_pad:
      batch of padded character id sequence tensor (B, Lmax)
  :param int strm_idx:
      stream index for parallel speaker attention in multi-speaker case
  :param torch.Tensor lang_ids: batch of target language id tensor (B, 1)
  :return: attention weights with the following shape,
      1) multi-head case => attention weights (B, H, Lmax, Tmax),
      2) multi-encoder case =>
          [(B, Lmax, Tmax1), (B, Lmax, Tmax2), ..., (B, Lmax, NumEncs)]
      3) other case => attention weights (B, Lmax, Tmax).
  :rtype: float ndarray
docstr_tok: ["Calculate","all","of","attentions",":","param","torch.Tensor","hs_pad",":","batch","of","padded","hidden","state","sequences","(","B",",","Tmax",",","D",")","in","multi-encoder","case",",","list","of","torch.Tensor",",","[","(","B",",","Tmax_1",",","D",")",",","(","B",",","Tmax_2",",","D",")",",","...",",","]","]",":","param","torch.Tensor","hlen",":","batch","of","lengths","of","hidden","state","sequences","(","B",")","[","in","multi-encoder","case",",","list","of","torch.Tensor",",","[","(","B",")",",","(","B",")",",","...",",","]",":","param","torch.Tensor","ys_pad",":","batch","of","padded","character","id","sequence","tensor","(","B",",","Lmax",")",":","param","int","strm_idx",":","stream","index","for","parallel","speaker","attention","in","multi-speaker","case",":","param","torch.Tensor","lang_ids",":","batch","of","target","language","id","tensor","(","B",",","1",")",":","return",":","attention","weights","with","the","following","shape",",","1",")","multi-head","case","=",">","attention","weights","(","B",",","H",",","Lmax",",","Tmax",")",",","2",")","multi-encoder","case","=",">","[","(","B",",","Lmax",",","Tmax1",")",",","(","B",",","Lmax",",","Tmax2",")",",","...",",","(","B",",","Lmax",",","NumEncs",")","]","3",")","other","case","=",">","attention","weights","(","B",",","Lmax",",","Tmax",")",".",":","rtype",":","float","ndarray"]
code: def calculate_all_attentions(
      self, hs_pad, hlen, ys_pad, strm_idx=0, lang_ids=None
  ):
      """Calculate all of attentions
  
      :param torch.Tensor hs_pad: batch of padded hidden state sequences
                                  (B, Tmax, D)
                                  in multi-encoder case, list of torch.Tensor,
                                  [(B, Tmax_1, D), (B, Tmax_2, D), ..., ] ]
      :param torch.Tensor hlen: batch of lengths of hidden state sequences (B)
                                  [in multi-encoder case, list of torch.Tensor,
                                  [(B), (B), ..., ]
      :param torch.Tensor ys_pad:
          batch of padded character id sequence tensor (B, Lmax)
      :param int strm_idx:
          stream index for parallel speaker attention in multi-speaker case
      :param torch.Tensor lang_ids: batch of target language id tensor (B, 1)
      :return: attention weights with the following shape,
          1) multi-head case => attention weights (B, H, Lmax, Tmax),
          2) multi-encoder case =>
              [(B, Lmax, Tmax1), (B, Lmax, Tmax2), ..., (B, Lmax, NumEncs)]
          3) other case => attention weights (B, Lmax, Tmax).
      :rtype: float ndarray
      """
      # to support mutiple encoder asr mode, in single encoder mode,
      # convert torch.Tensor to List of torch.Tensor
      if self.num_encs == 1:
          hs_pad = [hs_pad]
          hlen = [hlen]
  
      # TODO(kan-bayashi): need to make more smart way
      ys = [y[y != self.ignore_id] for y in ys_pad]  # parse padded ys
      att_idx = min(strm_idx, len(self.att) - 1)
  
      # hlen should be list of list of integer
      hlen = [list(map(int, hlen[idx])) for idx in range(self.num_encs)]
  
      self.loss = None
      # prepare input and output word sequences with sos/eos IDs
      eos = ys[0].new([self.eos])
      sos = ys[0].new([self.sos])
      if self.replace_sos:
          ys_in = [
              torch.cat([idx, y], dim=0) for idx, y in zip(lang_ids, ys)
          ]
      else:
          ys_in = [torch.cat([sos, y], dim=0) for y in ys]
      ys_out = [torch.cat([y, eos], dim=0) for y in ys]
  
      # padding for ys with -1
      # pys: utt x olen
      ys_in_pad = pad_list(ys_in, self.eos)
      ys_out_pad = pad_list(ys_out, self.ignore_id)
  
      # get length info
      olength = ys_out_pad.size(1)
  
      # initialization
      c_list = [self.zero_state(hs_pad[0])]
      z_list = [self.zero_state(hs_pad[0])]
      for _ in range(1, self.dlayers):
          c_list.append(self.zero_state(hs_pad[0]))
          z_list.append(self.zero_state(hs_pad[0]))
      att_ws = []
      if self.num_encs == 1:
          att_w = None
          self.att[att_idx].reset()  # reset pre-computation of h
      else:
          att_w_list = [None] * (self.num_encs + 1)  # atts + han
          att_c_list = [None] * (self.num_encs)  # atts
          for idx in range(self.num_encs + 1):
              self.att[
                  idx
              ].reset()  # reset pre-computation of h in atts and han
  
      # pre-computation of embedding
      eys = self.dropout_emb(self.embed(ys_in_pad))  # utt x olen x zdim
  
      # loop for an output sequence
      for i in range(olength):
          if self.num_encs == 1:
              att_c, att_w = self.att[att_idx](
                  hs_pad[0],
                  hlen[0],
                  self.dropout_dec[0](z_list[0]),
                  att_w,
              )
              att_ws.append(att_w)
          else:
              for idx in range(self.num_encs):
                  att_c_list[idx], att_w_list[idx] = self.att[idx](
                      hs_pad[idx],
                      hlen[idx],
                      self.dropout_dec[0](z_list[0]),
                      att_w_list[idx],
                  )
              hs_pad_han = torch.stack(att_c_list, dim=1)
              hlen_han = [self.num_encs] * len(ys_in)
              att_c, att_w_list[self.num_encs] = self.att[
                  self.num_encs
              ](
                  hs_pad_han,
                  hlen_han,
                  self.dropout_dec[0](z_list[0]),
                  att_w_list[self.num_encs],
              )
              att_ws.append(att_w_list.copy())
          ey = torch.cat(
              (eys[:, i, :], att_c), dim=1
          )  # utt x (zdim + hdim)
          z_list, c_list = self.rnn_forward(
              ey, z_list, c_list, z_list, c_list
          )
  
      if self.num_encs == 1:
          # convert to numpy array with the shape (B, Lmax, Tmax)
          att_ws = att_to_numpy(att_ws, self.att[att_idx])
      else:
          _att_ws = []
          for idx, ws in enumerate(zip(*att_ws)):
              ws = att_to_numpy(ws, self.att[idx])
              _att_ws.append(ws)
          att_ws = _att_ws
      return att_ws
  
imports: import logging
  import math
  import random
  from argparse import Namespace
  import numpy
  import torch
  import torch.nn.functional
  from espnet.nets.ctc_prefix_score import CTCPrefixScore, CTCPrefixScoreTH
  from espnet.nets.e2e_asr_common import end_detect
  from espnet.nets.pytorch_backend.nets_utils import mask_by_length, pad_list, th_accuracy, to_device
  from espnet.nets.pytorch_backend.rnn.attentions import att_to_numpy
  from espnet.nets.scorer_interface import ScorerInterface
label_desc: Use image node_id 7 for calling the Decoder obj's underlying member method code with example usage: obj.calculate_all_attentions(hs_pad, hlen, ys_pad, strm_idx, lang_ids) and returns: att_ws