Named Entity Recognition
NER
Bases: PredictiveTask[_TaskPromptSignature, _TaskResult, _TaskBridge]
Source code in sieves/tasks/predictive/ner/core.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 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 |
|
id
property
Returns task ID. Used by pipeline for results and dependency management.
Returns:
Type | Description |
---|---|
str
|
Task ID. |
prompt_signature_description
property
Returns prompt signature description.
Returns:
Type | Description |
---|---|
str | None
|
Prompt signature description. |
prompt_template
property
Returns prompt template.
Returns:
Type | Description |
---|---|
str | None
|
Prompt template. |
__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
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 |
|
__init__(entities, engine, task_id=None, show_progress=True, include_meta=True, prompt_template=None, prompt_signature_desc=None, fewshot_examples=())
" Initializes new PredictiveTask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
str | None
|
Task ID. |
None
|
show_progress
|
bool
|
Whether to show progress bar for processed documents. |
True
|
include_meta
|
bool
|
Whether to include meta information generated by the task. |
True
|
prompt_template
|
str | None
|
Custom prompt template. If None, task's default template is being used. |
None
|
prompt_signature_desc
|
str | None
|
Custom prompt signature description. If None, default will be used. |
None
|
fewshot_examples
|
Iterable[TaskFewshotExample]
|
Few-shot examples. |
()
|
Source code in sieves/tasks/predictive/ner/core.py
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 |
|
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
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
serialize()
Serializes task.
Returns:
Type | Description |
---|---|
Config
|
Config instance. |
Source code in sieves/tasks/core.py
50 51 52 53 54 |
|
GliXNER
Bases: NERBridge[list[str], Result, InferenceMode]
Source code in sieves/tasks/predictive/ner/bridges.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 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 |
|
prompt_signature_description
property
Returns prompt signature description. This is used by some engines to aid the language model in generating structured output.
Returns:
Type | Description |
---|---|
str | None
|
Prompt signature description. None if not used by engine. |
prompt_template
property
Returns prompt template. 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 | None
|
Prompt template as string. None if not used by engine. |
__init__(entities, task_id, prompt_template, prompt_signature_desc)
Initializes GliXNER bridge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entities
|
list[str]
|
List of entity types to extract. |
required |
task_id
|
str
|
Task ID. |
required |
prompt_template
|
str | None
|
Custom prompt template. |
required |
prompt_signature_desc
|
str | None
|
Custom prompt signature description. |
required |
Source code in sieves/tasks/predictive/ner/bridges.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
extract(docs)
Extract all values from doc instances that are to be injected into the prompts. Overriding the default implementation to include the entity types in the extracted values.
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/ner/bridges.py
68 69 70 71 72 73 74 |
|
NERBridge
Bases: Bridge[_BridgePromptSignature, _BridgeResult, EngineInferenceMode]
, ABC
Source code in sieves/tasks/predictive/ner/bridges.py
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 |
|
inference_mode
abstractmethod
property
Returns inference mode.
Returns:
Type | Description |
---|---|
EngineInferenceMode
|
Inference mode. |
prompt_signature
abstractmethod
property
Creates 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_signature_description
property
Returns prompt signature description. This is used by some engines to aid the language model in generating structured output.
Returns:
Type | Description |
---|---|
str | None
|
Prompt signature description. None if not used by engine. |
prompt_template
property
Returns prompt template. 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 | None
|
Prompt template as string. None if not used by engine. |
__init__(entities, task_id, prompt_template, prompt_signature_desc)
Initializes NERBridge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_template
|
str | None
|
Custom prompt template. |
required |
prompt_signature_desc
|
str | None
|
Custom prompt signature description. |
required |
Source code in sieves/tasks/predictive/ner/bridges.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
consolidate(results, docs_offsets)
abstractmethod
Consolidates 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 results[docs_chunk_offsets[i][0]:docs_chunk_offsets[i][1]]. |
required |
Returns:
Type | Description |
---|---|
Iterable[TaskResult]
|
Results per document. |
Source code in sieves/tasks/predictive/bridges.py
95 96 97 98 99 100 101 102 |
|
extract(docs)
Extract all values from doc instances that are to be injected into the prompts. Overriding the default implementation to include the entity types in the extracted values.
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/ner/bridges.py
68 69 70 71 72 73 74 |
|