docstr: Given the network predictions and targets computed the NLL loss.
docstr_tok: ["Given","the","network","predictions","and","targets","computed","the","NLL","loss","."]
code: def compute_objectives(self, predictions, batch, stage):
      "Given the network predictions and targets computed the NLL loss."
      p_ctc, p_seq, wav_lens, hyps = predictions
  
      ids = batch.id
      phns_eos, phn_lens_eos = batch.phn_encoded_eos
      phns, phn_lens = batch.phn_encoded
  
      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_eos = self.hparams.wav_augment.replicate_labels(phns_eos)
          phn_lens_eos = self.hparams.wav_augment.replicate_labels(
              phn_lens_eos
          )
  
      loss_ctc = self.hparams.ctc_cost(p_ctc, phns, wav_lens, phn_lens)
      loss_seq = self.hparams.seq_cost(p_seq, phns_eos, phn_lens_eos)
      loss = self.hparams.ctc_weight * loss_ctc
      loss += (1 - self.hparams.ctc_weight) * loss_seq
  
      # Record losses for posterity
      if stage != sb.Stage.TRAIN:
          self.ctc_metrics.append(ids, p_ctc, phns, wav_lens, phn_lens)
          self.seq_metrics.append(ids, p_seq, phns_eos, phn_lens_eos)
          self.per_metrics.append(
              ids,
              hyps,
              phns,
              None,
              phn_lens,
              self.label_encoder.decode_ndim,
          )
  
      return loss
  
file_path: speechbrain/recipes/TIMIT/ASR/seq2seq/train_with_wav2vec2.py
imports: import os
  import sys
  import torch
  import logging
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main, if_main_process
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