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 = predictions
  
      ids = batch.id
      tokens, tokens_lens = batch.tokens
  
      # Label Augmentation
      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:
          # Decode token terms to words
          sequence = sb.decoders.ctc_greedy_decode(
              p_ctc, wav_lens, blank_id=self.hparams.blank_index
          )
  
          predicted_words = self.tokenizer(
              sequence, task="decode_from_list"
          )
  
      elif stage == sb.Stage.TEST:
          # Decode token terms to words
          sequence = test_searcher(p_ctc, wav_lens)
          predicted_words = [hyp[0].text.split(" ") for hyp in sequence]
  
      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"
          )
  
          # Check for possible word alternatives and exclusions
          if stage == sb.Stage.TEST and self.normalize_fn is not None:
              target_words, predicted_words = self.normalize_fn(
                  target_words, predicted_words
              )
  
          self.wer_metric.append(ids, predicted_words, target_words)
          self.cer_metric.append(ids, predicted_words, target_words)
  
      return loss
  
imports: import functools
  import os
  import sys
  from pathlib import Path
  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 3 for calling the ASR obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss