docstr: Computes the loss given the predicted and targeted outputs.
  
  Arguments
  ---------
  predictions : torch.Tensor
      The posterior probabilities from `compute_forward`.
  batch : PaddedBatch
      This batch object contains all the relevant tensors for computation.
  stage : sb.Stage
      One of sb.Stage.TRAIN, sb.Stage.VALID, or sb.Stage.TEST.
  
  Returns
  -------
  loss : torch.Tensor
      A one-element tensor used for backpropagating the gradient.
docstr_tok: ["Computes","the","loss","given","the","predicted","and","targeted","outputs",".","Arguments","--","--","--","--","-","predictions",":","torch.Tensor","The","posterior","probabilities","from","`","compute_forward","`",".","batch",":","PaddedBatch","This","batch","object","contains","all","the","relevant","tensors","for","computation",".","stage",":","sb.Stage","One","of","sb.Stage.TRAIN",",","sb.Stage.VALID",",","or","sb.Stage.TEST",".","Returns","--","--","--","-","loss",":","torch.Tensor","A","one-element","tensor","used","for","backpropagating","the","gradient","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss given the predicted and targeted outputs.
  
      Arguments
      ---------
      predictions : torch.Tensor
          The posterior probabilities from `compute_forward`.
      batch : PaddedBatch
          This batch object contains all the relevant tensors for computation.
      stage : sb.Stage
          One of sb.Stage.TRAIN, sb.Stage.VALID, or sb.Stage.TEST.
  
      Returns
      -------
      loss : torch.Tensor
          A one-element tensor used for backpropagating the gradient.
      """
      batch = batch.to(self.device)
      tokens_eos, tokens_len = batch.phn_encoded_eos
      loss = self.hparams.compute_cost(
          predictions, tokens_eos, length=tokens_len
      )
      return loss
  
file_path: speechbrain/recipes/LibriSpeech/G2P/train_lm.py
imports: import sys
  import logging
  import os
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main
  from train import dataio_prep
label_desc: Use image node_id 2 for calling the LM obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss