docstr: Computes the loss (CTC) given predictions and targets.
docstr_tok: ["Computes","the","loss","(","CTC",")","given","predictions","and","targets","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss (CTC) given predictions and targets."""
  
      p_ctc, wav_lens, p_tokens = predictions
  
      ids = batch.id
      tokens_eos, tokens_eos_lens = batch.tokens_eos
      tokens, tokens_lens = batch.tokens
  
      if stage == sb.Stage.TRAIN and hasattr(
          self.hparams, "wav_augment"
      ):
          tokens = self.hparams.wav_augment.replicate_labels(tokens)
          tokens_lens = self.hparams.wav_augment.replicate_labels(
              tokens_lens
          )
  
      loss = self.hparams.ctc_cost(p_ctc, tokens, wav_lens, tokens_lens)
  
      if stage == sb.Stage.VALID:
          # Convert token indices to words
          predicted_words = self.tokenizer(
              p_tokens, task="decode_from_list"
          )
  
      elif stage == sb.Stage.TEST:
          predicted_words = [hyp[0].text.split(" ") for hyp in p_tokens]
  
      if stage != sb.Stage.TRAIN:
          # Convert indices to words
          target_words = undo_padding(tokens, tokens_lens)
          target_words = self.tokenizer(
              target_words, task="decode_from_list"
          )
  
          self.wer_metric.append(ids, predicted_words, target_words)
          self.cer_metric.append(ids, predicted_words, target_words)
  
      return loss
  
file_path: speechbrain/recipes/CommonVoice/ASR/CTC/train_with_wav2vec.py
imports: import sys
  import torch
  import logging
  import speechbrain
  import torchaudio
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.tokenizers.SentencePiece import SentencePiece
  from speechbrain.utils.data_utils import undo_padding
  from speechbrain.utils.distributed import run_on_main, if_main_process
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