docstr: Given examples and logits for those examples,
  compute the classification loss for each example
docstr_tok: ["Given","examples","and","logits","for","those","examples",",","compute","the","classification","loss","for","each","example"]
code: def _total_logprobs_from_logits(
      self, examples, logits
  ) -> list[float]:
      """Given examples and logits for those examples,
      compute the classification loss for each example"""
      total_logprobs = []
      for i, example in enumerate(examples):
          example_logits = logits[i]
          # NOTE: we take the last element of the returned token list
          # this is because the tokenizer returns a 1-element list for GPT tokenizers
          # and a 2-element list with start token in the first position for
          # OPT tokenizers
          class_tokens = [
              token[-1]
              for token in self.tokenizer(list(example.classes))[
                  "input_ids"
              ]
          ]
          # log_softmax just subtracts a constant, so repeated applications change nothing
          # and there is no point in taking logprobs before focusing on the
          # relevant indices
          example_logprobs = F.log_softmax(example_logits, dim=-1)
          relevant_logprobs = example_logprobs[class_tokens]
          total_logprobs.append(
              torch.logsumexp(relevant_logprobs, dim=-1).item()
          )
      return total_logprobs
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from typing import Union, cast, Sequence
  from typing_extensions import Literal, get_args
  import numpy
  import torch
  import torch.nn.functional
  from transformers import AutoModelForCausalLM, AutoTokenizer
  from accelerate import Accelerator
  from .isp_dataset import ClassificationExample, Example, ExampleWithClasses, LogoddsExample, SequenceProbExample, NumericExample, TaskType
  from .isp_utils import BasicParser
  from .isp_utils import OpenAIModel, OpenaAIModelList
label_desc: Use image node_id 12 for calling the HFModel obj's underlying member method code with example usage: obj._total_logprobs_from_logits(examples, logits) and returns: total_logprobs