docstr: Expects a dataset instance where returned items have the following attributes:
  - prompt: The prompt to evaluate on.
  - classes: A list of strings, each string is a class.
  - answer_index: The index of the correct class.
  
  n_debug: Number of examples to evaluate on for debugging purposes.
docstr_tok: ["Expects","a","dataset","instance","where","returned","items","have","the","following","attributes",":","-","prompt",":","The","prompt","to","evaluate","on",".","-","classes",":","A","list","of","strings",",","each","string","is","a","class",".","-","answer_index",":","The","index","of","the","correct","class",".","n_debug",":","Number","of","examples","to","evaluate","on","for","debugging","purposes","."]
code: def eval_classification(self, dataset, n_debug=None):
      """
      Expects a dataset instance where returned items have the following attributes:
      - prompt: The prompt to evaluate on.
      - classes: A list of strings, each string is a class.
      - answer_index: The index of the correct class.
  
      n_debug: Number of examples to evaluate on for debugging purposes.
      """
  
      if n_debug is None:
          n_debug = len(dataset)
      examples = [item for item in dataset][:n_debug]
  
      prompts = [
          self.format_fn(example.prompt) + class_seq
          for example in examples
          for class_seq in example.classes
      ]
      target_token_lengths = [
          len(self.tokenizer(class_seq)["input_ids"])
          for example in examples
          for class_seq in example.classes
      ]
  
      _, ll = self.get_conditional_loglikelihood_batch(
          prompts, completion_offset=torch.tensor(target_token_lengths)
      )
      pred_logprobs = ll.reshape((len(examples), -1))
      total_logprob = logsumexp(pred_logprobs, axis=1)
      normalised_logprobs = log_softmax(pred_logprobs, axis=1)
      pred_classes = np.argmax(pred_logprobs, axis=1)
      labels = np.array([e.answer_index for e in examples])
      losses = -normalised_logprobs[np.arange(labels.shape[0]), labels]
      metrics = {
          "Accuracy": (pred_classes == labels),
          "Loss": losses,
          "TotalProbSpanned": total_logprob,
      }
      return metrics
  
file_path: interpret-text/python/interpret_text/generative/model_lib/hf_tooling.py
imports: import torch
  import numpy
  from tqdm import tqdm
  import torch.nn.functional
  from scipy.special import log_softmax, logsumexp
label_desc: Use image node_id 8 for calling the HF_LM obj's underlying member method code with example usage: obj.eval_classification(dataset, n_debug) and returns: metrics