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.
Source code in promptolution/tasks/base_task.py
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
__init__(df, x_column, y_column=None, task_description=None, n_subsamples=30, eval_strategy='full', seed=42, config=None)
Initialize the BaseTask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data. |
required |
x_column
|
str
|
Name of the column containing input texts. |
required |
y_column
|
Optional[str]
|
Name of the column containing labels/ground truth (if applicable). |
None
|
task_description
|
str
|
Description of the task. |
None
|
n_subsamples
|
int
|
Number of subsamples to use for evaluation. |
30
|
eval_strategy
|
Literal
|
Subsampling strategy ("full", "subsample", "sequential_block", "random_block", "evaluated"). |
'full'
|
seed
|
int
|
Random seed for reproducibility. |
42
|
config
|
ExperimentConfig
|
Configuration for the task, overriding defaults. |
None
|
Source code in promptolution/tasks/base_task.py
evaluate(prompts, predictor, system_prompts=None, return_agg_scores=True, return_seq=False, eval_strategy=None)
evaluate(prompts: List[str], predictor: BasePredictor, system_prompts: Optional[Union[str, List[str]]] = None, return_agg_scores: Literal[True] = True, return_seq: Literal[False] = False, eval_strategy: Optional[EvalStrategy] = None) -> List[float]
evaluate(prompts: List[str], predictor: BasePredictor, system_prompts: Optional[Union[str, List[str]]] = None, return_agg_scores: Literal[False] = False, return_seq: Literal[False] = False, eval_strategy: Optional[EvalStrategy] = None) -> List[List[float]]
evaluate(prompts: List[str], predictor: BasePredictor, system_prompts: Optional[Union[str, List[str]]] = None, return_agg_scores: Literal[False] = False, return_seq: Literal[True] = True, eval_strategy: Optional[EvalStrategy] = None) -> Tuple[List[List[float]], List[List[str]]]
evaluate(prompts: str, predictor: BasePredictor, system_prompts: Optional[Union[str, List[str]]] = None, return_agg_scores: Literal[True] = True, return_seq: Literal[False] = False, eval_strategy: Optional[EvalStrategy] = None) -> List[float]
Evaluate a set of prompts using a given predictor.
This method orchestrates subsampling, prediction, caching, and result collection.
Note: Cannot return both aggregated scores and sequences (assertion will fail).
Source code in promptolution/tasks/base_task.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/base_task.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/base_task.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/base_task.py
subsample(eval_strategy=None)
Subsample the dataset based on the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eval_strategy
|
EvalStrategy
|
Subsampling strategy to use instead of self.eval_strategy. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]]
|
Tuple[List[str], List[str]]: Subsampled input data and labels. |
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
__init__(df, task_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 |
task_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
judge_tasks
Module for judge tasks.
JudgeTask
Bases: BaseTask
Task that evaluates a predictor using an LLM as a judge, optionally accepting a ground truth.
Source code in promptolution/tasks/judge_tasks.py
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 |
|
__init__(df, judge_llm, x_column='x', y_column=None, task_description=None, n_subsamples=30, eval_strategy='full', seed=42, judge_prompt=None, min_score=-5.0, max_score=5.0, config=None)
Initialize the JudgeTask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data. |
required |
judge_llm
|
BaseLLM
|
The LLM judging the predictions. |
required |
x_column
|
str
|
Name of the column containing input texts. |
'x'
|
y_column
|
Optional[str]
|
Name of the column containing labels/ground truth (if applicable). |
None
|
task_description
|
Optional[str]
|
Description of the task, parsed to the Judge-LLM and Meta-LLM. |
None
|
n_subsamples
|
int
|
Number of subsamples to use for evaluation. |
30
|
eval_strategy
|
EvalStrategy
|
Subsampling strategy to use for evaluation. |
'full'
|
seed
|
int
|
Random seed for reproducibility. |
42
|
judge_prompt
|
Optional[str]
|
Custom prompt for the judge. Note: The score of the Judge will be extracted inside |
None
|
min_score
|
float
|
Minimum score for evaluation. |
-5.0
|
max_score
|
float
|
Maximum score for evaluation. |
5.0
|
config
|
ExperimentConfig
|
Configuration for the task, overriding defaults. |
None
|
Source code in promptolution/tasks/judge_tasks.py
reward_tasks
Module for Reward tasks.
RewardTask
Bases: BaseTask
A task that evaluates a predictor using a reward function.
This task takes a DataFrame, a column name for input data, and a reward function. The reward function takes in a prediction as input and returns a scalar reward.
Source code in promptolution/tasks/reward_tasks.py
__init__(df, reward_function, x_column='x', task_description=None, n_subsamples=30, eval_strategy='full', seed=42, config=None)
Initialize the RewardTask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing the data. |
required |
reward_function
|
Callable
|
Function that takes a prediction and returns a reward score. Note: The optimizers aim to maximize. |
required |
x_column
|
str
|
Name of the column containing input texts. Defaults to "x". |
'x'
|
task_description
|
str
|
Description of the task. |
None
|
n_subsamples
|
int
|
Number of subsamples to use. Defaults to 30. |
30
|
eval_strategy
|
str
|
Subsampling strategy to use. Defaults to "full". |
'full'
|
seed
|
int
|
Random seed for reproducibility. Defaults to 42. |
42
|
config
|
ExperimentConfig
|
Configuration for the task, overriding defaults. |
None
|