class_docstr: VC Transformer module.
  
  This is a module of the Voice Transformer Network
  (a.k.a. VTN or Transformer-VC) described in
  `Voice Transformer Network: Sequence-to-Sequence
  Voice Conversion Using Transformer with
  Text-to-Speech Pretraining`_,
  which convert the sequence of acoustic features
  into the sequence of acoustic features.
  
  .. _`Voice Transformer Network: Sequence-to-Sequence
      Voice Conversion Using Transformer with
      Text-to-Speech Pretraining`:
      https://arxiv.org/pdf/1912.06813.pdf
class_docstr_tok: ["VC","Transformer","module",".","This","is","a","module","of","the","Voice","Transformer","Network","(","a.k.a",".","VTN","or","Transformer-VC",")","described","in","`","Voice","Transformer","Network",":","Sequence-to-Sequence","Voice","Conversion","Using","Transformer","with","Text-to-Speech","Pretraining","`","_",",","which","convert","the","sequence","of","acoustic","features","into","the","sequence","of","acoustic","features",".","..","_","`","Voice","Transformer","Network",":","Sequence-to-Sequence","Voice","Conversion","Using","Transformer","with","Text-to-Speech","Pretraining","`",":","https",":","\/\/arxiv.org\/pdf\/1912.06813.pdf"]
docstr: Calculate forward propagation.
  
  Args:
      xs (Tensor): Batch of padded acoustic features (B, Tmax, idim).
      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","acoustic","features","(","B",",","Tmax",",","idim",")",".","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 acoustic features (B, Tmax, idim).
          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]
  
      # thin out input frames for reduction factor
      # (B, Lmax, idim) ->  (B, Lmax // r, idim * r)
      if self.encoder_reduction_factor > 1:
          B, Lmax, idim = xs.shape
          if Lmax % self.encoder_reduction_factor != 0:
              xs = xs[:, : -(Lmax % self.encoder_reduction_factor), :]
          xs_ds = xs.contiguous().view(
              B,
              int(Lmax / self.encoder_reduction_factor),
              idim * self.encoder_reduction_factor,
          )
          ilens_ds = ilens.new(
              [ilen // self.encoder_reduction_factor for ilen in ilens]
          )
      else:
          xs_ds, ilens_ds = xs, ilens
  
      # forward encoder
      x_masks = self._source_mask(ilens_ds).to(xs.device)
      hs, hs_masks = self.encoder(xs_ds, x_masks)
  
      # integrate speaker embedding
      if self.spk_embed_dim is not None:
          hs_int = self._integrate_with_spk_embed(hs, spembs)
      else:
          hs_int = hs
  
      # 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)
  
      # if conv2d, modify mask. Use ceiling division here
      if "conv2d" in self.transformer_input_layer:
          ilens_ds_st = ilens_ds.new(
              [((ilen - 2 + 1) // 2 - 2 + 1) // 2 for ilen in ilens_ds]
          )
      else:
          ilens_ds_st = ilens_ds
  
      # forward decoder
      y_masks = self._target_mask(olens_in).to(xs.device)
      zs, _ = self.decoder(ys_in, y_masks, hs_int, hs_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_ds_st, ilens_ds_st
              )  # TODO(unilight): is changing to ilens_ds_st right?
              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_ds_st, olens_in
              )  # TODO(unilight): is changing to ilens_ds_st right?
              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_asr_transformer import subsequent_mask
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2Loss
  from espnet.nets.pytorch_backend.e2e_tts_transformer import TTSPlot
  from espnet.nets.pytorch_backend.e2e_tts_transformer import GuidedMultiHeadAttentionLoss
  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.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