docstr: Computes the loss NLL given predictions and targets.
docstr_tok: ["Computes","the","loss","NLL","given","predictions","and","targets","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss NLL given predictions and targets."""
  
      (
          log_probs,
          hyps,
          wav_lens,
      ) = predictions
      batch = batch.to(self.device)
      ids = batch.id
      tokens_eos, tokens_eos_lens = batch.tokens_eos
  
      # Label Augmentation
      if stage == sb.Stage.TRAIN and hasattr(
          self.hparams, "wav_augment"
      ):
          tokens_eos = self.hparams.wav_augment.replicate_labels(
              tokens_eos
          )
          tokens_eos_lens = self.hparams.wav_augment.replicate_labels(
              tokens_eos_lens
          )
  
      loss = self.hparams.nll_loss(
          log_probs,
          tokens_eos,
          length=tokens_eos_lens,
      )
  
      if stage != sb.Stage.TRAIN:
          tokens, tokens_lens = batch.tokens
  
          hyps = [hyp[0] if len(hyp) > 0 else [] for hyp in hyps]
  
          # Decode token terms to words
          predicted_words = self.tokenizer.batch_decode(
              hyps, skip_special_tokens=True
          )
  
          # Convert indices to words
          target_words = undo_padding(tokens, tokens_lens)
          target_words = self.tokenizer.batch_decode(
              target_words, skip_special_tokens=True
          )
  
          if hasattr(self.hparams, "normalized_transcripts"):
              predicted_words = [
                  self.tokenizer._normalize(text).split(" ")
                  for text in predicted_words
              ]
  
              target_words = [
                  self.tokenizer._normalize(text).split(" ")
                  for text in target_words
              ]
          else:
              predicted_words = [
                  text.split(" ") for text in predicted_words
              ]
  
              target_words = [text.split(" ") for text in target_words]
          self.wer_metric.append(ids, predicted_words, target_words)
          self.cer_metric.append(ids, predicted_words, target_words)
  
      return loss
  
file_path: speechbrain/recipes/LibriSpeech/ASR/transformer/train_with_whisper.py
imports: import os
  import sys
  import torch
  import logging
  import speechbrain
  from speechbrain.utils.distributed import run_on_main, if_main_process
  from speechbrain.utils.data_utils import undo_padding
  from hyperpyyaml import load_hyperpyyaml
  from pathlib import Path
label_desc: Use image node_id 2 for calling the ASR obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss