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.))
docstr: Computes the attention loss
  Arguments
  ---------
  alignments: torch.Tensor
      the aligment matrix from the model
  input_lengths: torch.Tensor
      a (batch, length) tensor of input lengths
  target_lengths: torch.Tensor
      a (batch, length) tensor of target (spectrogram) lengths
  epoch: int
      the current epoch number (used for the scheduling of the guided attention
      loss) A StepScheduler is typically used
  Returns
  -------
  attn_loss: torch.Tensor
      the attention loss value
docstr_tok: ["Computes","the","attention","loss","Arguments","--","--","--","--","-","alignments",":","torch.Tensor","the","aligment","matrix","from","the","model","input_lengths",":","torch.Tensor","a","(","batch",",","length",")","tensor","of","input","lengths","target_lengths",":","torch.Tensor","a","(","batch",",","length",")","tensor","of","target","(","spectrogram",")","lengths","epoch",":","int","the","current","epoch","number","(","used","for","the","scheduling","of","the","guided","attention","loss",")","A","StepScheduler","is","typically","used","Returns","--","--","--","-","attn_loss",":","torch.Tensor","the","attention","loss","value"]
code: def get_attention_loss(
      self, alignments, input_lengths, target_lengths, epoch
  ):
      """Computes the attention loss
      Arguments
      ---------
      alignments: torch.Tensor
          the aligment matrix from the model
      input_lengths: torch.Tensor
          a (batch, length) tensor of input lengths
      target_lengths: torch.Tensor
          a (batch, length) tensor of target (spectrogram) lengths
      epoch: int
          the current epoch number (used for the scheduling of the guided attention
          loss) A StepScheduler is typically used
      Returns
      -------
      attn_loss: torch.Tensor
          the attention loss value
      """
      zero_tensor = torch.tensor(0.0, device=alignments.device)
      if (
          self.guided_attention_weight is None
          or self.guided_attention_weight == 0
      ):
          attn_weight, attn_loss = zero_tensor, zero_tensor
      else:
          hard_stop_reached = (
              self.guided_attention_hard_stop is not None
              and epoch > self.guided_attention_hard_stop
          )
          if hard_stop_reached:
              attn_weight, attn_loss = zero_tensor, zero_tensor
          else:
              attn_weight = self.guided_attention_weight
              if self.guided_attention_scheduler is not None:
                  _, attn_weight = self.guided_attention_scheduler(
                      epoch
                  )
          attn_weight = torch.tensor(
              attn_weight, device=alignments.device
          )
          attn_loss = attn_weight * self.guided_attention_loss(
              alignments, input_lengths, target_lengths
          )
      return attn_loss, attn_weight
  
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 3 for calling the Loss obj's underlying member method code with example usage: obj.get_attention_loss(alignments, input_lengths, target_lengths, epoch) and returns: attn_loss,  attn_weight