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 forward propagation.
  
  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).
  
  Returns:
      Tensor: Loss value.
docstr_tok: ["Calculate","forward","propagation",".","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",")",".","Returns",":","Tensor",":","Loss","value","."]
code: def forward(
      self, xs, ilens, ys, labels, olens, spembs=None, *args, **kwargs
  ):
      """Calculate forward propagation.
  
      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).
  
      Returns:
          Tensor: Loss value.
  
      """
      # remove unnecessary padded part (for multi-gpus)
      max_ilen = max(ilens)
      max_olen = max(olens)
      if max_ilen != xs.shape[1]:
          xs = xs[:, :max_ilen]
      if max_olen != ys.shape[1]:
          ys = ys[:, :max_olen]
          labels = labels[:, :max_olen]
  
      # 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)
      # (B, Lmax//r, odim * r) -> (B, Lmax//r * r, odim)
      before_outs = self.feat_out(zs).view(zs.size(0), -1, self.odim)
      # (B, Lmax//r, r) -> (B, Lmax//r * r)
      logits = self.prob_out(zs).view(zs.size(0), -1)
  
      # postnet -> (B, Lmax//r * r, 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 groundtruth
      if self.reduction_factor > 1:
          assert olens.ge(
              self.reduction_factor
          ).all(), "Output length must be greater than or equal to reduction factor."
          olens = olens.new(
              [olen - olen % self.reduction_factor for olen in olens]
          )
          max_olen = max(olens)
          ys = ys[:, :max_olen]
          labels = labels[:, :max_olen]
          labels = torch.scatter(
              labels, 1, (olens - 1).unsqueeze(1), 1.0
          )  # see #3388
  
      # calculate loss values
      l1_loss, l2_loss, bce_loss = self.criterion(
          after_outs, before_outs, logits, ys, labels, olens
      )
      if self.loss_type == "L1":
          loss = l1_loss + bce_loss
      elif self.loss_type == "L2":
          loss = l2_loss + bce_loss
      elif self.loss_type == "L1+L2":
          loss = l1_loss + l2_loss + bce_loss
      else:
          raise ValueError("unknown --loss-type " + self.loss_type)
      report_keys = [
          {"l1_loss": l1_loss.item()},
          {"l2_loss": l2_loss.item()},
          {"bce_loss": bce_loss.item()},
          {"loss": loss.item()},
      ]
  
      # calculate guided attention loss
      if self.use_guided_attn_loss:
          # calculate for encoder
          if "encoder" in self.modules_applied_guided_attn:
              att_ws = []
              for idx, layer_idx in enumerate(
                  reversed(range(len(self.encoder.encoders)))
              ):
                  att_ws += [
                      self.encoder.encoders[layer_idx].self_attn.attn[
                          :, : self.num_heads_applied_guided_attn
                      ]
                  ]
                  if idx + 1 == self.num_layers_applied_guided_attn:
                      break
              att_ws = torch.cat(att_ws, dim=1)  # (B, H*L, T_in, T_in)
              enc_attn_loss = self.attn_criterion(att_ws, ilens, ilens)
              loss = loss + enc_attn_loss
              report_keys += [{"enc_attn_loss": enc_attn_loss.item()}]
          # calculate for decoder
          if "decoder" in self.modules_applied_guided_attn:
              att_ws = []
              for idx, layer_idx in enumerate(
                  reversed(range(len(self.decoder.decoders)))
              ):
                  att_ws += [
                      self.decoder.decoders[layer_idx].self_attn.attn[
                          :, : self.num_heads_applied_guided_attn
                      ]
                  ]
                  if idx + 1 == self.num_layers_applied_guided_attn:
                      break
              att_ws = torch.cat(
                  att_ws, dim=1
              )  # (B, H*L, T_out, T_out)
              dec_attn_loss = self.attn_criterion(
                  att_ws, olens_in, olens_in
              )
              loss = loss + dec_attn_loss
              report_keys += [{"dec_attn_loss": dec_attn_loss.item()}]
          # calculate for encoder-decoder
          if "encoder-decoder" in self.modules_applied_guided_attn:
              att_ws = []
              for idx, layer_idx in enumerate(
                  reversed(range(len(self.decoder.decoders)))
              ):
                  att_ws += [
                      self.decoder.decoders[layer_idx].src_attn.attn[
                          :, : self.num_heads_applied_guided_attn
                      ]
                  ]
                  if idx + 1 == self.num_layers_applied_guided_attn:
                      break
              att_ws = torch.cat(att_ws, dim=1)  # (B, H*L, T_out, T_in)
              enc_dec_attn_loss = self.attn_criterion(
                  att_ws, ilens, olens_in
              )
              loss = loss + enc_dec_attn_loss
              report_keys += [
                  {"enc_dec_attn_loss": enc_dec_attn_loss.item()}
              ]
  
      # report extra information
      if self.use_scaled_pos_enc:
          report_keys += [
              {
                  "encoder_alpha": self.encoder.embed[
                      -1
                  ].alpha.data.item()
              },
              {
                  "decoder_alpha": self.decoder.embed[
                      -1
                  ].alpha.data.item()
              },
          ]
      self.reporter.report(report_keys)
  
      return loss
  
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 6 for calling the Transformer obj's underlying member method code with example usage: obj.forward(xs, ilens, ys, labels, olens, spembs) and returns: loss