class_docstr: The Brain implementation for Tacotron2
class_docstr_tok: ["The","Brain","implementation","for","Tacotron2"]
docstr: Computes the loss given the predicted and targeted outputs.
  Arguments
  ---------
  predictions : torch.Tensor
      The model generated spectrograms and other metrics from `compute_forward`.
  batch : PaddedBatch
      This batch object contains all the relevant tensors for computation.
  stage : sb.Stage
      One of sb.Stage.TRAIN, sb.Stage.VALID, or sb.Stage.TEST.
  Returns
  -------
  loss : torch.Tensor
      A one-element tensor used for backpropagating the gradient.
docstr_tok: ["Computes","the","loss","given","the","predicted","and","targeted","outputs",".","Arguments","--","--","--","--","-","predictions",":","torch.Tensor","The","model","generated","spectrograms","and","other","metrics","from","`","compute_forward","`",".","batch",":","PaddedBatch","This","batch","object","contains","all","the","relevant","tensors","for","computation",".","stage",":","sb.Stage","One","of","sb.Stage.TRAIN",",","sb.Stage.VALID",",","or","sb.Stage.TEST",".","Returns","--","--","--","-","loss",":","torch.Tensor","A","one-element","tensor","used","for","backpropagating","the","gradient","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss given the predicted and targeted outputs.
      Arguments
      ---------
      predictions : torch.Tensor
          The model generated spectrograms and other metrics from `compute_forward`.
      batch : PaddedBatch
          This batch object contains all the relevant tensors for computation.
      stage : sb.Stage
          One of sb.Stage.TRAIN, sb.Stage.VALID, or sb.Stage.TEST.
      Returns
      -------
      loss : torch.Tensor
          A one-element tensor used for backpropagating the gradient.
      """
      effective_batch = self.batch_to_device(batch)
      # Hold on to the batch for the inference sample. This is needed because
      # the infernece sample is run from on_stage_end only, where
      # batch information is not available
      self.last_batch = effective_batch
      # Hold on to a sample (for logging)
      self._remember_sample(effective_batch, predictions)
      # Compute the loss
      loss = self._compute_loss(predictions, effective_batch, stage)
      return loss
  
file_path: speechbrain/recipes/LJSpeech/TTS/tacotron2/train.py
imports: import torch
  import speechbrain
  import sys
  import logging
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.text_to_sequence import text_to_sequence
  from speechbrain.utils.data_utils import scalarize
label_desc: Use image node_id 4 for calling the Tacotron2Brain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss