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).
      ys (Tensor): Batch of padded target features (B, Lmax, odim).
      olens (LongTensor): Batch of the lengths of each target (B,).
  
  Returns:
      Tensor: L1 loss value.
      Tensor: Mean square error 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",")",".","ys","(","Tensor",")",":","Batch","of","padded","target","features","(","B",",","Lmax",",","odim",")",".","olens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","Returns",":","Tensor",":","L1","loss","value",".","Tensor",":","Mean","square","error","loss","value","."]
code: def forward(self, after_outs, before_outs, ys, 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).
          ys (Tensor): Batch of padded target features (B, Lmax, odim).
          olens (LongTensor): Batch of the lengths of each target (B,).
  
      Returns:
          Tensor: L1 loss value.
          Tensor: Mean square error 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)
  
      # 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)
  
      # 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))
  
          # apply weight
          l1_loss = l1_loss.mul(out_weights).masked_select(masks).sum()
          mse_loss = (
              mse_loss.mul(out_weights).masked_select(masks).sum()
          )
  
      return l1_loss, mse_loss
  
imports: from typing import Dict, Optional, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.svs.abs_svs import AbsSVS
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.torch_utils.initialize import initialize
  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.encoder import Encoder
label_desc: Use image node_id 2 for calling the NaiveRNNLoss obj's underlying member method code with example usage: obj.forward(after_outs, before_outs, ys, olens) and returns: l1_loss,  mse_loss