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.
      """
      batch = batch.to(self.device)
  
      x, _ = batch.code
      y, _ = batch.sig
  
      # 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 = (x, y)
  
      (
          y_hat,
          scores_fake,
          feats_fake,
          scores_real,
          feats_real,
          log_dur_pred,
          log_dur,
      ) = predictions
  
      loss_g = self.hparams.generator_loss(
          stage,
          y_hat,
          y,
          scores_fake,
          feats_fake,
          feats_real,
          log_dur_pred,
          log_dur,
      )
      loss_d = self.hparams.discriminator_loss(scores_fake, scores_real)
      loss = {**loss_g, **loss_d}
      self.last_loss_stats[stage] = scalarize(loss)
      return loss
  
imports: import sys
  import copy
  import random
  import pathlib
  from hyperpyyaml import load_hyperpyyaml
  import speechbrain
  from speechbrain.utils.data_utils import scalarize
  import torch
  import torchaudio
  import numpy
label_desc: Use image node_id 2 for calling the HifiGanBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss