class_docstr: The Tacotron loss implementation
  The loss consists of an MSE loss on the spectrogram, a BCE gate loss
  and a guided attention loss (if enabled) that attempts to make the
  attention matrix diagonal
  The output of the moduel is a LossStats tuple, which includes both the
  total loss
  Arguments
  ---------
  guided_attention_sigma: float
      The guided attention sigma factor, controling the "width" of
      the mask
  gate_loss_weight: float
      The constant by which the gate loss will be multiplied
  mel_loss_weight: float
      The constant by which the mel loss will be multiplied
  spk_emb_loss_weight: float
      The constant by which the speaker embedding loss will be multiplied - placeholder for future work
  spk_emb_loss_type: str
      Type of the speaker embedding loss - placeholder for future work
  guided_attention_weight: float
      The weight for the guided attention
  guided_attention_scheduler: callable
      The scheduler class for the guided attention loss
  guided_attention_hard_stop: int
      The number of epochs after which guided attention will be compeltely
      turned off
  Example:
  >>> import torch
  >>> _ = torch.manual_seed(42)
  >>> from speechbrain.lobes.models.MSTacotron2 import Loss
  >>> loss = Loss(guided_attention_sigma=0.2)
  >>> mel_target = torch.randn(2, 80, 861)
  >>> gate_target = torch.randn(1722, 1)
  >>> mel_out = torch.randn(2, 80, 861)
  >>> mel_out_postnet = torch.randn(2, 80, 861)
  >>> gate_out = torch.randn(2, 861)
  >>> alignments = torch.randn(2, 861, 173)
  >>> pred_mel_lens = torch.randn(2)
  >>> targets = mel_target, gate_target
  >>> model_outputs = mel_out, mel_out_postnet, gate_out, alignments, pred_mel_lens
  >>> input_lengths = torch.tensor([173,  91])
  >>> target_lengths = torch.tensor([861, 438])
  >>> spk_embs = None
  >>> loss(model_outputs, targets, input_lengths, target_lengths, spk_embs, 1)
  TacotronLoss(loss=tensor([4.8566]), mel_loss=tensor(4.0097), spk_emb_loss=tensor([0.]), gate_loss=tensor(0.8460), attn_loss=tensor(0.0010), attn_weight=tensor(1.))
code: def __init__(
      self,
      guided_attention_sigma=None,
      gate_loss_weight=1.0,
      mel_loss_weight=1.0,
      spk_emb_loss_weight=1.0,
      spk_emb_loss_type=None,
      guided_attention_weight=1.0,
      guided_attention_scheduler=None,
      guided_attention_hard_stop=None,
  ):
      super().__init__()
      if guided_attention_weight == 0:
          guided_attention_weight = None
      self.guided_attention_weight = guided_attention_weight
      self.gate_loss_weight = gate_loss_weight
      self.mel_loss_weight = mel_loss_weight
      self.spk_emb_loss_weight = spk_emb_loss_weight
      self.spk_emb_loss_type = spk_emb_loss_type
  
      self.mse_loss = nn.MSELoss()
      self.bce_loss = nn.BCEWithLogitsLoss()
      self.guided_attention_loss = GuidedAttentionLoss(
          sigma=guided_attention_sigma
      )
      self.cos_sim = nn.CosineSimilarity()
      self.triplet_loss = torch.nn.TripletMarginWithDistanceLoss(
          distance_function=lambda x, y: 1.0 - F.cosine_similarity(x, y)
      )
      self.cos_emb_loss = nn.CosineEmbeddingLoss()
  
      self.guided_attention_scheduler = guided_attention_scheduler
      self.guided_attention_hard_stop = guided_attention_hard_stop
  
imports: from math import sqrt
  from speechbrain.nnet.loss.guidedattn_loss import GuidedAttentionLoss
  import torch
  from torch import nn
  from torch.nn import functional
  from collections import namedtuple
  import pickle
  from speechbrain.lobes.models.Tacotron2 import LinearNorm, Postnet, Encoder, Decoder, get_mask_from_lengths
label_desc: Use image node_id 1 to create a new Loss object from inherited base classes: nn with example: obj = Loss(guided_attention_sigma, gate_loss_weight, mel_loss_weight, spk_emb_loss_weight, spk_emb_loss_type, guided_attention_weight, guided_attention_scheduler, guided_attention_hard_stop)