class_docstr: Class that manages the training loop. See speechbrain.core.Brain.
class_docstr_tok: ["Class","that","manages","the","training","loop",".","See","speechbrain.core.Brain","."]
docstr: Computes the loss given the predicted and targeted outputs.
  Arguments
  ---------
  predictions : tensor
      The output tensor 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",":","tensor","The","output","tensor","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 : tensor
          The output tensor 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.
      """
      batch = batch.to(self.device)
      x, _ = batch.mel
      y, _ = batch.sig
      self.last_batch = (x, y)
      self._remember_sample(self.last_batch, predictions)
  
      preds, noise, noisy_sample, lens = predictions
  
      loss = self.hparams.compute_cost(
          preds.squeeze(1), noise.squeeze(1), length=lens
      )
  
      self.last_loss_stats[stage] = {"loss": loss}
      return loss
  
file_path: speechbrain/recipes/LJSpeech/TTS/vocoder/diffwave/train.py
imports: import torchaudio
  import logging
  import sys
  import torch
  import speechbrain
  import os
  from hyperpyyaml import load_hyperpyyaml
label_desc: Use image node_id 2 for calling the DiffWaveBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss