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."""
  
      if (
          stage == sb.Stage.TRAIN
          and self.step % show_results_every != 0
      ):
          p_seq, wav_lens = predictions
      else:
          p_seq, wav_lens, predicted_tokens = predictions
  
      ids = batch.id
      tokens_eos, tokens_eos_lens = batch.tokens_eos
      tokens, tokens_lens = batch.tokens
  
      # 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_seq = self.hparams.seq_cost(
          p_seq, tokens_eos, length=tokens_eos_lens
      )
  
      loss = loss_seq
  
      if (stage != sb.Stage.TRAIN) or (
          self.step % show_results_every == 0
      ):
          # Decode token terms to words
          predicted_semantics = [
              tokenizer.decode_ids(utt_seq).split(" ")
              for utt_seq in predicted_tokens
          ]
  
          target_semantics = [wrd.split(" ") for wrd in batch.semantics]
  
          for i in range(len(target_semantics)):
              print(" ".join(predicted_semantics[i]))
              print(" ".join(target_semantics[i]))
              print("")
  
          if stage != sb.Stage.TRAIN:
              self.wer_metric.append(
                  ids, predicted_semantics, target_semantics
              )
              self.cer_metric.append(
                  ids, predicted_semantics, target_semantics
              )
  
      return loss
  
file_path: speechbrain/recipes/timers-and-such/direct/train_with_wav2vec2.py
imports: import sys
  import torch
  import speechbrain
  import logging
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main, if_main_process
label_desc: Use image node_id 2 for calling the SLU obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss