class_docstr: Loss function module for Tacotron2.
class_docstr_tok: ["Loss","function","module","for","Tacotron2","."]
docstr: Initialize Tactoron2 loss module.
  
  Args:
      use_masking (bool): Whether to apply masking
          for padded part in loss calculation.
      use_weighted_masking (bool):
          Whether to apply weighted masking in loss calculation.
      bce_pos_weight (float): Weight of positive sample of stop token.
docstr_tok: ["Initialize","Tactoron2","loss","module",".","Args",":","use_masking","(","bool",")",":","Whether","to","apply","masking","for","padded","part","in","loss","calculation",".","use_weighted_masking","(","bool",")",":","Whether","to","apply","weighted","masking","in","loss","calculation",".","bce_pos_weight","(","float",")",":","Weight","of","positive","sample","of","stop","token","."]
code: def __init__(
      self,
      use_masking=True,
      use_weighted_masking=False,
      bce_pos_weight=20.0,
  ):
      """Initialize Tactoron2 loss module.
  
      Args:
          use_masking (bool): Whether to apply masking
              for padded part in loss calculation.
          use_weighted_masking (bool):
              Whether to apply weighted masking in loss calculation.
          bce_pos_weight (float): Weight of positive sample of stop token.
  
      """
      super(Tacotron2Loss, self).__init__()
      assert (use_masking != use_weighted_masking) or not use_masking
      self.use_masking = use_masking
      self.use_weighted_masking = use_weighted_masking
  
      # define criterions
      reduction = "none" if self.use_weighted_masking else "mean"
      self.l1_criterion = torch.nn.L1Loss(reduction=reduction)
      self.mse_criterion = torch.nn.MSELoss(reduction=reduction)
      self.bce_criterion = torch.nn.BCEWithLogitsLoss(
          reduction=reduction, pos_weight=torch.tensor(bce_pos_weight)
      )
  
      # NOTE(kan-bayashi): register pre hook function for the compatibility
      self._register_load_state_dict_pre_hook(
          self._load_state_dict_pre_hook
      )
  
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 1 to create a new Tacotron2Loss object from inherited base classes: torch.nn with example: obj = Tacotron2Loss(use_masking, use_weighted_masking, bce_pos_weight)