class_docstr: Base class for LLM models
  
  This class handles a few of the checks, as well as the whole prediction
  machinery.
  
  Required attributes are:
  
  - model_name
  - model
  - tokenizer
  - prompt
  - probas_sum_to_1
  - device
  - error_low_prob
  - threshold_low_prob
  - use_caching
class_docstr_tok: ["Base","class","for","LLM","models","This","class","handles","a","few","of","the","checks",",","as","well","as","the","whole","prediction","machinery",".","Required","attributes","are",":","-","model_name","-","model","-","tokenizer","-","prompt","-","probas_sum_to_1","-","device","-","error_low_prob","-","threshold_low_prob","-","use_caching"]
docstr: Make a prediction for a single sample
  
  The returned probabilites are *not normalized* yet.
  
  Raises a ``LowProbabilityError`` if the total probability of all labels
  is 0, or, assuming ``error_low_prob`` is ``'raise'``, when it is below
  ``threshold_low_prob``. This check is done here because we want to raise
  eagerly instead of going through all samples and then raise.
docstr_tok: ["Make","a","prediction","for","a","single","sample","The","returned","probabilites","are","*","not","normalized","*","yet",".","Raises","a","``","LowProbabilityError","``","if","the","total","probability","of","all","labels","is","0",",","or",",","assuming","``","error_low_prob","``","is","``","'raise","'","``",",","when","it","is","below","``","threshold_low_prob","``",".","This","check","is","done","here","because","we","want","to","raise","eagerly","instead","of","going","through","all","samples","and","then","raise","."]
code: def _predict_one(self, text):
      """Make a prediction for a single sample
  
      The returned probabilites are *not normalized* yet.
  
      Raises a ``LowProbabilityError`` if the total probability of all labels
      is 0, or, assuming ``error_low_prob`` is ``'raise'``, when it is below
      ``threshold_low_prob``. This check is done here because we want to raise
      eagerly instead of going through all samples and then raise.
  
      """
      inputs = self.tokenizer_(text, return_tensors="pt").to(
          self.device_
      )
  
      probas_all_labels = []
      for label_id in self.label_ids_:
          logits = self.cached_model_.generate_logits(
              label_id=label_id, **inputs
          )
          logits = torch.vstack(logits)
          probas = torch.nn.functional.softmax(logits, dim=-1)
  
          # in case we deal with BFloats which are not supported on CPU
          probas = probas.to(torch.float)
  
          n = len(logits)
          label_id = label_id[:n]  # don't need EOS, PAD, etc.
          probas_at_idx = probas[torch.arange(n), label_id]
          # multiplying the probabilities for token A, B, C, ... This is
          # because we are interested in P(A) AND P(B|A) AND P(C|A,B), etc.
          # p(A) * P(B|A) =
          # p(A) * p(AnB) / p(A) =
          # p(A) * p(A) * p(B) / p(A) =
          # p(A) * p(B)
          # thus the product of individual probalities is correct
          probas_all_labels.append(torch.prod(probas_at_idx).item())
  
      prob_sum = sum(probas_all_labels)
      if prob_sum == 0.0:
          raise LowProbabilityError(
              "The sum of all probabilities is zero."
          )
  
      probs_are_low = prob_sum < self.threshold_low_prob
      if probs_are_low and (self.error_low_prob == "raise"):
          raise LowProbabilityError(
              f"The sum of all probabilities is {prob_sum:.3f}, "
              f"which is below the minimum threshold of {self.threshold_low_prob:.3f}"
          )
  
      y_prob = np.array(probas_all_labels).astype(np.float64)
      return y_prob
  
imports: import importlib
  import warnings
  from string import Formatter
  import numpy
  import torch
  from sklearn.base import BaseEstimator, ClassifierMixin
  from sklearn.utils import check_random_state
  from sklearn.utils.validation import check_is_fitted
  from transformers import AutoConfig, AutoTokenizer, LogitsProcessor
  from skorch.exceptions import LowProbabilityError
  from skorch.llm.prompts import DEFAULT_PROMPT_FEW_SHOT, DEFAULT_PROMPT_ZERO_SHOT, DELIM
label_desc: Use image node_id 11 for calling the _LlmBase obj's underlying member method code with example usage: obj._predict_one(text) and returns: y_prob