Tasks
Task preprocessing preserves finite numerical references and metadata through its JSONL transport. Unsupported values must be converted in the preprocessing function before Inspect maps records to samples.
See Numerical task data for supported values, a worked example and migration from older task caches.
Modules:
| Name | Description |
|---|---|
task_preprocessor |
|
Classes:
| Name | Description |
|---|---|
DefaultTaskPreprocessor |
Default task preprocessor that returns the input dataset unchanged. |
TaskPreprocessingFunction |
A protocol for a function that preprocesses datasets. |
TaskPreprocessor |
Preprocess a dataset and preserve its supported JSON values in task data. |
DefaultTaskPreprocessor
Bases: TaskPreprocessor
Default task preprocessor that returns the input dataset unchanged.
Methods:
| Name | Description |
|---|---|
__call__ |
Preprocesses the input dataset for a specific task. |
__init__ |
Initializes the default task preprocessor. |
Attributes:
| Name | Type | Description |
|---|---|---|
cache_key |
str
|
Version custom preprocessing rather than guessing its implementation. |
Source code in evalsense/tasks/task_preprocessor.py
cache_key
property
Version custom preprocessing rather than guessing its implementation.
__call__
__call__(
hf_dataset: Dataset,
dataset_manager: DatasetManager,
field_spec: FieldSpec | RecordToSample | None = None,
force_reprocess: bool = False,
) -> Dataset
Preprocesses the input dataset for a specific task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hf_dataset
|
Dataset
|
The input dataset to preprocess, in HuggingFace format. |
required |
dataset_manager
|
DatasetManager
|
The dataset manager used to retrieve the dataset. |
required |
field_spec
|
FieldSpec
|
Specification mapping dataset fields to sample fields. See Inspect AI documentation for more details. |
None
|
force_reprocess
|
bool
|
Whether to force reprocess the dataset even if it already exists. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The preprocessed dataset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
A record contains a non-finite floating-point value. |
TypeError
|
A record contains a value unsupported by the JSON transport. |
Source code in evalsense/tasks/task_preprocessor.py
__init__
Initializes the default task preprocessor.
Source code in evalsense/tasks/task_preprocessor.py
TaskPreprocessingFunction
Bases: Protocol
A protocol for a function that preprocesses datasets.
You can pass this function to a TaskPreprocessor to perform some task-specific preprocessing on a dataset. This is especially useful in cases in which a single dataset can be used for multiple different tasks, with each requiring different preprocessing steps.
Methods:
| Name | Description |
|---|---|
__call__ |
Preprocesses the input dataset for a specific task. |
Source code in evalsense/tasks/task_preprocessor.py
__call__
Preprocesses the input dataset for a specific task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hf_dataset
|
Dataset
|
The input dataset to preprocess, in HuggingFace format. |
required |
dataset_manager
|
DatasetManager
|
The dataset manager used to retrieve the dataset. |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
The preprocessed dataset. |
Source code in evalsense/tasks/task_preprocessor.py
TaskPreprocessor
Preprocess a dataset and preserve its supported JSON values in task data.
Stored Arrow values are written to JSONL without decimal-precision rounding. Materialise transformations in the preprocessing function; display formats and lazy transforms are not applied during serialisation. Unsupported values must be converted before the record-to-sample mapper runs.
Methods:
| Name | Description |
|---|---|
__call__ |
Preprocesses the input dataset for a specific task. |
__init__ |
Initializes the task preprocessor. |
Attributes:
| Name | Type | Description |
|---|---|---|
cache_key |
str
|
Version custom preprocessing rather than guessing its implementation. |
Source code in evalsense/tasks/task_preprocessor.py
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 | |
cache_key
property
Version custom preprocessing rather than guessing its implementation.
__call__
__call__(
hf_dataset: Dataset,
dataset_manager: DatasetManager,
field_spec: FieldSpec | RecordToSample | None = None,
force_reprocess: bool = False,
) -> Dataset
Preprocesses the input dataset for a specific task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hf_dataset
|
Dataset
|
The input dataset to preprocess, in HuggingFace format. |
required |
dataset_manager
|
DatasetManager
|
The dataset manager used to retrieve the dataset. |
required |
field_spec
|
FieldSpec
|
Specification mapping dataset fields to sample fields. See Inspect AI documentation for more details. |
None
|
force_reprocess
|
bool
|
Whether to force reprocess the dataset even if it already exists. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The preprocessed dataset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
A record contains a non-finite floating-point value. |
TypeError
|
A record contains a value unsupported by the JSON transport. |
Source code in evalsense/tasks/task_preprocessor.py
__init__
__init__(
name: str,
preprocessing_function: TaskPreprocessingFunction,
*,
version: str | None = None,
) -> None
Initializes the task preprocessor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the task preprocessor. |
required |
preprocessing_function
|
TaskPreprocessingFunction
|
The function used to preprocess the dataset. |
required |
version
|
str | None
|
Required for custom code. Bump when its behavior or external inputs change. |
None
|