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__(config=None)
evaluate(prompts, predictor, system_prompts=None)
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 | |
system_prompts
|
List[str]
|
List of system prompts to evaluate. |
None
|
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
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.
Source code in promptolution/tasks/classification_tasks.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
__init__(df, description=None, x_column='x', y_column='y', n_subsamples=30, eval_strategy='full', seed=42, metric=accuracy_score, config=None)
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 |
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'
|
n_subsamples
|
int
|
Number of subsamples to use. No subsampling if None. Defaults to None. |
30
|
eval_strategy
|
str
|
Subsampling strategy to use. Options: - "full": Uses the entire dataset for evaluation. - "evaluated": Uses only previously evaluated datapoints from the cache. - "subsample": Randomly selects n_subsamples datapoints without replacement. - "sequential_block": Uses a block of block_size consecutive datapoints, advancing through blocks sequentially. - "random_block": Randomly selects a block of block_size consecutive datapoints. Defaults to "full". |
'full'
|
seed
|
int
|
Random seed for reproducibility. Defaults to 42. |
42
|
metric
|
Callable
|
Metric to use for evaluation. Defaults to accuracy_score. |
accuracy_score
|
config
|
ExperimentConfig
|
Configuration for the task, overriding defaults. |
None
|
Source code in promptolution/tasks/classification_tasks.py
evaluate(prompts, predictor, system_prompts=None, return_agg_scores=True, return_seq=False, eval_strategy=None)
Evaluate a set of prompts using a given predictor.
This method orchestrates subsampling, prediction, caching, and result collection.
Source code in promptolution/tasks/classification_tasks.py
increment_block_idx()
Increment the block index for subsampling.
Raises:
Type | Description |
---|---|
ValueError
|
If the eval_strategy does not contain "block". |
Source code in promptolution/tasks/classification_tasks.py
pop_datapoints(n=None, frac=None)
Pop a number of datapoints from the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of datapoints to pop. Defaults to None. |
None
|
frac
|
float
|
Fraction of datapoints to pop. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: DataFrame containing the popped datapoints. |
Source code in promptolution/tasks/classification_tasks.py
reset_block_idx()
Reset the block index for subsampling.
Raises:
Type | Description |
---|---|
ValueError
|
If the eval_strategy does not contain "block". |
Source code in promptolution/tasks/classification_tasks.py
subsample(eval_strategy=None)
Subsample the dataset based on the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy
|
str
|
Subsampling strategy to use instead of self.subsample_strategy. Defaults to None. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Subsampled input data and labels. |