Classification
Classification predictive task and few‑shot example schemas.
Classification
Bases: PredictiveTask[_TaskPromptSignature, _TaskResult, _TaskBridge]
Predictive task for text classification across multiple engine backends.
Source code in sieves/tasks/predictive/classification/core.py
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
fewshot_examples
property
Return few-shot examples.
Returns:
| Type | Description |
|---|---|
Sequence[FewshotExample]
|
Few-shot examples. |
id
property
Return task ID.
Used by pipeline for results and dependency management.
Returns:
| Type | Description |
|---|---|
str
|
Task ID. |
prompt_signature_description
property
Return prompt signature description.
Returns:
| Type | Description |
|---|---|
str | None
|
Prompt signature description. |
prompt_template
property
Return prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template. |
__add__(other)
Chain this task with another task or pipeline using the + operator.
This returns a new Pipeline that executes this task first, followed by the
task(s) in other. The original task(s)/pipeline are not mutated.
Cache semantics:
- If other is a Pipeline, the resulting pipeline adopts other's
use_cache setting (because the left-hand side is a single task).
- If other is a Task, the resulting pipeline defaults to use_cache=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Task | Pipeline
|
A |
required |
Returns:
| Type | Description |
|---|---|
Pipeline
|
A new |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in sieves/tasks/core.py
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 | |
__call__(docs)
Execute the task on a set of documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Documents to process. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[Doc]
|
Processed documents. |
Source code in sieves/tasks/predictive/core.py
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 | |
__init__(labels, model, task_id=None, include_meta=True, batch_size=-1, prompt_instructions=None, fewshot_examples=(), label_descriptions=None, multi_label=True, generation_settings=GenerationSettings())
Initialize new PredictiveTask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[str]
|
Labels to predict. |
required |
model
|
_TaskModel
|
Model to use. |
required |
task_id
|
str | None
|
Task ID. |
None
|
include_meta
|
bool
|
Whether to include meta information generated by the task. |
True
|
batch_size
|
int
|
Batch size to use for inference. Use -1 to process all documents at once. |
-1
|
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
None
|
fewshot_examples
|
Sequence[FewshotExample]
|
Few-shot examples. |
()
|
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. If provided, the keys must match the labels. |
None
|
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
True
|
generation_settings
|
GenerationSettings
|
Generation settings. |
GenerationSettings()
|
Source code in sieves/tasks/predictive/classification/core.py
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 | |
deserialize(config, **kwargs)
classmethod
Generate PredictiveTask instance from config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Config to generate instance from. |
required |
kwargs
|
dict[str, Any]
|
Values to inject into loaded config. |
{}
|
Returns:
| Type | Description |
|---|---|
PredictiveTask[TaskPromptSignature, TaskResult, TaskBridge]
|
Deserialized PredictiveTask instance. |
Source code in sieves/tasks/predictive/core.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
optimize(optimizer, verbose=True)
Optimize task prompt and few-shot examples with the available optimization config.
Updates task to use best prompt and few-shot examples found by the optimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimizer
|
Optimizer
|
Optimizer to run. |
required |
verbose
|
bool
|
Whether to suppress output. DSPy produces a good amount of logs, so this can be useful to not pollute your terminal. Only warnings and errors will be printed. |
True
|
Returns:
| Type | Description |
|---|---|
tuple[str, Sequence[FewshotExample]]
|
Best found prompt and few-shot examples. |
Source code in sieves/tasks/predictive/core.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
serialize()
Serialize task.
Returns:
| Type | Description |
|---|---|
Config
|
Config instance. |
Source code in sieves/tasks/core.py
88 89 90 91 92 93 | |
to_hf_dataset(docs, threshold=0.5)
Convert results to a Hugging Face dataset with multi-hot labels.
The emitted dataset contains a text column and a labels column which is a multi-hot list aligned to
self._labels. This method is robust to different result shapes produced by various engines and bridges in
both single-label and multi-label configurations:
- list[tuple[str, float]] for multi-label results
- tuple[str, float] for single-label results
- str for single-label results (assumes score 1.0)
- pydantic.BaseModel exposing label and optional score
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Documents whose |
required |
threshold
|
float
|
Threshold to convert scores into multi-hot indicators. |
0.5
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A |
Raises:
| Type | Description |
|---|---|
KeyError
|
If any document is missing this task's results. |
TypeError
|
If a result cannot be interpreted. |
Source code in sieves/tasks/predictive/classification/core.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
FewshotExampleMultiLabel
Bases: FewshotExample
Few‑shot example for multi‑label classification with per‑label confidences.
Source code in sieves/tasks/predictive/classification/core.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
input_fields
property
Defines which fields are inputs.
Returns:
| Type | Description |
|---|---|
Sequence[str]
|
Sequence of field names. |
check_confidence()
Validate that confidences lie within [0, 1].
Source code in sieves/tasks/predictive/classification/core.py
49 50 51 52 53 54 | |
from_dspy(example)
classmethod
Convert from dspy.Example.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
example
|
Example
|
Example as |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Example as |
Source code in sieves/tasks/predictive/core.py
76 77 78 79 80 81 82 83 | |
to_dspy()
Convert to dspy.Example.
Returns:
| Type | Description |
|---|---|
Example
|
Example as |
Source code in sieves/tasks/predictive/core.py
69 70 71 72 73 74 | |
FewshotExampleSingleLabel
Bases: FewshotExample
Few‑shot example for single‑label classification with a global confidence.
Source code in sieves/tasks/predictive/classification/core.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
input_fields
property
Defines which fields are inputs.
Returns:
| Type | Description |
|---|---|
Sequence[str]
|
Sequence of field names. |
check_confidence()
Check confidence value.
Return: FewshotExampleSingleLabel instance.
Source code in sieves/tasks/predictive/classification/core.py
69 70 71 72 73 74 75 76 77 78 79 | |
from_dspy(example)
classmethod
Convert from dspy.Example.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
example
|
Example
|
Example as |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Example as |
Source code in sieves/tasks/predictive/core.py
76 77 78 79 80 81 82 83 | |
to_dspy()
Convert to dspy.Example.
Returns:
| Type | Description |
|---|---|
Example
|
Example as |
Source code in sieves/tasks/predictive/core.py
69 70 71 72 73 74 | |
Bridges for classification task.
ClassificationBridge
Bases: Bridge[_BridgePromptSignature, _BridgeResult, EngineInferenceMode], ABC
Abstract base class for classification bridges.
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
inference_mode
abstractmethod
property
Return inference mode.
Returns:
| Type | Description |
|---|---|
EngineInferenceMode
|
Inference mode. |
prompt_signature
abstractmethod
property
Create output signature.
E.g.: Signature in DSPy, Pydantic objects in outlines, JSON schema in jsonformers.
This is engine-specific.
Returns:
| Type | Description |
|---|---|
type[TaskPromptSignature] | TaskPromptSignature
|
Output signature object. This can be an instance (e.g. a regex string) or a class (e.g. a Pydantic class). |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
consolidate(results, docs_offsets)
abstractmethod
Consolidate results for document chunks into document results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Iterable[TaskResult]
|
Results per document chunk. |
required |
docs_offsets
|
list[tuple[int, int]]
|
Chunk offsets per document. Chunks per document can be obtained with |
required |
Returns:
| Type | Description |
|---|---|
Iterable[TaskResult]
|
Results per document. |
Source code in sieves/tasks/predictive/bridges.py
127 128 129 130 131 132 133 134 135 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |
integrate(results, docs)
abstractmethod
Integrate results into Doc instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Iterable[TaskResult]
|
Results from prompt executable. |
required |
docs
|
Iterable[Doc]
|
Doc instances to update. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[Doc]
|
Updated doc instances. |
Source code in sieves/tasks/predictive/bridges.py
118 119 120 121 122 123 124 125 | |
DSPyClassification
Bases: ClassificationBridge[PromptSignature, Result, InferenceMode]
DSPy bridge for classification.
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |
HuggingFaceClassification
Bases: ClassificationBridge[list[str], Result, InferenceMode]
HuggingFace bridge for classification.
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |
LangChainClassification
Bases: PydanticBasedClassification[InferenceMode]
LangChain bridge for classification.
Source code in sieves/tasks/predictive/classification/bridges.py
488 489 490 491 492 493 494 | |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |
OutlinesClassification
Bases: PydanticBasedClassificationWithLabelForcing[InferenceMode]
Outlines bridge for classification.
Source code in sieves/tasks/predictive/classification/bridges.py
571 572 573 574 575 576 577 | |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |
PydanticBasedClassification
Bases: ClassificationBridge[BaseModel | list[str], BaseModel | str, EngineInferenceMode], ABC
Base class for Pydantic-based classification bridges.
Source code in sieves/tasks/predictive/classification/bridges.py
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
inference_mode
abstractmethod
property
Return inference mode.
Returns:
| Type | Description |
|---|---|
EngineInferenceMode
|
Inference mode. |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |
PydanticBasedClassificationWithLabelForcing
Bases: PydanticBasedClassification[EngineInferenceMode], ABC
Base class for Pydantic-based classification bridges with label forcing.
Source code in sieves/tasks/predictive/classification/bridges.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
inference_mode
abstractmethod
property
Return inference mode.
Returns:
| Type | Description |
|---|---|
EngineInferenceMode
|
Inference mode. |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different engines have different expectations as how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind engine-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by engine. |
__init__(task_id, prompt_instructions, labels, multi_label, label_descriptions=None)
Initialize InformationExtractionBridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
labels
|
list[str]
|
Labels to classify. |
required |
multi_label
|
bool
|
If True, task returns confidence scores for all specified labels. If False, task returns most likely class label. In the latter case label forcing mechanisms are utilized, which can lead to higher accuracy. |
required |
label_descriptions
|
dict[str, str] | None
|
Optional descriptions for each label. |
None
|
Source code in sieves/tasks/predictive/classification/bridges.py
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 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Iterable[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts |
Source code in sieves/tasks/predictive/bridges.py
110 111 112 113 114 115 116 | |