docstr: Computes the CTC loss given predictions and targets.
docstr_tok: ["Computes","the","CTC","loss","given","predictions","and","targets","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the CTC loss given predictions and targets."""
      p_ctc, wav_lens = predictions
      ids = batch.id
      tokens, tokens_lens = batch.tokens
  
      if stage == sb.Stage.TRAIN:
          if hasattr(self.hparams, "fea_augment"):
              tokens = self.hparams.fea_augment.replicate_labels(tokens)
              tokens_lens = self.hparams.fea_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
          sequences = sb.decoders.ctc_greedy_decode(
              p_ctc, wav_lens, blank_id=self.hparams.blank_index
          )
          predicted_words_list = []
  
          for sequence in sequences:
              # Decode token terms to words
              predicted_tokens = self.tokenizer.convert_ids_to_tokens(
                  sequence
              )
  
              predicted_words = []
              for c in predicted_tokens:
                  if c == "[CLS]":
                      continue
                  elif c == "[SEP]" or c == "[PAD]":
                      break
                  else:
                      predicted_words.append(c)
  
              predicted_words_list.append(predicted_words)
  
      elif stage == sb.Stage.TEST:
          p_tokens = test_searcher(p_ctc, wav_lens)
          # select one-best
          text_hyps = [hyp[0].text for hyp in p_tokens]
  
          predicted_words_list = []
          preds = []
          for seq in text_hyps:
              seq = seq.replace("[CLS]", "")
              seq = seq.replace("[SEP]", "")
              seq = seq.replace("[PAD]", "")
              for c in seq:
                  preds.append(c)
              predicted_words_list.append(preds)
  
      if stage != sb.Stage.TRAIN:
          target_words_list = [list(wrd) for wrd in batch.wrd]
          self.cer_metric.append(
              ids=ids,
              predict=predicted_words_list,
              target=target_words_list,
          )
  
      return loss
  
file_path: speechbrain/recipes/AISHELL-1/ASR/CTC/train_with_wav2vec.py
imports: import sys
  import torch
  import logging
  import speechbrain
  from speechbrain.utils.distributed import run_on_main
  from hyperpyyaml import load_hyperpyyaml
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