docstr: Computes the NLL-loss using reply as label.
          
docstr_tok: ["Computes","the","NLL-loss","using","reply","as","label","."]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the NLL-loss using reply as label."""
      # Get required data from batch
      batch = batch.to(self.device)
      ids = batch.id
      lm_labels, _ = batch.lm_labels
      prompt_bos, _ = batch.prompt_bos
      reply_eos, reply_lens = batch.reply_eos
  
      loss = self.hparams.ce_loss(
          predictions.flatten(end_dim=-2), lm_labels.flatten()
      )
  
      if stage == sb.Stage.VALID:
          padding_mask = ~self.hparams.padding_mask(
              prompt_bos, pad_idx=tokenizer.pad_token_id
          )
          hyps = self.modules.llama2_model.generate(
              prompt_bos.detach(),
              padding_mask.detach(),
          )
      elif stage == sb.Stage.TEST:
          padding_mask = ~self.hparams.padding_mask(
              prompt_bos, pad_idx=tokenizer.pad_token_id
          )
          hyps = self.modules.llama2_model.generate(
              prompt_bos.detach(),
              padding_mask.detach(),
              "beam",
          )
  
      if stage != sb.Stage.TRAIN:
          reply_truncated = [
              reply_eos[i][
                  : int(reply_lens[i].item() * reply_eos.shape[1] - 1)
              ].detach()
              for i in range(reply_eos.shape[0])
          ]
          predicted_words = tokenizer.batch_decode(
              hyps[:, prompt_bos.shape[1] :],
              skip_special_tokens=True,
              clean_up_tokenization_spaces=True,
          )
          target_words = tokenizer.batch_decode(
              reply_truncated,
              skip_special_tokens=True,
              clean_up_tokenization_spaces=True,
          )
          self.bleu_4_metric.append(ids, predicted_words, target_words)
          self.bleu_2_metric.append(ids, predicted_words, target_words)
          if stage != sb.Stage.TRAIN:
              self.hyps.extend(predicted_words)
              self.references.extend(target_words)
  
      return loss
  
file_path: speechbrain/recipes/MultiWOZ/response_generation/llama2/train_with_llama2.py
imports: import sys
  import speechbrain
  import torch
  from itertools import chain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main
  import math
  from speechbrain.dataio.batch import PaddedBatch
label_desc: Use image node_id 2 for calling the ResGenBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss