Predictors
Module for LLM predictors.
base_predictor
Base module for predictors in the promptolution library.
BasePredictor
Bases: ABC
Abstract base class for predictors in the promptolution library.
This class defines the interface that all concrete predictor implementations should follow.
Attributes:
Name | Type | Description |
---|---|---|
llm |
The language model used for generating predictions. |
|
classes |
List[str]
|
The list of valid class labels. |
config |
ExperimentConfig
|
Experiment configuration overwriting defaults |
Source code in promptolution/predictors/base_predictor.py
__init__(llm, config=None)
Initialize the predictor with a language model and configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
BaseLLM
|
Language model to use for prediction. |
required |
config
|
ExperimentConfig
|
Configuration for the predictor. |
None
|
Source code in promptolution/predictors/base_predictor.py
predict(prompts, xs, system_prompts=None, return_seq=False)
Abstract method to make predictions based on prompts and input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[str]
|
Prompt or list of prompts to use for prediction. |
required |
xs
|
ndarray
|
Array of input data. |
required |
system_prompts
|
List[str]
|
List of system prompts to use for the language model. |
None
|
return_seq
|
bool
|
Whether to return the generating sequence. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
Array of predictions, optionally with sequences. |
Source code in promptolution/predictors/base_predictor.py
classifier
Module for classification predictors.
FirstOccurrenceClassifier
Bases: BasePredictor
A predictor class for classification tasks using language models.
This class takes a language model and a list of classes, and provides a method to predict classes for given prompts and input data. The class labels are extracted by matching the words in the prediction with the list of valid class labels. The first occurrence of a valid class label in the prediction is used as the predicted class. If no valid class label is found, the first class label in the list is used as the default prediction.
Attributes:
Name | Type | Description |
---|---|---|
llm |
The language model used for generating predictions. |
|
classes |
List[str]
|
The list of valid class labels. |
config |
ExperimentConfig
|
Configuration for the classifier, overriding defaults. |
Inherits from
BasePredictor: The base class for predictors in the promptolution library.
Source code in promptolution/predictors/classifier.py
__init__(llm, classes, config=None)
Initialize the FirstOccurrenceClassifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
The language model to use for predictions. |
required | |
classes
|
List[str]
|
The list of valid class labels. |
required |
config
|
ExperimentConfig
|
Configuration for the classifier, overriding defaults. |
None
|
Source code in promptolution/predictors/classifier.py
MarkerBasedClassifier
Bases: BasePredictor
A predictor class for classification tasks using language models.
This class takes a language model and a list of classes, and provides a method to predict classes for given prompts and input data. The class labels are extracted.
Attributes:
Name | Type | Description |
---|---|---|
llm |
The language model used for generating predictions. |
|
classes |
List[str]
|
The list of valid class labels. |
marker |
str
|
The marker to use for extracting the class label. |
Inherits from
BasePredictor: The base class for predictors in the promptolution library.
Source code in promptolution/predictors/classifier.py
__init__(llm, classes=None, begin_marker='<final_answer>', end_marker='</final_answer>', config=None)
Initialize the MarkerBasedClassifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
The language model to use for predictions. |
required | |
classes
|
List[str]
|
The list of valid class labels. If None, does not force any class. |
None
|
begin_marker
|
str
|
The marker to use for extracting the class label. |
'<final_answer>'
|
end_marker
|
str
|
The marker to use for extracting the class label. |
'</final_answer>'
|
config
|
ExperimentConfig
|
Configuration for the classifier, overriding defaults. |
None
|