Tasks
Module for task-related functions and classes.
base_task
Base module for tasks.
BaseTask
Bases: ABC
Abstract base class for tasks in the promptolution library.
This class defines the interface that all concrete task implementations should follow.
Methods:
Name | Description |
---|---|
evaluate |
An abstract method that should be implemented by subclasses to evaluate prompts using a given predictor. |
Source code in promptolution/tasks/base_task.py
__init__(*args, **kwargs)
evaluate(prompts, predictor)
abstractmethod
Abstract method to evaluate prompts using a given predictor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[str]
|
List of prompts to evaluate. |
required |
predictor
|
The predictor to use for evaluation. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of evaluation scores for each prompt. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not implemented by a subclass. |
Source code in promptolution/tasks/base_task.py
DummyTask
Bases: BaseTask
A dummy task implementation for testing purposes.
This task generates random evaluation scores for given prompts.
Attributes:
Name | Type | Description |
---|---|---|
initial_population |
List[str]
|
List of initial prompts. |
description |
str
|
Description of the dummy task. |
xs |
ndarray
|
Array of dummy input data. |
ys |
ndarray
|
Array of dummy labels. |
classes |
List[str]
|
List of possible class labels. |
Source code in promptolution/tasks/base_task.py
__init__()
Initialize the DummyTask.
Source code in promptolution/tasks/base_task.py
evaluate(prompts, predictor)
Generate random evaluation scores for the given prompts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[str]
|
List of prompts to evaluate. |
required |
predictor
|
The predictor to use for evaluation (ignored in this implementation). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of random evaluation scores, one for each prompt. |
Source code in promptolution/tasks/base_task.py
classification_tasks
Module for classification tasks.
ClassificationTask
Bases: BaseTask
A class representing a classification task in the promptolution library.
This class handles the loading and management of classification datasets, as well as the evaluation of predictors on these datasets.
Attributes:
Name | Type | Description |
---|---|---|
description |
str
|
Description of the task. |
classes |
List[str]
|
List of possible class labels. |
xs |
ndarray
|
Array of input data. |
ys |
ndarray
|
Array of labels. |
initial_prompts |
List[str]
|
Initial set of prompts to start optimization with. |
metric |
Callable
|
Metric to use for evaluation. |
Inherits from
BaseTask: The base class for tasks in the promptolution library.
Source code in promptolution/tasks/classification_tasks.py
__init__(df, description, initial_prompts=None, x_column='x', y_column='y', metric=accuracy_score)
Initialize the ClassificationTask from a pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing the data |
required |
description
|
str
|
Description of the task |
required |
initial_prompts
|
List[str]
|
Initial set of prompts to start optimization with. Defaults to None. |
None
|
x_column
|
str
|
Name of the column containing input texts. Defaults to "x". |
'x'
|
y_column
|
str
|
Name of the column containing labels. Defaults to "y". |
'y'
|
seed
|
int
|
Random seed for reproducibility. Defaults to 42. |
required |
metric
|
Callable
|
Metric to use for evaluation. Defaults to accuracy_score. |
accuracy_score
|
Source code in promptolution/tasks/classification_tasks.py
evaluate(prompts, predictor, n_samples=20, subsample=False, return_seq=False)
Evaluate a set of prompts using a given predictor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[str]
|
List of prompts to evaluate. |
required |
predictor
|
BasePredictor
|
Predictor to use for evaluation. |
required |
n_samples
|
int
|
Number of samples to use if subsampling. Defaults to 20. |
20
|
subsample
|
bool
|
Whether to use subsampling. |
False
|
return_seq
|
bool
|
whether to return the generating sequence |
False
|
subsample
|
bool
|
Whether to use subsampling. |
False
|
return_seq
|
bool
|
whether to return the generating sequence |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of accuracy scores for each prompt. |