class_docstr: Text-to-Speech Transformer module.
  
  This is a module of text-to-speech Transformer described
  in `Neural Speech Synthesis with Transformer Network`_,
  which convert the sequence of characters
  or phonemes into the sequence of Mel-filterbanks.
  
  .. _`Neural Speech Synthesis with Transformer Network`:
      https://arxiv.org/pdf/1809.08895.pdf
class_docstr_tok: ["Text-to-Speech","Transformer","module",".","This","is","a","module","of","text-to-speech","Transformer","described","in","`","Neural","Speech","Synthesis","with","Transformer","Network","`","_",",","which","convert","the","sequence","of","characters","or","phonemes","into","the","sequence","of","Mel-filterbanks",".","..","_","`","Neural","Speech","Synthesis","with","Transformer","Network","`",":","https",":","\/\/arxiv.org\/pdf\/1809.08895.pdf"]
docstr: Calculate all of the attention weights.
  
  Args:
      xs (Tensor): Batch of padded character ids (B, Tmax).
      ilens (LongTensor): Batch of lengths of each input batch (B,).
      ys (Tensor): Batch of padded target features (B, Lmax, odim).
      olens (LongTensor): Batch of the lengths of each target (B,).
      spembs (Tensor, optional):
          Batch of speaker embedding vectors (B, spk_embed_dim).
      skip_output (bool, optional): Whether to skip calculate the final output.
      keep_tensor (bool, optional): Whether to keep original tensor.
  
  Returns:
      dict: Dict of attention weights and outputs.
docstr_tok: ["Calculate","all","of","the","attention","weights",".","Args",":","xs","(","Tensor",")",":","Batch","of","padded","character","ids","(","B",",","Tmax",")",".","ilens","(","LongTensor",")",":","Batch","of","lengths","of","each","input","batch","(","B",",",")",".","ys","(","Tensor",")",":","Batch","of","padded","target","features","(","B",",","Lmax",",","odim",")",".","olens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","spembs","(","Tensor",",","optional",")",":","Batch","of","speaker","embedding","vectors","(","B",",","spk_embed_dim",")",".","skip_output","(","bool",",","optional",")",":","Whether","to","skip","calculate","the","final","output",".","keep_tensor","(","bool",",","optional",")",":","Whether","to","keep","original","tensor",".","Returns",":","dict",":","Dict","of","attention","weights","and","outputs","."]
code: def calculate_all_attentions(
      self,
      xs,
      ilens,
      ys,
      olens,
      spembs=None,
      skip_output=False,
      keep_tensor=False,
      *args,
      **kwargs,
  ):
      """Calculate all of the attention weights.
  
      Args:
          xs (Tensor): Batch of padded character ids (B, Tmax).
          ilens (LongTensor): Batch of lengths of each input batch (B,).
          ys (Tensor): Batch of padded target features (B, Lmax, odim).
          olens (LongTensor): Batch of the lengths of each target (B,).
          spembs (Tensor, optional):
              Batch of speaker embedding vectors (B, spk_embed_dim).
          skip_output (bool, optional): Whether to skip calculate the final output.
          keep_tensor (bool, optional): Whether to keep original tensor.
  
      Returns:
          dict: Dict of attention weights and outputs.
  
      """
      self.eval()
      with torch.no_grad():
          # forward encoder
          x_masks = self._source_mask(ilens).to(xs.device)
          hs, h_masks = self.encoder(xs, x_masks)
  
          # integrate speaker embedding
          if self.spk_embed_dim is not None:
              hs = self._integrate_with_spk_embed(hs, spembs)
  
          # thin out frames for reduction factor
          # (B, Lmax, odim) ->  (B, Lmax//r, odim)
          if self.reduction_factor > 1:
              ys_in = ys[
                  :, self.reduction_factor - 1 :: self.reduction_factor
              ]
              olens_in = olens.new(
                  [olen // self.reduction_factor for olen in olens]
              )
          else:
              ys_in, olens_in = ys, olens
  
          # add first zero frame and remove last frame for auto-regressive
          ys_in = self._add_first_frame_and_remove_last_frame(ys_in)
  
          # forward decoder
          y_masks = self._target_mask(olens_in).to(xs.device)
          zs, _ = self.decoder(ys_in, y_masks, hs, h_masks)
  
          # calculate final outputs
          if not skip_output:
              before_outs = self.feat_out(zs).view(
                  zs.size(0), -1, self.odim
              )
              if self.postnet is None:
                  after_outs = before_outs
              else:
                  after_outs = before_outs + self.postnet(
                      before_outs.transpose(1, 2)
                  ).transpose(1, 2)
  
      # modifiy mod part of output lengths due to reduction factor > 1
      if self.reduction_factor > 1:
          olens = olens.new(
              [olen - olen % self.reduction_factor for olen in olens]
          )
  
      # store into dict
      att_ws_dict = dict()
      if keep_tensor:
          for name, m in self.named_modules():
              if isinstance(m, MultiHeadedAttention):
                  att_ws_dict[name] = m.attn
          if not skip_output:
              att_ws_dict["before_postnet_fbank"] = before_outs
              att_ws_dict["after_postnet_fbank"] = after_outs
      else:
          for name, m in self.named_modules():
              if isinstance(m, MultiHeadedAttention):
                  attn = m.attn.cpu().numpy()
                  if "encoder" in name:
                      attn = [
                          a[:, :l, :l]
                          for a, l in zip(attn, ilens.tolist())
                      ]
                  elif "decoder" in name:
                      if "src" in name:
                          attn = [
                              a[:, :ol, :il]
                              for a, il, ol in zip(
                                  attn,
                                  ilens.tolist(),
                                  olens_in.tolist(),
                              )
                          ]
                      elif "self" in name:
                          attn = [
                              a[:, :l, :l]
                              for a, l in zip(attn, olens_in.tolist())
                          ]
                      else:
                          logging.warning(
                              "unknown attention module: " + name
                          )
                  else:
                      logging.warning(
                          "unknown attention module: " + name
                      )
                  att_ws_dict[name] = attn
          if not skip_output:
              before_outs = before_outs.cpu().numpy()
              after_outs = after_outs.cpu().numpy()
              att_ws_dict["before_postnet_fbank"] = [
                  m[:l].T for m, l in zip(before_outs, olens.tolist())
              ]
              att_ws_dict["after_postnet_fbank"] = [
                  m[:l].T for m, l in zip(after_outs, olens.tolist())
              ]
      self.train()
      return att_ws_dict
  
imports: import logging
  import torch
  import torch.nn.functional
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import GuidedAttentionLoss
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2Loss
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  from espnet.nets.pytorch_backend.tacotron2.decoder import Prenet
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.decoder import Decoder
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.initializer import initialize
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.cli_utils import strtobool
  from espnet.utils.fill_missing_args import fill_missing_args
label_desc: Use image node_id 8 for calling the Transformer obj's underlying member method code with example usage: obj.calculate_all_attentions(xs, ilens, ys, olens, spembs, skip_output, keep_tensor) and returns: att_ws_dict