class_docstr: Tacotron2 module for end-to-end text-to-speech (E2E-TTS).
  
  This is a module of Spectrogram prediction network in Tacotron2 described
  in `Natural TTS Synthesis
  by Conditioning WaveNet on Mel Spectrogram Predictions`_,
  which converts the sequence of characters
  into the sequence of Mel-filterbanks.
  
  .. _`Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions`:
     https://arxiv.org/abs/1712.05884
class_docstr_tok: ["Tacotron2","module","for","end-to-end","text-to-speech","(","E2E-TTS",")",".","This","is","a","module","of","Spectrogram","prediction","network","in","Tacotron2","described","in","`","Natural","TTS","Synthesis","by","Conditioning","WaveNet","on","Mel","Spectrogram","Predictions","`","_",",","which","converts","the","sequence","of","characters","into","the","sequence","of","Mel-filterbanks",".","..","_","`","Natural","TTS","Synthesis","by","Conditioning","WaveNet","on","Mel","Spectrogram","Predictions","`",":","https",":","\/\/arxiv.org\/abs\/1712.05884"]
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).
      extras (Tensor, optional):
          Batch of groundtruth spectrograms (B, Lmax, spc_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",")",".","extras","(","Tensor",",","optional",")",":","Batch","of","groundtruth","spectrograms","(","B",",","Lmax",",","spc_dim",")",".","Returns",":","Tensor",":","Loss","value","."]
code: def forward(
      self,
      xs,
      ilens,
      ys,
      labels,
      olens,
      spembs=None,
      extras=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).
          extras (Tensor, optional):
              Batch of groundtruth spectrograms (B, Lmax, spc_dim).
  
      Returns:
          Tensor: Loss value.
  
      """
      # remove unnecessary padded part (for multi-gpus)
      max_in = max(ilens)
      max_out = max(olens)
      if max_in != xs.shape[1]:
          xs = xs[:, :max_in]
      if max_out != ys.shape[1]:
          ys = ys[:, :max_out]
          labels = labels[:, :max_out]
  
      # calculate tacotron2 outputs
      hs, hlens = self.enc(xs, ilens)
      if self.spk_embed_dim is not None:
          spembs = (
              F.normalize(spembs)
              .unsqueeze(1)
              .expand(-1, hs.size(1), -1)
          )
          hs = torch.cat([hs, spembs], dim=-1)
      after_outs, before_outs, logits, att_ws = self.dec(hs, hlens, ys)
  
      # 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_out = max(olens)
          ys = ys[:, :max_out]
          labels = labels[:, :max_out]
          labels = torch.scatter(
              labels, 1, (olens - 1).unsqueeze(1), 1.0
          )  # see #3388
  
      # calculate taco2 loss
      l1_loss, mse_loss, bce_loss = self.taco2_loss(
          after_outs, before_outs, logits, ys, labels, olens
      )
      loss = l1_loss + mse_loss + bce_loss
      report_keys = [
          {"l1_loss": l1_loss.item()},
          {"mse_loss": mse_loss.item()},
          {"bce_loss": bce_loss.item()},
      ]
  
      # calculate attention loss
      if self.use_guided_attn_loss:
          # NOTE(kan-bayashi):
          # length of output for auto-regressive input will be changed when r > 1
          if self.reduction_factor > 1:
              olens_in = olens.new(
                  [olen // self.reduction_factor for olen in olens]
              )
          else:
              olens_in = olens
          attn_loss = self.attn_loss(att_ws, ilens, olens_in)
          loss = loss + attn_loss
          report_keys += [
              {"attn_loss": attn_loss.item()},
          ]
  
      # calculate cbhg loss
      if self.use_cbhg:
          # remove unnecessary padded part (for multi-gpus)
          if max_out != extras.shape[1]:
              extras = extras[:, :max_out]
  
          # calculate cbhg outputs & loss and report them
          cbhg_outs, _ = self.cbhg(after_outs, olens)
          cbhg_l1_loss, cbhg_mse_loss = self.cbhg_loss(
              cbhg_outs, extras, olens
          )
          loss = loss + cbhg_l1_loss + cbhg_mse_loss
          report_keys += [
              {"cbhg_l1_loss": cbhg_l1_loss.item()},
              {"cbhg_mse_loss": cbhg_mse_loss.item()},
          ]
  
      report_keys += [{"loss": loss.item()}]
      self.reporter.report(report_keys)
  
      return loss
  
imports: import logging
  import numpy
  import torch
  import torch.nn.functional
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
  from espnet.nets.pytorch_backend.rnn.attentions import AttForward, AttForwardTA, AttLoc
  from espnet.nets.pytorch_backend.tacotron2.cbhg import CBHG, CBHGLoss
  from espnet.nets.pytorch_backend.tacotron2.decoder import Decoder
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
  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 3 for calling the Tacotron2 obj's underlying member method code with example usage: obj.forward(xs, ilens, ys, labels, olens, spembs, extras) and returns: loss