docstr: Computes the loss (CTC+NLL) given predictions and targets.
docstr_tok: ["Computes","the","loss","(","CTC+NLL",")","given","predictions","and","targets","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss (CTC+NLL) given predictions and targets."""
  
      if stage == sb.Stage.TRAIN:
          # We don't have to compute anything as the HF model directly returns
          # the constrative loss.
          loss = predictions
      else:
          # We compute the accuracy between embeddings with cosing sim.
          loss, out, mask_time_indices = predictions
          cosine_sim = torch.cosine_similarity(
              out.projected_states,
              out.projected_quantized_states,
              dim=-1,
          )
          acc = torch.masked_select(
              cosine_sim,
              mask_time_indices.type(torch.BoolTensor).to(self.device),
          ).mean()
          self.acc_metric.append(acc)
  
      return loss
  
file_path: speechbrain/recipes/CommonVoice/self-supervised-learning/wav2vec2/train_hf_wav2vec2.py
imports: import sys
  import torch
  import logging
  import speechbrain
  import torchaudio
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 2 for calling the W2VBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss