docstr: Computes the loss (Transducer+(CTC+NLL)) given predictions and targets.
docstr_tok: ["Computes","the","loss","(","Transducer+","(","CTC+NLL",")",")","given","predictions","and","targets","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss (Transducer+(CTC+NLL)) given predictions and targets."""
  
      ids = batch.id
      phn, phn_lens = batch.phn_encoded
      phn_with_eos, phn_with_eos_lens = batch.phn_encoded_eos
  
      # Train returns 4 elements vs 3 for val and test
      if len(predictions) == 4:
          p_ctc, p_ce, logits_transducer, wav_lens = predictions
      else:
          logits_transducer, wav_lens, predicted_phn = predictions
  
      if stage == sb.Stage.TRAIN:
          if hasattr(self.hparams, "wav_augment"):
              phn = self.hparams.wav_augment.replicate_labels(phn)
              phn_lens = self.hparams.wav_augment.replicate_labels(
                  phn_lens
              )
              phn_with_eos = self.hparams.wav_augment.replicate_labels(
                  phn_with_eos
              )
              phn_with_eos_lens = (
                  self.hparams.wav_augment.replicate_labels(
                      phn_with_eos_lens
                  )
              )
          if hasattr(self.hparams, "fea_augment"):
              phn = self.hparams.fea_augment.replicate_labels(phn)
              phn_lens = self.hparams.fea_augment.replicate_labels(
                  phn_lens
              )
              phn_with_eos = self.hparams.fea_augment.replicate_labels(
                  phn_with_eos
              )
              phn_with_eos_lens = (
                  self.hparams.fea_augment.replicate_labels(
                      phn_with_eos_lens
                  )
              )
  
      if stage == sb.Stage.TRAIN:
          CTC_loss = 0.0
          CE_loss = 0.0
          if p_ctc is not None:
              CTC_loss = self.hparams.ctc_cost(
                  p_ctc, phn, wav_lens, phn_lens
              )
          if p_ce is not None:
              CE_loss = self.hparams.ce_cost(
                  p_ce, phn_with_eos, length=phn_with_eos_lens
              )
          loss_transducer = self.hparams.transducer_cost(
              logits_transducer, phn, wav_lens, phn_lens
          )
          loss = (
              self.hparams.ctc_weight * CTC_loss
              + self.hparams.ce_weight * CE_loss
              + (1 - (self.hparams.ctc_weight + self.hparams.ce_weight))
              * loss_transducer
          )
      else:
          loss = self.hparams.transducer_cost(
              logits_transducer, phn, wav_lens, phn_lens
          )
  
      if stage != sb.Stage.TRAIN:
          self.per_metrics.append(
              ids, predicted_phn, phn, target_len=phn_lens
          )
  
      return loss
  
file_path: speechbrain/tests/integration/ASR_ConformerTransducer_streaming/example_asr_conformertransducer_streaming_experiment.py
imports: import pathlib
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  import torch
label_desc: Use image node_id 2 for calling the ConformerTransducerBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss