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 hate loss will be multiplied
  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.Tacotron2 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)
  >>> targets = mel_target, gate_target
  >>> model_outputs = mel_out, mel_out_postnet, gate_out, alignments
  >>> input_lengths = torch.tensor([173,  91])
  >>> target_lengths = torch.tensor([861, 438])
  >>> loss(model_outputs, targets, input_lengths, target_lengths, 1)
  TacotronLoss(loss=tensor(4.8566), mel_loss=tensor(4.0097), gate_loss=tensor(0.8460), attn_loss=tensor(0.0010), attn_weight=tensor(1.))
class_docstr_tok: ["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","hate","loss","will","be","multiplied","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.Tacotron2","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",")",">",">",">","targets","=","mel_target",",","gate_target",">",">",">","model_outputs","=","mel_out",",","mel_out_postnet",",","gate_out",",","alignments",">",">",">","input_lengths","=","torch.tensor","(","[","173",",","91","]",")",">",">",">","target_lengths","=","torch.tensor","(","[","861",",","438","]",")",">",">",">","loss","(","model_outputs",",","targets",",","input_lengths",",","target_lengths",",","1",")","TacotronLoss","(","loss=tensor","(","4.8566",")",",","mel_loss=tensor","(","4.0097",")",",","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,
      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.mse_loss = nn.MSELoss()
      self.bce_loss = nn.BCEWithLogitsLoss()
      self.guided_attention_loss = GuidedAttentionLoss(
          sigma=guided_attention_sigma
      )
      self.gate_loss_weight = gate_loss_weight
      self.guided_attention_weight = guided_attention_weight
      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
  from speechbrain.lobes.models.transformer.Transformer import get_mask_from_lengths
  import torch
  from torch import nn
  from torch.nn import functional
  from collections import namedtuple
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, guided_attention_weight, guided_attention_scheduler, guided_attention_hard_stop)