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.
      """
      x, y, metadata = self.batch_to_device(batch, return_metadata=True)
      self.last_batch = [x[0], y[-1], y[-2], predictions[0], *metadata]
      self._remember_sample([x[0], *y, *metadata], predictions)
      loss = self.hparams.criterion(
          predictions, y, self.hparams.epoch_counter.current
      )
      self.last_loss_stats[stage] = scalarize(loss)
      return loss["total_loss"]
  
imports: import os
  import sys
  import torch
  import logging
  import torchaudio
  import numpy
  import speechbrain
  from speechbrain.inference.vocoders import HIFIGAN
  from pathlib import Path
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.data_utils import scalarize
label_desc: Use image node_id 4 for calling the FastSpeech2Brain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss