original_docstring: Computes the loss with the specified alignment algorithm
docstring: Computes the loss with the specified alignment algorithm
docstring_tokens: 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.modules, "env_corrupt"):
              phns = torch.cat([phns, phns], dim=0)
              phn_lens = torch.cat([phn_lens, phn_lens], dim=0)
  
          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
code_tokens: def compute_objectives ( self , predictions , batch , stage ) : 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 . modules , "env_corrupt" ) : phns = torch . cat ( [ phns , phns ] , dim = 0 ) phn_lens = torch . cat ( [ phn_lens , phn_lens ] , dim = 0 ) 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
short_docstring: Computes the loss with the specified alignment algorithm
short_docstring_tokens: Computes the loss with the specified alignment algorithm
comment: """Computes the loss with the specified alignment algorithm"""