class_docstr: Loss function module for feed-forward Transformer.
class_docstr_tok: ["Loss","function","module","for","feed-forward","Transformer","."]
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).
      d_outs (Tensor): Batch of outputs of duration predictor (B, Tmax).
      ys (Tensor): Batch of target features (B, Lmax, odim).
      ds (Tensor): Batch of durations (B, Tmax).
      ilens (LongTensor): Batch of the lengths of each input (B,).
      olens (LongTensor): Batch of the lengths of each target (B,).
  
  Returns:
      Tensor: L1 loss value.
      Tensor: Duration predictor 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",")",".","d_outs","(","Tensor",")",":","Batch","of","outputs","of","duration","predictor","(","B",",","Tmax",")",".","ys","(","Tensor",")",":","Batch","of","target","features","(","B",",","Lmax",",","odim",")",".","ds","(","Tensor",")",":","Batch","of","durations","(","B",",","Tmax",")",".","ilens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","input","(","B",",",")",".","olens","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","Returns",":","Tensor",":","L1","loss","value",".","Tensor",":","Duration","predictor","loss","value","."]
code: def forward(
      self, after_outs, before_outs, d_outs, ys, ds, ilens, 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).
          d_outs (Tensor): Batch of outputs of duration predictor (B, Tmax).
          ys (Tensor): Batch of target features (B, Lmax, odim).
          ds (Tensor): Batch of durations (B, Tmax).
          ilens (LongTensor): Batch of the lengths of each input (B,).
          olens (LongTensor): Batch of the lengths of each target (B,).
  
      Returns:
          Tensor: L1 loss value.
          Tensor: Duration predictor loss value.
  
      """
      # apply mask to remove padded part
      if self.use_masking:
          duration_masks = make_non_pad_mask(ilens).to(ys.device)
          d_outs = d_outs.masked_select(duration_masks)
          ds = ds.masked_select(duration_masks)
          out_masks = (
              make_non_pad_mask(olens).unsqueeze(-1).to(ys.device)
          )
          before_outs = before_outs.masked_select(out_masks)
          after_outs = (
              after_outs.masked_select(out_masks)
              if after_outs is not None
              else None
          )
          ys = ys.masked_select(out_masks)
  
      # calculate loss
      l1_loss = self.l1_criterion(before_outs, ys)
      if after_outs is not None:
          l1_loss += self.l1_criterion(after_outs, ys)
      duration_loss = self.duration_criterion(d_outs, ds)
  
      # make weighted mask and apply it
      if self.use_weighted_masking:
          out_masks = (
              make_non_pad_mask(olens).unsqueeze(-1).to(ys.device)
          )
          out_weights = (
              out_masks.float()
              / out_masks.sum(dim=1, keepdim=True).float()
          )
          out_weights /= ys.size(0) * ys.size(2)
          duration_masks = make_non_pad_mask(ilens).to(ys.device)
          duration_weights = (
              duration_masks.float()
              / duration_masks.sum(dim=1, keepdim=True).float()
          )
          duration_weights /= ds.size(0)
  
          # apply weight
          l1_loss = (
              l1_loss.mul(out_weights).masked_select(out_masks).sum()
          )
          duration_loss = (
              duration_loss.mul(duration_weights)
              .masked_select(duration_masks)
              .sum()
          )
  
      return l1_loss, duration_loss
  
imports: import logging
  import torch
  import torch.nn.functional
  from espnet.asr.asr_utils import get_model_conf, torch_load
  from espnet.nets.pytorch_backend.fastspeech.duration_calculator import DurationCalculator
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictor, DurationPredictorLoss
  from espnet.nets.pytorch_backend.fastspeech.length_regulator import LengthRegulator
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, make_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  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 2 for calling the FeedForwardTransformerLoss obj's underlying member method code with example usage: obj.forward(after_outs, before_outs, d_outs, ys, ds, ilens, olens) and returns: l1_loss,  duration_loss