class_docstr: Loss function module for Tacotron2.
class_docstr_tok: ["Loss","function","module","for","Tacotron2","."]
docstr: Calculate forward propagation.
  
  Args:
      after_outs (Tensor): Batch of outputs after postnets (B, Lmax, odim).
      before_outs (Tensor): Batch of outputs before postnets (B, Lmax, odim).
      logits (Tensor): Batch of stop logits (B, Lmax).
      ys (Tensor): Batch of padded target features (B, Lmax, odim).
      labels (LongTensor): Batch of the sequences of stop token labels (B, Lmax).
      olens (LongTensor): Batch of the lengths of each target (B,).
  
  Returns:
      Tensor: L1 loss value.
      Tensor: Mean square error loss value.
      Tensor: Binary cross entropy loss value.
docstr_tok: ["Calculate","forward","propagation",".","Args",":","after_outs","(","Tensor",")",":","Batch","of","outputs","after","postnets","(","B",",","Lmax",",","odim",")",".","before_outs","(","Tensor",")",":","Batch","of","outputs","before","postnets","(","B",",","Lmax",",","odim",")",".","logits","(","Tensor",")",":","Batch","of","stop","logits","(","B",",","Lmax",")",".","ys","(","Tensor",")",":","Batch","of","padded","target","features","(","B",",","Lmax",",","odim",")",".","labels","(","LongTensor",")",":","Batch","of","the","sequences","of","stop","token","labels","(","B",",","Lmax",")",".","olens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","Returns",":","Tensor",":","L1","loss","value",".","Tensor",":","Mean","square","error","loss","value",".","Tensor",":","Binary","cross","entropy","loss","value","."]
code: def forward(self, after_outs, before_outs, logits, ys, labels, olens):
      """Calculate forward propagation.
  
      Args:
          after_outs (Tensor): Batch of outputs after postnets (B, Lmax, odim).
          before_outs (Tensor): Batch of outputs before postnets (B, Lmax, odim).
          logits (Tensor): Batch of stop logits (B, Lmax).
          ys (Tensor): Batch of padded target features (B, Lmax, odim).
          labels (LongTensor): Batch of the sequences of stop token labels (B, Lmax).
          olens (LongTensor): Batch of the lengths of each target (B,).
  
      Returns:
          Tensor: L1 loss value.
          Tensor: Mean square error loss value.
          Tensor: Binary cross entropy loss value.
  
      """
      # make mask and apply it
      if self.use_masking:
          masks = make_non_pad_mask(olens).unsqueeze(-1).to(ys.device)
          ys = ys.masked_select(masks)
          after_outs = after_outs.masked_select(masks)
          before_outs = before_outs.masked_select(masks)
          labels = labels.masked_select(masks[:, :, 0])
          logits = logits.masked_select(masks[:, :, 0])
  
      # calculate loss
      l1_loss = self.l1_criterion(after_outs, ys) + self.l1_criterion(
          before_outs, ys
      )
      mse_loss = self.mse_criterion(
          after_outs, ys
      ) + self.mse_criterion(before_outs, ys)
      bce_loss = self.bce_criterion(logits, labels)
  
      # make weighted mask and apply it
      if self.use_weighted_masking:
          masks = make_non_pad_mask(olens).unsqueeze(-1).to(ys.device)
          weights = (
              masks.float() / masks.sum(dim=1, keepdim=True).float()
          )
          out_weights = weights.div(ys.size(0) * ys.size(2))
          logit_weights = weights.div(ys.size(0))
  
          # apply weight
          l1_loss = l1_loss.mul(out_weights).masked_select(masks).sum()
          mse_loss = (
              mse_loss.mul(out_weights).masked_select(masks).sum()
          )
          bce_loss = (
              bce_loss.mul(logit_weights.squeeze(-1))
              .masked_select(masks.squeeze(-1))
              .sum()
          )
  
      return l1_loss, mse_loss, bce_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 2 for calling the Tacotron2Loss obj's underlying member method code with example usage: obj.forward(after_outs, before_outs, logits, ys, labels, olens) and returns: l1_loss,  mse_loss,  bce_loss