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 : dict
      The output dict 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",":","dict","The","output","dict","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 : dict
          The output dict 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.
      """
  
      # Prepare clean targets for comparison
      clean_spec = self.compute_feats(self.clean_wavs)
  
      # Directly compare the masked spectrograms with the clean targets
      loss = sb.nnet.losses.mse_loss(
          predictions["spec"], clean_spec, self.lens
      )
  
      # Append this batch of losses to the loss metric for easy
      self.loss_metric.append(
          batch.id,
          predictions["spec"],
          clean_spec,
          self.lens,
          reduction="batch",
      )
  
      # Some evaluations are slower, and we only want to perform them
      # on the validation set.
      if stage != sb.Stage.TRAIN:
          # Evaluate speech intelligibility as an additional metric
          self.stoi_metric.append(
              batch.id,
              predictions["wav"],
              self.clean_wavs,
              self.lens,
              reduction="batch",
          )
  
      return loss
  
file_path: speechbrain/templates/enhancement/train.py
imports: import sys
  import torch
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from mini_librispeech_prepare import prepare_mini_librispeech
label_desc: Use image node_id 3 for calling the SEBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss