docstr: Computes the loss given predictions and targets.
docstr_tok: ["Computes","the","loss","given","predictions","and","targets","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss given predictions and targets."""
      (p_seq, wav_lens, hyps) = predictions
      ids = batch.id
      tokens_eos, tokens_eos_lens = batch.tokens_eos
  
      # st loss
      loss = self.hparams.seq_cost(
          p_seq, tokens_eos, length=tokens_eos_lens
      )
  
      fr_detokenizer = MosesDetokenizer(lang=self.hparams.lang)
  
      if stage != sb.Stage.TRAIN:
          predictions = [
              fr_detokenizer.detokenize(
                  tokenizer.sp.decode_ids(utt_seq).split(" ")
              )
              for utt_seq in hyps
          ]
  
          detokenized_translation = [
              fr_detokenizer.detokenize(translation.split(" "))
              for translation in batch.trans
          ]
          # it needs to be a list of list due to the extend on the bleu implementation
          targets = [detokenized_translation]
  
          self.bleu_metric.append(ids, predictions, targets)
  
          # compute the accuracy of the one-step-forward prediction
          self.acc_metric.append(p_seq, tokens_eos, tokens_eos_lens)
  
      return loss
  
file_path: speechbrain/recipes/IWSLT22_lowresource/AST/transformer/train.py
imports: import sys
  import torch
  import logging
  import speechbrain
  from speechbrain.tokenizers.SentencePiece import SentencePiece
  from speechbrain.utils.distributed import run_on_main
  from hyperpyyaml import load_hyperpyyaml
  from sacremoses import MosesDetokenizer
label_desc: Use image node_id 2 for calling the ST obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss