docstr: Computes the loss with the specified alignment algorithm
docstr_tok: ["Computes","the","loss","with","the","specified","alignment","algorithm"]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss with the specified alignment algorithm"""
      pout, pout_lens = predictions
      ids = batch.id
      phns, phn_lens = batch.phn_encoded
      phn_ends, _ = batch.phn_ends
  
      if stage == sb.Stage.TRAIN and hasattr(
          self.hparams, "wav_augment"
      ):
          phns = self.hparams.wav_augment.replicate_labels(phns)
          phn_lens = self.hparams.wav_augment.replicate_labels(phn_lens)
  
      phns, phn_lens = phns.to(self.device), phn_lens.to(self.device)
      phns_orig = sb.utils.data_utils.undo_padding(phns, phn_lens)
      phns = self.hparams.aligner.expand_phns_by_states_per_phoneme(
          phns, phn_lens
      )
  
      phns = phns.int()
  
      if self.training_type == "forward":
          forward_scores = self.hparams.aligner(
              pout, pout_lens, phns, phn_lens, "forward"
          )
          loss = -forward_scores
  
      elif self.training_type == "ctc":
          loss = self.hparams.compute_cost_ctc(
              pout, phns, pout_lens, phn_lens
          )
      elif self.training_type == "viterbi":
          prev_alignments = self.hparams.aligner.get_prev_alignments(
              ids, pout, pout_lens, phns, phn_lens
          )
          prev_alignments = prev_alignments.to(self.hparams.device)
          loss = self.hparams.compute_cost_nll(pout, prev_alignments)
  
      viterbi_scores, alignments = self.hparams.aligner(
          pout, pout_lens, phns, phn_lens, "viterbi"
      )
  
      if self.training_type in ["viterbi", "forward"]:
          self.hparams.aligner.store_alignments(ids, alignments)
  
      if stage != sb.Stage.TRAIN:
          self.accuracy_metrics.append(
              ids, alignments, phn_ends, phns_orig
          )
  
      return loss
  
file_path: speechbrain/recipes/TIMIT/Alignment/train.py
imports: import os
  import sys
  import torch
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 2 for calling the AlignBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss