class_docstr: Zero-shot classification using a Large Language Model (LLM).
  
  This class allows you to use an LLM from Hugging Face transformers for
  zero-shot classification. There is no training during the ``fit`` call,
  instead, the LLM will be prompted to predict the labels for each sample.
  
  Parameters
  ----------
  model_name : str or None (default=None)
    The name of the model to use. This is the same name as used on Hugging
    Face Hub. For example, to use GPT2, pass ``'gpt2'``, to use the small
    flan-t5 model, pass ``'google/flan-t5-small'``. If the ``model_name``
    parameter is passed, don't pass ``model`` or ``tokenizer`` parameters.
  
  model : torch.nn.Module or None (default=None)
    The model to use. This should be a PyTorch text generation model from
    Hugging Face Hub or a model with the same API. Most notably, the model
    should have a ``generate`` method. If you pass the ``model``, you should
    also pass the ``tokenizer``, but you shall not pass the ``model_name``.
  
    Passing the model explicitly instead of the ``model_name`` can have a few
    advantages. Most notably, this allows you to modify the model, e.g.
    changing its config or how the model is loaded. For instance, some models
    can only be loaded with the option ``trust_remote_code=True``. If using
    the ``model_name`` argument, the default settings will be used instead.
    Passing the model explicitly also allows you to use custom models that are
    not uploaded to Hugging Face Hub.
  
  tokenizer (default=None)
    A tokenizer that is compatible with the model. Typically, this is loaded
    using the ``AutoTokenizer.from_pretrained`` method provided by Hugging
    Face transformers. If you pass the ``tokenizer``, you should also pass the
    ``model``, but you should not pass the ``model_name``.
  
  prompt : str or None (default=None)
  
    The prompt to use. This is the text that will be passed to the model to
    generate the prediction. If no prompt is passed, a default prompt will be
    used. The prompt should be a Python string with two placeholders, one
    called ``text`` and one called ``labels``. The ``text`` placeholder will
    replaced by the contents from ``X`` and the ``labels`` placeholder will be
    replaced by the unique labels taken from ``y``.
  
    An example prompt could be something like this:
  
        "Classify this text: {text}. Possible labels are {labels}". Your
        response: "
  
    All general tips for good prompt crafting apply here as well. Be aware
    that if the prompt is too long, it will exceed the context size of the
    model.
  
  probas_sum_to_1 : bool (default=True)
    If ``True``, then the probabilities for each sample will be normalized to
    sum to 1. If ``False``, the probabilities will not be normalized.
  
    In general, without normalization, the probabilities will not sum to 1
    because the LLM can generate any token, not just the labels. Since the
    model is restricted to only generate the available labels, there will be
    some probability mass that is unaccounted for. You could consider the
    missing probability mass to be an implicit 'other' class.
  
    In general, you should set this parameter to ``True`` because the default
    assumption is that probabilities sum to 1. However, setting this to
    ``False`` can be useful for debugging purposes, as it allows you to see
    how much probability the LLM assigns to different tokens. If the total
    probabilities are very low, it could be a sign that the LLM is not
    powerful enough or that the prompt is not well crafted.
  
  device : str or torch.device (default='cpu')
    The device to use. In general, using a GPU or other accelerated hardware
    is advised if runtime performance is critical.
  
    Note that if the ``model`` parameter is passed explicitly, the device of
    that model takes precedence over the value of ``device``.
  
  error_low_prob : {'ignore', 'warn', 'raise', 'return_none'} (default='ignore')
    Controls what should happen if the sum of the probabilities for a sample
    is below a given threshold. When encountering low probabilities, the
    options are to do one of the following:
  
      - ``'ignore'``: do nothing
      - ``'warn'``: issue a warning
      - ``'raise'``: raise an error
      - ``'return_none'``: return ``None`` as the prediction when calling
        ``.predict``
  
    The threshold is controlled by the ``threshold_low_prob`` parameter.
  
  threshold_low_prob : float (default=0.0)
    The threshold for the sum of the probabilities below which they are
    considered to be too low. The consequences of low probabilities are
    controlled by the ``error_low_prob`` parameter.
  
  use_caching : bool (default=True)
    If ``True``, the predictions for each sample will be cached, as well as
    the intermediate result for each generated token. This can speed up
    predictions when some samples are duplicated, or when labels have a long
    common prefix. An example of the latter would be if a label is called
    "intent.support.email" and another label is called "intent.support.phone",
    then the tokens for the common prefix "intent.support." are reused for
    both labels, as their probabilities are identical.
  
    Note that caching is currently not supported for encoder-decoder
    architectures such as flan-t5. If you want to use such an architecture,
    turn caching off.
  
    If you see any issues you might suspect are caused by caching, turn this
    option off, see if it helps, and report the issue on the skorch GitHub
    page.
  
  Attributes
  ----------
  classes_ : ndarray of shape (n_classes, )
    A list of class labels known to the classifier. This attribute can be used
    to identify which column in the probabilties returned by ``predict_proba``
    corresponds to which class.
class_docstr_tok: ["Zero-shot","classification","using","a","Large","Language","Model","(","LLM",")",".","This","class","allows","you","to","use","an","LLM","from","Hugging","Face","transformers","for","zero-shot","classification",".","There","is","no","training","during","the","``","fit","``","call",",","instead",",","the","LLM","will","be","prompted","to","predict","the","labels","for","each","sample",".","Parameters","--","--","--","--","--","model_name",":","str","or","None","(","default=None",")","The","name","of","the","model","to","use",".","This","is","the","same","name","as","used","on","Hugging","Face","Hub",".","For","example",",","to","use","GPT2",",","pass","``","'gpt2","'","``",",","to","use","the","small","flan-t5","model",",","pass","``","'google\/flan-t5-small","'","``",".","If","the","``","model_name","``","parameter","is","passed",",","do","n't","pass","``","model","``","or","``","tokenizer","``","parameters",".","model",":","torch.nn.Module","or","None","(","default=None",")","The","model","to","use",".","This","should","be","a","PyTorch","text","generation","model","from","Hugging","Face","Hub","or","a","model","with","the","same","API",".","Most","notably",",","the","model","should","have","a","``","generate","``","method",".","If","you","pass","the","``","model","``",",","you","should","also","pass","the","``","tokenizer","``",",","but","you","shall","not","pass","the","``","model_name","``",".","Passing","the","model","explicitly","instead","of","the","``","model_name","``","can","have","a","few","advantages",".","Most","notably",",","this","allows","you","to","modify","the","model",",","e.g",".","changing","its","config","or","how","the","model","is","loaded",".","For","instance",",","some","models","can","only","be","loaded","with","the","option","``","trust_remote_code=True","``",".","If","using","the","``","model_name","``","argument",",","the","default","settings","will","be","used","instead",".","Passing","the","model","explicitly","also","allows","you","to","use","custom","models","that","are","not","uploaded","to","Hugging","Face","Hub",".","tokenizer","(","default=None",")","A","tokenizer","that","is","compatible","with","the","model",".","Typically",",","this","is","loaded","using","the","``","AutoTokenizer.from_pretrained","``","method","provided","by","Hugging","Face","transformers",".","If","you","pass","the","``","tokenizer","``",",","you","should","also","pass","the","``","model","``",",","but","you","should","not","pass","the","``","model_name","``",".","prompt",":","str","or","None","(","default=None",")","The","prompt","to","use",".","This","is","the","text","that","will","be","passed","to","the","model","to","generate","the","prediction",".","If","no","prompt","is","passed",",","a","default","prompt","will","be","used",".","The","prompt","should","be","a","Python","string","with","two","placeholders",",","one","called","``","text","``","and","one","called","``","labels","``",".","The","``","text","``","placeholder","will","replaced","by","the","contents","from","``","X","``","and","the","``","labels","``","placeholder","will","be","replaced","by","the","unique","labels","taken","from","``","y","``",".","An","example","prompt","could","be","something","like","this",":","``","Classify","this","text",":","{","text","}",".","Possible","labels","are","{","labels","}","''",".","Your","response",":","``","All","general","tips","for","good","prompt","crafting","apply","here","as","well",".","Be","aware","that","if","the","prompt","is","too","long",",","it","will","exceed","the","context","size","of","the","model",".","probas_sum_to_1",":","bool","(","default=True",")","If","``","True","``",",","then","the","probabilities","for","each","sample","will","be","normalized","to","sum","to","1",".","If","``","False","``",",","the","probabilities","will","not","be","normalized",".","In","general",",","without","normalization",",","the","probabilities","will","not","sum","to","1","because","the","LLM","can","generate","any","token",",","not","just","the","labels",".","Since","the","model","is","restricted","to","only","generate","the","available","labels",",","there","will","be","some","probability","mass","that","is","unaccounted","for",".","You","could","consider","the","missing","probability","mass","to","be","an","implicit","'other","'","class",".","In","general",",","you","should","set","this","parameter","to","``","True","``","because","the","default","assumption","is","that","probabilities","sum","to","1",".","However",",","setting","this","to","``","False","``","can","be","useful","for","debugging","purposes",",","as","it","allows","you","to","see","how","much","probability","the","LLM","assigns","to","different","tokens",".","If","the","total","probabilities","are","very","low",",","it","could","be","a","sign","that","the","LLM","is","not","powerful","enough","or","that","the","prompt","is","not","well","crafted",".","device",":","str","or","torch.device","(","default='cpu","'",")","The","device","to","use",".","In","general",",","using","a","GPU","or","other","accelerated","hardware","is","advised","if","runtime","performance","is","critical",".","Note","that","if","the","``","model","``","parameter","is","passed","explicitly",",","the","device","of","that","model","takes","precedence","over","the","value","of","``","device","``",".","error_low_prob",":","{","'ignore","'",",","'warn","'",",","'raise","'",",","'return_none","'","}","(","default='ignore","'",")","Controls","what","should","happen","if","the","sum","of","the","probabilities","for","a","sample","is","below","a","given","threshold",".","When","encountering","low","probabilities",",","the","options","are","to","do","one","of","the","following",":","-","``","'ignore","'","``",":","do","nothing","-","``","'warn","'","``",":","issue","a","warning","-","``","'raise","'","``",":","raise","an","error","-","``","'return_none","'","``",":","return","``","None","``","as","the","prediction","when","calling","``",".predict","``","The","threshold","is","controlled","by","the","``","threshold_low_prob","``","parameter",".","threshold_low_prob",":","float","(","default=0.0",")","The","threshold","for","the","sum","of","the","probabilities","below","which","they","are","considered","to","be","too","low",".","The","consequences","of","low","probabilities","are","controlled","by","the","``","error_low_prob","``","parameter",".","use_caching",":","bool","(","default=True",")","If","``","True","``",",","the","predictions","for","each","sample","will","be","cached",",","as","well","as","the","intermediate","result","for","each","generated","token",".","This","can","speed","up","predictions","when","some","samples","are","duplicated",",","or","when","labels","have","a","long","common","prefix",".","An","example","of","the","latter","would","be","if","a","label","is","called","``","intent.support.email","''","and","another","label","is","called","``","intent.support.phone","''",",","then","the","tokens","for","the","common","prefix","``","intent.support",".","''","are","reused","for","both","labels",",","as","their","probabilities","are","identical",".","Note","that","caching","is","currently","not","supported","for","encoder-decoder","architectures","such","as","flan-t5",".","If","you","want","to","use","such","an","architecture",",","turn","caching","off",".","If","you","see","any","issues","you","might","suspect","are","caused","by","caching",",","turn","this","option","off",",","see","if","it","helps",",","and","report","the","issue","on","the","skorch","GitHub","page",".","Attributes","--","--","--","--","--","classes_",":","ndarray","of","shape","(","n_classes",",",")","A","list","of","class","labels","known","to","the","classifier",".","This","attribute","can","be","used","to","identify","which","column","in","the","probabilties","returned","by","``","predict_proba","``","corresponds","to","which","class","."]
code: def __init__(
      self,
      model_name=None,
      *,
      model=None,
      tokenizer=None,
      prompt=None,
      probas_sum_to_1=True,
      device="cpu",
      error_low_prob="ignore",
      threshold_low_prob=0.0,
      use_caching=True,
  ):
      self.model_name = model_name
      self.model = model
      self.tokenizer = tokenizer
      self.prompt = prompt
      self.probas_sum_to_1 = probas_sum_to_1
      self.device = device
      self.error_low_prob = error_low_prob
      self.threshold_low_prob = threshold_low_prob
      self.use_caching = use_caching
  
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 1 to create a new ZeroShotClassifier object from inherited base classes: _LlmBase with example: obj = ZeroShotClassifier(model_name)