API reference
data_models
Data models for the data extraction evaluation toolkit.
base
Core data models regarding annotations.
AnnotationType
Bases: StrEnum
Enumeration of annotation types.
Source code in deet/data_models/base.py
18 19 20 21 22 | |
Attribute
pydantic-model
Bases: BaseModel
Core attribute definition for data extraction tasks.
Represents a single piece of information to be extracted from documents.
Fields:
-
prompt(str | None) -
output_data_type(AttributeType) -
attribute_id(int) -
attribute_label(str)
Source code in deet/data_models/base.py
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 | |
enter_custom_prompt(max_tries=5)
Use CLI to add a prompt.
Source code in deet/data_models/base.py
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 | |
populate_prompt_from_dict(input_dict, *, overwrite=True)
Populate the prompt field in an Attribute instance from a dict.
The dict must contain following fields
- attribute_id
- prompt
and attribute_id(dict) must match self.attribute_id.
NOTE: this would typically be used in a loop to populate prompts for a list of attributes from a csv file where every row represents an attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
dict[str, Any]
|
An input dict, typically a line in a csv file. |
required |
overwrite
|
bool
|
Overwrite existing val in |
True
|
Source code in deet/data_models/base.py
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 | |
print_tabulated()
Print tabulated version of the contents of this attribute.
Source code in deet/data_models/base.py
193 194 195 196 197 198 | |
write_to_csv(filepath, mode='a')
Write an attribute as a line to a csv file - fields represent columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path
|
outfile destination. |
required |
mode
|
Literal['a', 'w']
|
_w_rite or _a_ppend. |
'a'
|
Source code in deet/data_models/base.py
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 | |
AttributeType
Bases: StrEnum
Enum of permitted attribute data types.
Source code in deet/data_models/base.py
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 | |
__str__()
Return the string value for JSON serialization.
Source code in deet/data_models/base.py
74 75 76 | |
missing_annotation_default()
Return default output_data when no gold-standard annotation exists.
Used when synthesizing a placeholder annotation (e.g. comparing LLM output to gold standard where a value was never annotated).
Returns a fresh list or dict for mutable types so callers do not share
state.
Raises:
| Type | Description |
|---|---|
ValueError
|
If this member has no defined default. |
Note
This is not Enum._missing_; that hook resolves unrecognised raw
values when constructing enum members, not per-type defaults.
Source code in deet/data_models/base.py
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 | |
to_json_type()
Map AttributeType to JS types for the JSON schema.
Source code in deet/data_models/base.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
to_python_type()
Map AttributeType to actual Python types.
Source code in deet/data_models/base.py
78 79 80 81 82 83 84 85 86 87 88 | |
GoldStandardAnnotation
pydantic-model
Bases: BaseModel
A single gold standard annotation for an attribute.
raw_data stores the data as it comes from source,
output_data is computed and coerces raw_data into the correct type.
This can change if the AttributeType of the attribute changes.
Fields:
-
attribute(Attribute) -
raw_data(Any) -
annotation_type(AnnotationType) -
additional_text(str | None) -
reasoning(str | None)
Source code in deet/data_models/base.py
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 | |
additional_text = None
pydantic-field
Notes provided by the annotator - usually the citation from the paper containing the context window where the attribute is found
output_data
property
Coerce raw data to correct type based on attribute.
raw_data
pydantic-field
The output data exactly as it was first seen without any coercion to the correct type
reasoning = None
pydantic-field
Reasoning, taken from LLM response
handle_output_data_input(data)
classmethod
Catch instantations with output_data and send this to raw_data.
Source code in deet/data_models/base.py
356 357 358 359 360 361 362 | |
LLMAnnotationResponse
pydantic-model
Bases: BaseModel
LLM response model for a single annotation.
This mirrors EppiGoldStandardAnnotation structure but uses attribute_id instead of full EppiAttribute object, as the LLM cannot provide the full attribute object.
Config:
extra:forbid
Fields:
-
attribute_id(int) -
output_data(Any) -
additional_text(str | None) -
reasoning(str | None)
Source code in deet/data_models/base.py
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 | |
additional_text
pydantic-field
Supporting text from document containing the context window where the attribute is found
attribute_id
pydantic-field
The ID of the EPPI attribute being annotated
output_data
pydantic-field
The LLM's annotation.
reasoning
pydantic-field
Reasoning or explanation for the annotation decision
LLMInputSchema
pydantic-model
Bases: BaseModel
Schema for data going into the LLM.
Config:
extra:ignore
Fields:
-
prompt(str) -
attribute_id(int) -
output_data_type(AttributeType)
Validators:
Source code in deet/data_models/base.py
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 | |
fill_prompt(data, fill_from_field='attribute_label')
pydantic-validator
Fill prompt field if empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
the incoming data |
required |
fill_from_field
|
str
|
field to use to fill prompt if empty. Defaults to "attribute_label". |
'attribute_label'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the populated data. |
Source code in deet/data_models/base.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 | |
LLMResponseSchema
pydantic-model
Bases: BaseModel
Root schema for LLM annotation extraction response.
This structure matches the expected format that can be converted to list[GoldStandardAnnotation] after attribute resolution.
Config:
extra:forbid
Fields:
Source code in deet/data_models/base.py
459 460 461 462 463 464 465 466 467 468 469 470 471 | |
annotations
pydantic-field
List of annotations extracted from the document
coerce_annotation_to_bool(val)
Coerce an annotation to a bool.
Source code in deet/data_models/base.py
256 257 258 259 260 261 262 263 264 265 266 | |
coerce_annotation_to_float(val)
Coerce an annotation to a float.
Source code in deet/data_models/base.py
283 284 285 286 287 288 289 290 291 292 293 294 | |
coerce_annotation_to_int(val)
Coerce an annotation to a int.
Source code in deet/data_models/base.py
269 270 271 272 273 274 275 276 277 278 279 280 | |
coerce_annotation_to_list(val)
Coerce an annotation to list.
Source code in deet/data_models/base.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
coerce_annotation_to_str(val)
Coerce an annotation to a string.
Source code in deet/data_models/base.py
251 252 253 | |
documents
Data models concerning documents and how to represent them in deet.
ContextType
Bases: StrEnum
Types of context that can be provided to the LLM.
Source code in deet/data_models/documents.py
42 43 44 45 46 47 48 49 | |
Document
pydantic-model
Bases: BaseModel
Represents a document.
This can be used both for references itemised in a document listing gold standard annotations (e.g. eppi.json) AND for a document coming from a file (e.g. pdf) without linking to a gold standard annotations document with references.
Config:
extra:allowvalidate_assignment:True
Fields:
-
name(str) -
citation(ReferenceFileInput) -
context(str | None) -
context_type(ContextType | None) -
document_id(int | None) -
document_identity(DocumentIdentity | None) -
parsed_document(ParsedOutput | None) -
original_doc_filepath(Path | None) -
is_final(bool) -
is_linked(bool)
Validators:
Source code in deet/data_models/documents.py
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 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 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
safe_identity
property
Definitely Return an identity. Initialise identity if not set already, or raise an error if this is not possible.
safe_parsed_document
property
Return the parsed_document, or raise an error if document is not linked.
author_year_from_document_identity(substring_strategy)
Create lower-case author_year guess from a Document's
DocumentIdentity field.
The idea is to take the last name of the first author.
NOTE: this can probably improved with more knowledge of how destiny encodes the first_author field.
Returns:
| Name | Type | Description |
|---|---|---|
author_year |
str
|
|
Source code in deet/data_models/documents.py
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 | |
init_document_identity(existing_ids=None, *, return_id=True)
Initialise document_identity field using available metadata.
Source code in deet/data_models/documents.py
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 | |
link_parsed_document(parsed_document, original_doc_filepath=None)
Link parsed document and document metadata/reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed_document
|
ParsedOutput
|
the output from the parser |
required |
original_doc_filepath
|
Path
|
full filepath to the original doc. |
None
|
Source code in deet/data_models/documents.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
load(path)
classmethod
Load linked document from .json.
Source code in deet/data_models/documents.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
save(path)
Save linked document to .json.
Source code in deet/data_models/documents.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
set_abstract_context()
Set the abstract, contained in citation field, as context.
Source code in deet/data_models/documents.py
426 427 428 429 430 431 432 433 434 435 436 437 438 | |
set_context_from_parsed()
Symlink context to parsed_document.text.
Source code in deet/data_models/documents.py
463 464 465 466 467 468 469 | |
validate_final()
pydantic-validator
Validate Document is permitted to be is_final.
Source code in deet/data_models/documents.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
validate_linking_complete()
pydantic-validator
Validate linking is completed if is_linked=True.
Source code in deet/data_models/documents.py
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 | |
DocumentIDSource
Bases: StrEnum
Sources for a given document_id. Can be e.g. eppi_item_id.
To be extended if e.g. we start working with non-eppi gold standard references.
Source code in deet/data_models/documents.py
52 53 54 55 56 57 58 59 60 61 62 63 64 | |
DocumentIdentity
pydantic-model
Bases: BaseModel
A unified identity for a document, deriveable from multiple sources.
Fields:
-
document_id(int | None) -
document_id_source(DocumentIDSource | None) -
doi(str | None) -
first_author(str | None) -
year(str | None)
Source code in deet/data_models/documents.py
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 | |
populate_id(existing_ids=None, hierarchy=None)
Populate document_id using a hierarchical list of ID creation methods.
Tries each method in order until a unique ID is generated. If an ID conflicts with existing_ids, tries the next method. RANDINT always succeeds as fallback.
NOTE: we will have to implement some sort of matching thing, if we are concerned that an id-collision might be becuase we have already parsed&linked a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
existing_ids
|
set[int] | None
|
List of existing IDs to check for conflicts. |
None
|
hierarchy
|
list[DocumentIDSource] | None
|
Ordered list of DocumentIDSource methods to try. Defaults to [EPPI_ITEM_ID, DOI_AUTHOR_YEAR, DOI_ID, AUTHOR_YEAR_ID, RANDINT]. |
None
|
Raises:
| Type | Description |
|---|---|
BadDocumentIdError
|
If unable to generate unique ID (should never happen as RANDINT is always in hierarchy). |
Source code in deet/data_models/documents.py
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 | |
GoldStandardAnnotatedDocument
pydantic-model
Bases: BaseModel, Generic[DocumentTypeVar, GoldStandardAnnotationTypeVar]
A document with its gold standard annotations.
Fields:
-
document(DocumentTypeVar) -
annotations(list[GoldStandardAnnotationTypeVar])
Source code in deet/data_models/documents.py
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 | |
get_attribute_annotation(attribute)
Get the value of the annotation of the corresponding attribute.
Source code in deet/data_models/documents.py
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 | |
GoldStandardAnnotatedDocumentList
pydantic-model
Bases: BaseModel, Generic[GoldStandardAnnotatedDocumentTypeVar]
A list of GoldStandardAnnotatedDocuments (or subclasses thereof). This list is indexed to enable easy retrieval by document_id.
Fields:
-
gold_standard_annotations(Sequence[GoldStandardAnnotatedDocumentTypeVar])
Source code in deet/data_models/documents.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
annotation_index
cached
property
Cached index to enable retrieving annotated documents by id.
get_by_id(document_id)
Get GoldStandardAnnotatedDocument where document.document_identity matches document_identity.
Source code in deet/data_models/documents.py
581 582 583 584 585 586 587 588 589 590 591 | |
enums
A store for plain enums, so they can quickly be imported in the CLI. We can use these to set argument types and defaults, without needing large imports, that would slow the CLI down during autocomplete, or when asking for --help.
CustomPromptPopulationMethod
Bases: StrEnum
Methods of populating prompts.
Source code in deet/data_models/enums.py
11 12 13 14 15 | |
eppi
EPPI-specific data models extending the core models.
AttributeAnswerCoT
pydantic-model
Bases: BaseModel
Detailed answer format for a single attribute with reasoning.
Fields:
Source code in deet/data_models/eppi.py
392 393 394 395 396 397 398 399 400 401 402 | |
answer
pydantic-field
The answer to the question, 'True' or 'False'
attribute_name
pydantic-field
The name of the attribute being asked about
citation
pydantic-field
The citation from the Research Information to support the answer
reasoning
pydantic-field
The reasoning behind the answer
BatchAnswerFormatCoT
pydantic-model
Bases: BaseModel
Batch answers for all attributes with reasoning.
Fields:
Source code in deet/data_models/eppi.py
405 406 407 408 409 410 | |
answers
pydantic-field
List of answers for each attribute
EppiAttribute
pydantic-model
Bases: Attribute
EPPI-specific attribute with additional fields.
Extends the core Attribute class with EPPI-specific metadata and hierarchy information.
Uses alias generators to automatically map camelCase EPPI JSON fields to snake_case Python fields.
Config:
validate_by_name:Truevalidate_by_alias:True
Fields:
-
prompt(str | None) -
attribute_id(int) -
attribute_selection_type(EppiAttributeSelectionType) -
output_data_type(AttributeType) -
attribute_label(str) -
attribute_set_description(str | None) -
hierarchy_path(str | None) -
hierarchy_level(int) -
is_leaf(bool) -
parent_attribute_id(int | None) -
attribute_description(str | None)
Source code in deet/data_models/eppi.py
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 | |
attribute_description = None
pydantic-field
Detailed description explaining what this attribute represents
attribute_set_description = None
pydantic-field
Description of the attribute set this attribute belongs to
hierarchy_level = 0
pydantic-field
Numeric level indicating depth in the attribute hierarchy (0 = root level)
hierarchy_path = None
pydantic-field
Dot-separated path showing the hierarchical position of this attribute
is_leaf = True
pydantic-field
Whether this attribute is a leaf node (has no child attributes)
parent_attribute_id = None
pydantic-field
ID of the parent attribute in the hierarchy
EppiAttributeSelectionType
Bases: StrEnum
AttributeType as it appears in eppi json.
Source code in deet/data_models/eppi.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
EppiCodeSet
pydantic-model
Bases: BaseModel
Represents a single CodeSet from EPPI JSON.
CodeSets contain hierarchical attribute definitions used in EPPI-Reviewer.
Fields:
Source code in deet/data_models/eppi.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
get_attributes_list()
Extract AttributesList from the CodeSet.
Source code in deet/data_models/eppi.py
352 353 354 355 356 | |
EppiDocument
pydantic-model
Bases: Document
EPPI-specific document.
Uses alias generators to automatically map camelCase EPPI JSON fields to snake_case Python fields.
Config:
validate_by_name:Truevalidate_by_alias:True
Fields:
-
citation(ReferenceFileInput) -
context(str | None) -
context_type(ContextType | None) -
document_identity(DocumentIdentity | None) -
parsed_document(ParsedOutput | None) -
original_doc_filepath(Path | None) -
is_final(bool) -
is_linked(bool) -
name(str) -
document_id(int) -
parent_title(str | None) -
short_title(str | None) -
date_created(datetime | None) -
created_by(str | None) -
edited_by(str | None) -
year(int | None) -
month(str | None) -
abstract(str | None) -
authors(str | None) -
keywords(str | None) -
doi(str | None)
Validators:
-
validate_linking_complete -
validate_final -
empty_year_string_to_none→year -
parse_date_string→date_created -
populate_citation_field
Source code in deet/data_models/eppi.py
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 | |
empty_year_string_to_none(value)
pydantic-validator
Parse an empty string year to None or return as is.
Source code in deet/data_models/eppi.py
230 231 232 233 234 235 236 | |
parse_date_string(value)
pydantic-validator
Parse a string datetime to native datetime.
Source code in deet/data_models/eppi.py
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 | |
populate_citation_field(data)
pydantic-validator
Populate the citation field with a Destiny
reference derived from the EPPI data.
Source code in deet/data_models/eppi.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
EppiGoldStandardAnnotatedDocument
pydantic-model
Bases: GoldStandardAnnotatedDocument[EppiDocument, EppiGoldStandardAnnotation]
EPPI-specific gold standard annotated document.
Fields:
-
document(DocumentTypeVar) -
annotations(list[GoldStandardAnnotationTypeVar])
Source code in deet/data_models/eppi.py
337 338 339 340 | |
EppiGoldStandardAnnotation
pydantic-model
Bases: GoldStandardAnnotation
EPPI-specific gold standard annotation.
In EPPI-Reviewer context, an "arm" refers to a study group or intervention group within a research study (e.g., "Treatment Group", "Control Group", "Placebo Group"). Each annotation is associated with a specific arm to indicate which study group the extracted information relates to.
Fields:
-
attribute(Attribute) -
raw_data(Any) -
annotation_type(AnnotationType) -
additional_text(str | None) -
reasoning(str | None) -
arm_id(int | None) -
arm_title(str | None) -
arm_description(str | None) -
item_attribute_full_text_details(list[EppiItemAttributeFullTextDetails] | None)
Source code in deet/data_models/eppi.py
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 | |
arm_description = None
pydantic-field
Detailed description of the study arm
arm_id = None
pydantic-field
ID of the study arm this annotation relates to
arm_title = None
pydantic-field
Title or name of the study arm
item_attribute_full_text_details = None
pydantic-field
List of detailed text extracts and arm-specific information for this annotation
EppiItemAttributeFullTextDetails
pydantic-model
Bases: BaseModel
EPPI-specific item attribute full text details.
Arm specific information, exact text keywords for the attribute.
Fields:
Validators:
Source code in deet/data_models/eppi.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
validate_at_least_one_field(data)
pydantic-validator
Ensure at least one field is not None.
Source code in deet/data_models/eppi.py
296 297 298 299 300 301 302 303 304 305 306 | |
EppiRawData
pydantic-model
Bases: BaseModel
Represents the complete EPPI JSON structure.
This model validates and structures the raw EPPI JSON data, making it easier to work with and validate.
Fields:
Source code in deet/data_models/eppi.py
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 | |
extract_all_attributes(flatten_hierarchy_func)
Extract and flatten attributes from all CodeSets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flatten_hierarchy_func
|
Callable[[list], list]
|
Function to flatten attribute hierarchy |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of flattened attribute dictionaries |
Source code in deet/data_models/eppi.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
parse_citation_to_destiny(reference)
Create a ReferenceFileInput object from document data.
NOTE: we are not using the wrapping parser method in repository as it is for the whole document, and if it fails, we wouldn't be able to map a destiny reference.
See https://github.com/destiny-evidence/destiny-repository/issues/458
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
dict[str, Any]
|
one reference from the eppi json. |
required |
Source code in deet/data_models/eppi.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 | |
sanitise_doi(doi_candidate, *, raise_on_fail=False)
Clean DOI strings in EPPI jsons.
Source code in deet/data_models/eppi.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
evaluation
Data models to help with evaluation.
AttributeMetric
pydantic-model
Bases: BaseModel
Data structure storing a metric for an attribute for a data extraction run.
Fields:
Source code in deet/data_models/evaluation.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 132 | |
dictify()
Return a dictionary representation, unpacking the attribute into ID and label.
Source code in deet/data_models/evaluation.py
96 97 98 99 100 101 102 103 104 105 106 | |
save_to_csv(filepath, mode='a')
Write an evaluation metric for an attribute as a line to a csv file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path
|
outfile destination. |
required |
mode
|
Literal['a', 'w']
|
_w_rite or _a_ppend. |
'a'
|
Source code in deet/data_models/evaluation.py
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 | |
check_metric_returns_float(metric)
Check whether a metric returns a scalar.
Source code in deet/data_models/evaluation.py
23 24 25 26 27 28 | |
get_metrics_for_attribute_type(attribute_type)
Return the metric set registered for the given attribute data type.
Some types map to an empty dict when no suitable default metrics are implemented yet (float, list, dict); callers may still merge in custom metrics.
Source code in deet/data_models/evaluation.py
76 77 78 79 80 81 82 83 84 85 | |
n_labels(y_true, y_pred)
Count the number of positive instances of the class in gold data.
Source code in deet/data_models/evaluation.py
31 32 33 | |
extraction
Data models for LLM extraction outputs.
DocumentExtractionResult
pydantic-model
Bases: BaseModel
Result of extracting data from a single document via an LLM.
Fields:
-
annotations(list[GoldStandardAnnotation]) -
messages(list[dict[str, Any]]) -
input_tokens(int) -
output_tokens(int) -
model(str | None) -
total_cost_usd(float | None) -
timestamp(datetime)
Validators:
Source code in deet/data_models/extraction.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
compute_total_cost_usd()
pydantic-validator
Populate total_cost_usd from tokens and model (estimate_cost_usd).
Source code in deet/data_models/extraction.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
ExtractionRunMetadata
pydantic-model
Bases: BaseModel
Aggregate metadata for a batch extraction run.
Fields:
-
model(str | None) -
total_input_tokens(int) -
total_output_tokens(int) -
total_cost_usd(float | None) -
per_document_tokens(dict[str, dict[str, int]]) -
timestamp(datetime)
Source code in deet/data_models/extraction.py
40 41 42 43 44 45 46 47 48 | |
ExtractionRunOutput
pydantic-model
Bases: BaseModel
Top-level output from a batch extraction run.
Fields:
-
annotated_documents(list[GoldStandardAnnotatedDocument]) -
metadata(ExtractionRunMetadata)
Source code in deet/data_models/extraction.py
51 52 53 54 55 | |
pipeline
Models to employ for implementing DEET jobs in sequential, harmonised pipelines.
BaseExecutor
Bases: ABC
Abstract base class for all executors.
Source code in deet/data_models/pipeline.py
104 105 106 107 108 109 110 111 112 113 114 | |
CodeExecutor
Bases: BaseExecutor
Executor for Python callable.
Source code in deet/data_models/pipeline.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
EgressMethod
Bases: StrEnum
An enum of egree methods for a PipelineStage.
Source code in deet/data_models/pipeline.py
60 61 62 63 64 | |
Executor
A wrapper for all kinds of executors.
Source code in deet/data_models/pipeline.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
__init__(executor)
Init new executor instance.
Source code in deet/data_models/pipeline.py
325 326 327 | |
execute(job, args=None, kwargs=None)
Execute a job.
Source code in deet/data_models/pipeline.py
329 330 331 332 333 334 335 336 | |
IngressMethod
Bases: StrEnum
An enum of ingress methods for a PipelineStage.
Source code in deet/data_models/pipeline.py
51 52 53 54 55 56 57 | |
Job
pydantic-model
Bases: BaseModel
The attributes describing a specific job.
Config:
arbitrary_types_allowed:True
Fields:
-
name(str) -
job_format(JobFormat) -
job_type(JobType | list[JobType]) -
language(Language) -
ingress_method(IngressMethod | None) -
egress_method(EgressMethod) -
job(Callable | Path) -
script_args(list[str] | None) -
func_args(list[Any] | None) -
func_kwargs(dict[str, Any] | None) -
capture_output(bool) -
executor(Executor)
Source code in deet/data_models/pipeline.py
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 | |
run_job()
Run the job defined in this model instance.
Source code in deet/data_models/pipeline.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
JobExecutionError
Bases: Exception
To raise when a job hits a generic error.
Source code in deet/data_models/pipeline.py
47 48 | |
JobFormat
Bases: StrEnum
An enum of job formats.
Jobs are the building blocks of pipeline stages. The job format describes the 'medium' in which the job is provided to the job object.
Source code in deet/data_models/pipeline.py
67 68 69 70 71 72 73 74 75 76 77 | |
JobType
Bases: StrEnum
An enum of job types.
This is a descriptive label of the broad category of what the job is doing.
Source code in deet/data_models/pipeline.py
80 81 82 83 84 85 86 87 88 89 90 91 | |
Language
Bases: StrEnum
An enum of permitted languages a job can be specified in.
Source code in deet/data_models/pipeline.py
94 95 96 97 98 99 100 101 | |
MissingBinaryError
Bases: Exception
To raise when we're missing a binary required to run a script.
Source code in deet/data_models/pipeline.py
43 44 | |
Pipeline
pydantic-model
Bases: BaseModel
A complete pipeline consisting of several PipelineStage objects.
Fields:
-
name(str) -
stages(list[PipelineStage])
Source code in deet/data_models/pipeline.py
472 473 474 475 476 477 478 479 480 481 482 483 484 | |
run()
Run all pipeline stages.
Source code in deet/data_models/pipeline.py
480 481 482 483 484 | |
PipelineStage
pydantic-model
Bases: BaseModel
A stage in a DEET pipeline.
Fields:
-
name(str) -
skip_jobs_if_failed(bool) -
input_file(Path | None) -
data(Any | None) -
jobs(Job | list[Job]) -
logfile(Path | None) -
default_func_args(list[Any] | None) -
default_func_kwargs(dict[str, Any] | None)
Validators:
-
convert_jobs_to_list→jobs
Source code in deet/data_models/pipeline.py
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 | |
convert_jobs_to_list(v)
pydantic-validator
Convert jobs to list of jobs if just one job supplied.
Source code in deet/data_models/pipeline.py
395 396 397 398 399 400 401 | |
run_jobs(func_args=None, func_kwargs=None)
Run all jobs in a pipeline stage.
Source code in deet/data_models/pipeline.py
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 | |
write_stage_logfile(payload, filepath)
staticmethod
Write logfile for a specific stage.
Source code in deet/data_models/pipeline.py
403 404 405 406 | |
ScriptExecutor
Bases: BaseExecutor
An executor class for different kinds of scripts.
Source code in deet/data_models/pipeline.py
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 | |
__init__(python_path=None, r_path=None, bash_path=Path('/bin/bash'))
Create ScriptExecutor instance.
Source code in deet/data_models/pipeline.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
bash_executor(script_path, args, *, capture_output=True)
Execute a bash script.
Source code in deet/data_models/pipeline.py
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 | |
python_executor(script_path, args, *, capture_output=True)
Execute a python script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_path
|
Path
|
file path to script. |
required |
args
|
list[str]
|
args to run with script. |
required |
capture_output
|
bool
|
Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
None | str
|
None | str: output from stdout or None. |
Source code in deet/data_models/pipeline.py
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 | |
r_executor(script_path, args, *, capture_output=True)
Execute an R script.
Source code in deet/data_models/pipeline.py
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 | |
verify_filetype(filename, filetype)
staticmethod
Verify a given file is of a given filetype via checking the ending.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of file. |
required |
filetype
|
Literal[".py", ".R", ".sh"]
|
|
required |
Raises:
| Type | Description |
|---|---|
WrongFiletypeError
|
When ending doesnt match the input. |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if OK. |
Source code in deet/data_models/pipeline.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
WrongFiletypeError
Bases: Exception
Raise for wrong filetype.
Source code in deet/data_models/pipeline.py
30 31 32 33 34 35 36 37 38 39 40 | |
__init__(msg='Supplied filetype is not correct.', *args, **kwargs)
Init the exception with default message.
Source code in deet/data_models/pipeline.py
33 34 35 36 37 38 39 40 | |
jobify(name, job_type=JobType.DATA_PROCESSING, func_args=None, func_kwargs=None, *, capture_output=True)
Decorate to wrap a function as a Job instance.
Source code in deet/data_models/pipeline.py
494 495 496 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 | |
stage_from_job(job=None, stage_name=None, input_file=None, logfile=None, *, skip_jobs_if_failed=False)
stage_from_job(
job: Job,
stage_name: str | None = None,
input_file: Path | None = None,
logfile: Path | None = None,
*,
skip_jobs_if_failed: bool = False,
) -> PipelineStage
stage_from_job(
job: None = None,
stage_name: str | None = None,
input_file: Path | None = None,
logfile: Path | None = None,
*,
skip_jobs_if_failed: bool = False,
) -> Callable[[Job], PipelineStage]
Create a PipelineStage from a single Job.
Can be used as a function or as a decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job | None
|
The Job to wrap in a PipelineStage. If None, returns a decorator. |
None
|
stage_name
|
str | None
|
Name for the stage. Defaults to job name if not provided. |
None
|
input_file
|
Path | None
|
Optional input file for the stage. |
None
|
logfile
|
Path | None
|
Optional logfile for the stage. |
None
|
skip_jobs_if_failed
|
bool
|
Whether to skip remaining jobs if one fails. |
False
|
Returns:
| Type | Description |
|---|---|
PipelineStage | Callable[[Job], PipelineStage]
|
PipelineStage or decorator function. |
Examples:
As a function:
>>> stage = stage_from_job(my_job, stage_name="my_stage")
As a decorator:
>>> @stage_from_job(stage_name="my_stage")
... @jobify(name="my_job")
... def my_function():
... pass
Source code in deet/data_models/pipeline.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
processed_gold_standard_annotations
Data models for procesed annotation data.
ProcessedAnnotationData
pydantic-model
Bases: ProcessedAttributeData, Generic[AttributeTypeVar, DocumentTypeVar, GoldStandardAnnotationTypeVar, GoldStandardAnnotatedDocumentTypeVar]
Structured result from annotation processing.
This model provides a clean, validated structure for all processed annotation data with useful properties and methods.
Fields:
-
attributes(list[AttributeTypeVar]) -
documents(list[DocumentTypeVar]) -
annotations(list[GoldStandardAnnotationTypeVar]) -
annotated_documents(list[GoldStandardAnnotatedDocumentTypeVar]) -
attribute_id_to_label(dict[int, str])
Source code in deet/data_models/processed_gold_standard_annotations.py
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 | |
total_annotated_documents
property
Total number of documents with annotations.
total_annotations
property
Total number of annotations processed.
total_documents
property
Total number of documents processed.
export_linkage_mapper_csv(file_path)
Export a csv mapper to link document IDs and filenames.
Source code in deet/data_models/processed_gold_standard_annotations.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
get_annotations_by_annotation_type(annotation_type)
Get all annotations of a specific type (human/llm).
Source code in deet/data_models/processed_gold_standard_annotations.py
308 309 310 311 312 313 314 | |
get_attribute_by_id(attribute_id)
Get an attribute by its ID.
Source code in deet/data_models/processed_gold_standard_annotations.py
316 317 318 319 320 321 | |
get_attributes_by_attribute_type(attribute_type)
Get all attributes of a specific type.
Source code in deet/data_models/processed_gold_standard_annotations.py
293 294 295 296 297 298 299 | |
get_documents_with_annotations()
Get only documents that have annotations.
Source code in deet/data_models/processed_gold_standard_annotations.py
301 302 303 304 305 306 | |
ProcessedAttributeData
pydantic-model
Bases: BaseModel, Generic[AttributeTypeVar]
Structured result from annotation processing.
Contains only attributes, so the ProcessedAnnotationData class can subclass this
Fields:
-
attributes(list[AttributeTypeVar])
Source code in deet/data_models/processed_gold_standard_annotations.py
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 | |
total_attributes
property
Total number of attributes processed.
export_attributes_csv_file(filepath)
Write a csv file containing all attributes for prompt population.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path
|
outfile path. |
required |
Source code in deet/data_models/processed_gold_standard_annotations.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
populate_custom_prompts(method, filepath=None, **kwargs)
Populate custom prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | None
|
infile path. |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if method is file and there's no filepath. |
Source code in deet/data_models/processed_gold_standard_annotations.py
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 | |
ProcessedEppiAnnotationData
pydantic-model
Bases: ProcessedAnnotationData[EppiAttribute, EppiDocument, EppiGoldStandardAnnotation, EppiGoldStandardAnnotatedDocument]
Structured result from EPPI annotation processing.
This differs from Base ProcessedAnnotationData by specifying raw_data as an EppiRawData object
Fields:
-
attributes(list[AttributeTypeVar]) -
documents(list[DocumentTypeVar]) -
annotations(list[GoldStandardAnnotationTypeVar]) -
annotated_documents(list[GoldStandardAnnotatedDocumentTypeVar]) -
attribute_id_to_label(dict[int, str]) -
raw_data(EppiRawData | None)
Source code in deet/data_models/processed_gold_standard_annotations.py
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 | |
populate_custom_prompts(method, filepath=None, **kwargs)
Populate custom prompts, then recompute each annotation's raw_data.
An EPPI Report.json (or similar) only carries EPPI-Reviewer field names;
it does not set each attribute's output_data_type in DEET. Ingested
attributes default to bool from the codeset. The custom prompt
definition file (e.g. a CSV with output_data_type such as
string or bool) is the source of those types, not the JSON. After
the base method updates prompts and types, we re-apply
eppi_output_data_from_eppi_fields so raw_data matches
AdditionalText and the updated type (e.g. "32" for a string count,
not boolean True from initial ingest only).
Source code in deet/data_models/processed_gold_standard_annotations.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
evaluators
gold_standard_llm_evaluator
Generalisable evaluation module for comparing data extracted by LLMs with data extracted by hand.
GoldStandardLLMEvaluator
A class to manage the evaluation of LLM-extracted data against "gold-standard" ground truth data.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
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 | |
__init__(gold_standard_annotated_documents, llm_annotated_documents, attributes, extraction_run_id, custom_metrics=None)
Initialise GoldStandardLLMEvaluator with a list of ground truth and LLM-generated data to compare, along with the attributes you want to compare.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
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 | |
add_custom_metrics(custom_metrics)
Add custom metrics. These must be valid metrics from sklearn.metrics.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
display_metrics()
Print metrics in a nice table to the command line.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
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 | |
evaluate_llm_annotations()
Compare a list of human annotations to those generated by llms. Return a list of AttributeMetric objects.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
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 | |
export_llm_comparison(filepath)
Export a comparison CSV for gold vs LLM per document and attribute.
Columns include identifiers, EPPI-oriented fields, extractions, LLM verbatim,
fuzzy grounding scores (against the LLM annotated document's context),
and run id.
Column semantics:
attribute_presence: Whether the gold annotation is present.human_additional_text/item_attribute_full_text_details: Taken from the eppi json file when present; empty when absent.human_extraction: Actual ground truth to be extracted.human_verbatim_fuzzy_match_pct: Grounding ofhuman_additional_textagainst the LLM annotated document'scontext.llm_verbatim_text/llm_verbatim_fuzzy_match_pct: LLMadditional_textand its grounding against the samecontext.
Example row (illustrative types): attribute_presence is the string
"True" or "False"; human_verbatim_fuzzy_match_pct and
llm_verbatim_fuzzy_match_pct are decimal strings (e.g. "100.00",
"87.50"); human_extraction / llm_extraction serialize according to
the attribute's coerced value (e.g. bool, int, or str) as written by
:class:csv.DictWriter.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
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 | |
write_metrics_to_csv(filepath)
Save metrics to csv.
Source code in deet/evaluators/gold_standard_llm_evaluator.py
266 267 268 269 270 271 272 | |
exceptions
Custom exceptions.
BadDocumentIdError
Bases: Exception
Raise when our Document.document_id field
doesn't satisfy our criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
description |
required |
Source code in deet/exceptions.py
101 102 103 104 105 106 107 108 109 | |
DuplicateAnnotationError
Bases: Exception
Raise when multiple annotations for a single attribute are present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/exceptions.py
16 17 18 19 20 21 22 23 | |
EmptyPdfExtractionError
Bases: Exception
Raise when PDF parsing yields no extractable text.
Occurs when the PDF has no mappable text (e.g. image-only) or when text is represented in a way pdfminer cannot decode.
Source code in deet/exceptions.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
FileParserMismatchError
Bases: Exception
Raise when we have an input-file <> parser mismatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/exceptions.py
56 57 58 59 60 61 62 63 | |
InvalidFileTypeError
Bases: Exception
Raise when user supplies a not permitted file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/exceptions.py
46 47 48 49 50 51 52 53 | |
InvalidInputFileTypeError
Bases: Exception
Raise when user supplies a not permitted input file type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/exceptions.py
26 27 28 29 30 31 32 33 | |
InvalidOutputFileTypeError
Bases: Exception
Raise when user supplies a not permitted output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/exceptions.py
36 37 38 39 40 41 42 43 | |
JsonStyleError
Bases: Exception
Raise when a json containing document-reference-linkages is incorrectly formatted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
description |
required |
Source code in deet/exceptions.py
112 113 114 115 116 117 118 119 120 | |
LitellmModelNotMappedError
Bases: Exception
Raised when litellm reports the model is missing from its registry.
litellm.get_max_tokens can raise a bare Exception with a
characteristic message; we translate that to this type so callers can
handle it without a broad except Exception.
Source code in deet/exceptions.py
161 162 163 164 165 166 167 168 | |
MalformedLanguageError
Bases: Exception
Raise when language checker fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
description |
required |
Source code in deet/exceptions.py
66 67 68 69 70 71 72 73 | |
MissingCitationElementError
Bases: Exception
Raise when required element of citation is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
description |
required |
Source code in deet/exceptions.py
91 92 93 94 95 96 97 98 | |
MissingDocumentError
Bases: Exception
Raise when looking up a document by id fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/exceptions.py
6 7 8 9 10 11 12 13 | |
NoAbstractError
Bases: Exception
Raise when we can't find an abstract in our citation info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
description |
required |
Source code in deet/exceptions.py
123 124 125 126 127 128 129 130 | |
UnsupportedEppiAttributeTypeError
Bases: ValueError
Raised when EPPI AdditionalText / Codes mapping cannot handle an attribute type.
Subclasses :class:ValueError so existing except ValueError call sites remain
valid while allowing targeted handling via UnsupportedEppiAttributeTypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_data_type
|
AttributeType
|
The :class: |
required |
Source code in deet/exceptions.py
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 | |
__init__(output_data_type, *, message=None)
Store output_data_type and build a default message when omitted.
Source code in deet/exceptions.py
147 148 149 150 151 152 153 154 155 156 157 158 | |
extractors
cli_helpers
Helper functions to run extraction via the CLI.
init_extraction_run(out_dir, run_name)
Set up ID, folder and logging for data extraction run.
Source code in deet/extractors/cli_helpers.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
load_or_init_config(config_path)
Load config, or initialise default config.
Source code in deet/extractors/cli_helpers.py
16 17 18 19 20 21 22 23 24 25 26 | |
prepare_documents(documents, config, linked_document_path, pdf_dir, link_map_path)
Load documents depending on the context type we want.
NOTE: while there are no arg-defaults defined here, when used in cli.py, we populate defaults via typer arg defaults.
If fulltext, try to load linked documents, or create them if not.
Source code in deet/extractors/cli_helpers.py
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 | |
llm_data_extractor
Generalisable data extraction module for LLM-based document analysis.
DataExtractionConfig
pydantic-model
Bases: BaseModel
Configuration for data extraction tasks.
Fields:
-
model(str) -
provider(LLMProvider) -
temperature(float) -
max_tokens(int | None) -
default_context_type(ContextType) -
max_context_tokens(int | None) -
truncate_on_overflow(bool) -
prompt_config(PromptConfig) -
include_reasoning(bool) -
include_additional_text(bool)
Validators:
Source code in deet/extractors/llm_data_extractor.py
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 | |
default_context_type = ContextType.FULL_DOCUMENT
pydantic-field
Type of context to provide
include_additional_text = True
pydantic-field
Include additional text/citations in output
include_reasoning = True
pydantic-field
Include reasoning in output
max_context_tokens
pydantic-field
Maximum context length in tokens (total payload: system + attributes + context). None = infer from model. Override to manage costs.
prompt_config
pydantic-field
Prompt configuration
truncate_on_overflow = False
pydantic-field
When True, automatically truncate context that exceeds max_context_tokens. When False (default), raise ValueError.
populate_max_context_tokens_from_model()
pydantic-validator
Populate max_context_tokens from model when not set.
Source code in deet/extractors/llm_data_extractor.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
LLMDataExtractor
Generalisable module for LLM-based data extraction from documents.
This module provides a flexible interface for extracting structured data from documents using LLMs, with support for different context types and customizable prompts.
Source code in deet/extractors/llm_data_extractor.py
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 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 486 487 488 489 490 491 492 493 494 495 496 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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
__init__(config, custom_system_prompt_file=None, *, show_litellm_debug_messages=False)
Initialise the data extraction module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DataExtractionConfig
|
config obj for data extraction run |
required |
custom_system_prompt_file
|
Path | None
|
path to non-defualt |
None
|
show_litellm_debug_messages
|
bool
|
show verbose litellm logs. |
False
|
Source code in deet/extractors/llm_data_extractor.py
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 | |
extract_from_document(attributes, filter_attribute_ids=None, *, payload=None, md_path=None, context_type=None)
Extract data from a single document.
Call with either payload (document text) or md_path (path to markdown file). If md_path is provided, the file is read and used as the payload. Prompt payloads are not written here; the batch entry point extract_from_documents writes them to prompt_outfile when provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes
|
list[Attribute]
|
List of attributes to extract. |
required |
payload
|
str | None
|
Document text to extract from. Required if md_path not set. |
None
|
md_path
|
Path | None
|
Path to a markdown file to read as payload. Required if payload not set. |
None
|
context_type
|
ContextType | None
|
Override config context type; if None, use config default. |
None
|
Returns:
| Type | Description |
|---|---|
DocumentExtractionResult
|
DocumentExtractionResult with annotations, messages, token counts, |
DocumentExtractionResult
|
cost, model name, and timestamp. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no attributes are selected for extraction after filtering. |
ValueError
|
If neither payload nor md_path provided, or both provided. |
Source code in deet/extractors/llm_data_extractor.py
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 | |
extract_from_documents(attributes, documents, filter_attribute_ids=None, output_file=None, context_type=None, prompt_outfile=None, *, show_progress=False)
Extract data from all documents.
Loops over documents and extracts data using list of attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes
|
list[Attribute]
|
List of attributes to extract. |
required |
documents
|
Sequence[Document]
|
Sequence of Document instances (required). |
required |
filter_attribute_ids
|
list[int] | None
|
Optional list of attribute IDs to filter by. |
None
|
output_file
|
Path | None
|
Optional path to save combined results JSON. |
None
|
context_type
|
ContextType | None
|
Override config context type; if None, use config default. |
None
|
prompt_outfile
|
Path | None
|
Optional path to write a single JSON object: keys are document IDs, values are prompt payload (messages). |
None
|
show_progress
|
bool
|
Whether to show a progress bar. |
False
|
Returns:
| Type | Description |
|---|---|
ExtractionRunOutput
|
ExtractionRunOutput containing annotated documents and run metadata. |
Source code in deet/extractors/llm_data_extractor.py
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 | |
PromptConfig
pydantic-model
Bases: BaseModel
Configuration for prompts used in data extraction.
Fields:
-
system_prompt(str | Path)
Validators:
Source code in deet/extractors/llm_data_extractor.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
system_prompt
pydantic-field
System prompt that defines the task and role
load_system_prompt_file()
pydantic-validator
Load system prompt from file if Path provided.
Source code in deet/extractors/llm_data_extractor.py
68 69 70 71 72 73 74 75 76 77 78 | |
default_system_prompt()
Get default system prompt included in the package.
Source code in deet/extractors/llm_data_extractor.py
53 54 55 | |
logger
Customisations on the loguru logger.
processors
base_converter
Generic classes and functions for converters.
AnnotationConverter
Bases: Generic[DocumentTypeVar, AttributeTypeVar, GoldStandardAnnotationTypeVar, GoldStandardAnnotatedDocumentTypeVar], ABC
Abstract base class to define expected behaviour of an annotationconverter.
OUTFILE_LOADERS maps the outfiles to be read/written to a filename, and a TypeAdapter defining the type of Pydantic Model to read back in.
Source code in deet/processors/base_converter.py
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 | |
outfile_names
property
Return a dictionary of outfiles to names, using outfile_loaders.
processed_data_type
abstractmethod
property
Return the class to use when instantiating processed data.
__init__(base_output_dir=DEFAULT_BASE_OUTPUT_DIR)
Initialise the converter with configurable output paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Base directory for saving processed files |
required | |
attributes_filename
|
Filename for attributes output |
required | |
documents_filename
|
Filename for documents output |
required | |
annotated_documents_filename
|
Filename for annotated documents output |
required | |
attribute_mapping_filename
|
Filename for attribute ID to label mapping |
required |
Source code in deet/processors/base_converter.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
process_annotation_file(file_path, set_attribute_type=None)
abstractmethod
Parse a raw input format into processed data.
Source code in deet/processors/base_converter.py
97 98 99 100 101 102 103 104 | |
reload_output(file_path)
Read data back in, using OUTFILE_LOADERS and the subclass's processed_data_type.
Source code in deet/processors/base_converter.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
write_processed_data_to_file(processed_data, output_dir, outfiles_to_write=None)
Save processed data to structured files using Pydantic model serialisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processed_data
|
ProcessedAnnotationData
|
The processed data from process_annotation_file |
required |
output_dir
|
str | Path
|
Write all output (json) files from conversion to this |
required |
directory. NOTE
|
we output files will live in a sub-directory |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping data types to saved file paths |
Source code in deet/processors/base_converter.py
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 | |
Outfiles
Bases: StrEnum
Enum of all outfiles producable by this module. Extend as required.
Source code in deet/processors/base_converter.py
27 28 29 30 31 32 33 | |
converter_register
A register of supported supported annotation formats and a map to their converters.
SupportedImportFormat
Bases: StrEnum
Supported formats to import gold standard annotation data from.
Source code in deet/processors/converter_register.py
13 14 15 16 17 18 19 20 21 | |
get_annotation_converter()
Return an instance of the parser for the given data type.
Source code in deet/processors/converter_register.py
19 20 21 | |
csv_annotation_converter
Convert annotation CSV files to Pydantic models.
CSVAnnotationConverter
Bases: AnnotationConverter
A class to convert raw CSV (e.g. Covidence) annotations into structured Pydantic models.
This converter operates on flat CSV columns, infers field/column types, and produces attributes, documents, and annotated document records.
Source code in deet/processors/csv_annotation_converter.py
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 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 486 487 488 489 490 491 492 493 494 495 496 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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
processed_data_type
property
Return ProcessedAnnotationData.
__init__(base_output_dir=DEFAULT_BASE_OUTPUT_DIR, attributes_filename=DEFAULT_ATTRIBUTES_FILENAME, documents_filename=DEFAULT_DOCUMENTS_FILENAME, annotated_documents_filename=DEFAULT_ANNOTATED_DOCUMENTS_FILENAME, attribute_mapping_filename=DEFAULT_ATTRIBUTE_MAPPING_FILENAME, config=None)
Initialize the converter output configurations (base directory + filenames) to save the multiple files created during csv processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_output_dir
|
str | Path | None
|
Base directory for saving processed files |
DEFAULT_BASE_OUTPUT_DIR
|
attributes_filename
|
str
|
Filename for attributes output |
DEFAULT_ATTRIBUTES_FILENAME
|
documents_filename
|
str
|
Filename for documents output |
DEFAULT_DOCUMENTS_FILENAME
|
annotated_documents_filename
|
str
|
Filename for annotated documents output |
DEFAULT_ANNOTATED_DOCUMENTS_FILENAME
|
attribute_mapping_filename
|
str
|
Filename for attribute ID to label mapping |
DEFAULT_ATTRIBUTE_MAPPING_FILENAME
|
Source code in deet/processors/csv_annotation_converter.py
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 | |
build_attributes(attribute_fields, rows)
Build a list of Attribute objects from CSV rows and specified attribute
columns.
Infers the AttributeType for each attribute field and assigns a unique ID
to each Attribute.
Source code in deet/processors/csv_annotation_converter.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
build_destiny_reference(row, mapping, source='deet CSV converter')
Convert a CSV row into a ReferenceFileInput for destiny_sdk.reference.
This method extracts bibliographic metadata and abstract content from the
given row using the provided reference field mapping. It constructs
BibliographicMetadataEnhancement and AbstractContentEnhancement
objects, then wraps them in EnhancementFileInput objects, and finally
returns a ReferenceFileInput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
dict
|
Dictionary representing a single CSV row. |
required |
mapping
|
dict[str, Any]
|
Dictionary mapping nested keys (dot-separated strings) to CSV column names. |
required |
source
|
str
|
Optional string indicating the source of the data; defaults to "deet CSV converter" |
'deet CSV converter'
|
Returns: ReferenceFileInput object containing all extracted enhancements
Source code in deet/processors/csv_annotation_converter.py
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 | |
build_documents_and_annotations(attributes, reference_fields, rows)
Build Document objects and their corresponding GoldStandardAnnotatedDocument`s
from CSV rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes
|
list[Attribute]
|
|
required |
reference_fields
|
dict
|
Dictionary mapping reference field labels (as defined in destiny_sdk.enhancements) to CSV column names. |
required |
rows
|
list[dict]
|
List of dictionaries representing all CSV rows. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[Document], list[GoldStandardAnnotatedDocument]]
|
A tuple containing: Document and List[GoldStandardAnnotatedDocument] |
Source code in deet/processors/csv_annotation_converter.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
load_csv(file_path, attribute_fields=None, reference_fields=None)
Load a CSV, normalize headers, and return all column names, attribute names, reference names, and rows.
Source code in deet/processors/csv_annotation_converter.py
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 486 487 488 489 490 491 492 493 494 495 496 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 | |
process_annotation_file(file_path, set_attribute_type=None, attribute_fields=None, reference_fields=None)
Process a complete CSV annotation file and return structured data.
Each row is assumed to represent a document, and columns correspond to different types of fields (metadata, reference information, and attributes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to the CSV annotation file. |
required |
attribute_fields
|
list | None
|
List of column names to be treated as document attributes. |
None
|
reference_fields
|
dict | None
|
Dictionary mapping reference field labels(as defined in |
None
|
Returns:
| Type | Description |
|---|---|
ProcessedAnnotationData
|
ProcessedAnnotationData containing all processed data. |
Source code in deet/processors/csv_annotation_converter.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
CSVParserConfig
pydantic-model
Bases: BaseModel
Configuration Seetings for parsing CSV.
Fields:
-
author_separator(str) -
auto_assign_reference_fields(Boolean)
Source code in deet/processors/csv_annotation_converter.py
71 72 73 74 75 | |
ColumnTypeInferenceError
Bases: Exception
Raised when column type inference fails due to incompatible types.
Source code in deet/processors/csv_annotation_converter.py
67 68 | |
eppi_annotation_converter
Convert annotation JSON files to Pydantic models.
EppiAnnotationConverter
Bases: AnnotationConverter
A class to convert raw EPPI-Reviewer JSON annotations into structured Pydantic models.
This converter handles the complex hierarchical structure of EPPI attributes by flattening them while preserving parent-child relationships through path information.
Source code in deet/processors/eppi_annotation_converter.py
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 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 486 487 488 489 490 491 492 493 494 495 496 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 | |
processed_data_type
property
Return ProcessedEppiAnnotationData.
__init__(base_output_dir=DEFAULT_BASE_OUTPUT_DIR, attributes_filename=DEFAULT_ATTRIBUTES_FILENAME, documents_filename=DEFAULT_DOCUMENTS_FILENAME, annotated_documents_filename=DEFAULT_ANNOTATED_DOCUMENTS_FILENAME, attribute_mapping_filename=DEFAULT_ATTRIBUTE_MAPPING_FILENAME)
Initialise the converter with configurable output paths. Set self.OUTFILE_LOADERS mapping the outfiles to be read/written to a filename, and a TypeAdapter defining the type of Pydantic Model to read back in when deserialising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Base directory for saving processed files |
required | |
attributes_filename
|
str
|
Filename for attributes output |
DEFAULT_ATTRIBUTES_FILENAME
|
documents_filename
|
str
|
Filename for documents output |
DEFAULT_DOCUMENTS_FILENAME
|
annotated_documents_filename
|
str
|
Filename for annotated documents output |
DEFAULT_ANNOTATED_DOCUMENTS_FILENAME
|
attribute_mapping_filename
|
str
|
Filename for attribute ID to label mapping |
DEFAULT_ATTRIBUTE_MAPPING_FILENAME
|
Source code in deet/processors/eppi_annotation_converter.py
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 | |
convert_to_eppi_annotations(annotations_data, attributes_lookup, attribute_id_to_label=None)
Convert several dicts to a list of EppiGoldStandardAnnotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotations_data
|
list[dict[str, Any]]
|
List of human, gold standard annotation dicts from EPPI JSON |
required |
document
|
The document these annotations belong to |
required | |
attributes_lookup
|
dict[int, EppiAttribute]
|
Lookup dictionary for attributes |
required |
attribute_id_to_label
|
dict[int, str] | None
|
Mapping from attribute ID to label |
None
|
Returns:
| Type | Description |
|---|---|
list[EppiGoldStandardAnnotation]
|
List of EppiGoldStandardAnnotation models |
Source code in deet/processors/eppi_annotation_converter.py
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 | |
convert_to_eppi_attributes(flattened_attributes, set_attribute_type=None)
Convert flattened attribute data to EppiAttribute models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flattened_attributes
|
list[dict[str, Any]]
|
List of flattened attribute dictionaries |
required |
Returns:
| Type | Description |
|---|---|
list[EppiAttribute]
|
List of EppiAttribute models |
Source code in deet/processors/eppi_annotation_converter.py
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 | |
dedup_annotations(annotations)
Merge annotations with the same attribute id.
Source code in deet/processors/eppi_annotation_converter.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
flatten_attributes_hierarchy(attributes_list, parent_path='')
Recursively flatten the hierarchical attributes structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes_list
|
list[dict[str, Any]]
|
List of attribute dictionaries from the JSON |
required |
parent_path
|
str
|
Path to the parent attribute (for hierarchy tracking) |
''
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of flattened attribute dictionaries with hierarchy information |
Source code in deet/processors/eppi_annotation_converter.py
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 | |
process_annotation_file(file_path, set_attribute_type=None)
Process a complete annotation file and return structured data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to the JSON annotation file |
required |
set_attribute_type
|
str | AttributeType | None
|
custom AttributeType to set for incoming annotations. |
None
|
Returns:
| Type | Description |
|---|---|
ProcessedEppiAnnotationData
|
ProcessedAnnotationData containing all processed data |
Source code in deet/processors/eppi_annotation_converter.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 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 | |
eppi_output_data_from_eppi_fields(output_data_type, *, additional_text)
Map EPPI evidence onto typed raw_data for coerced output_data.
Glossary
- Codes: Rows under
References[].Codesin EPPI export JSON. Each row means the reviewer applied that code for the reference (e.g. ticked a box). - raw_data: The value stored on
GoldStandardAnnotationbefore / during coercion to the Python type implied by the attribute. - output_data: The coerced, typed value used in evaluation (derived from
raw_data). For EPPI ingest, booleans reflect code presence; other types come from theAdditionalTextfield.
A Code row exists means the attribute was applied. For boolean attributes that is
True even when AdditionalText is empty (the checkbox alone carries the
positive annotation).
For every non-boolean type, only the info-box AdditionalText is used.
ItemAttributeFullTextDetails is not used for the stored value (it may still be
attached to the model for other uses).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_data_type
|
AttributeType
|
Target attribute type (from codeset or prompt CSV). |
required |
additional_text
|
str
|
EPPI |
required |
Returns:
| Type | Description |
|---|---|
EppiRawDataValue
|
Value to store in |
EppiRawDataValue
|
|
EppiRawDataValue
|
|
Source code in deet/processors/eppi_annotation_converter.py
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 | |
linker
Tools for linking references/citations with parsed documents.
DocumentReferenceLinker
Core class for linking references/citations with parsed document text.
Source code in deet/processors/linker.py
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 486 487 488 489 490 491 492 493 494 495 496 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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
__init__(references, document_reference_mapping=None, document_base_dir=None, parser=parser, linking_strategies=None)
Initialise DocumentReferenceLinker class.
Source code in deet/processors/linker.py
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 | |
link_many_references_parsed_documents(*, return_images=False, return_metadata=False)
Link multiple references to parsed documents using available LinkingStrategy(s).
Iterates over linking strategies in hierarchical order, attempting to link each reference-doc to its corresponding file.
If required, parses files. Creates Document objects where is_linked=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
return_images
|
bool
|
Whether to include images in parsed output |
False
|
return_metadata
|
bool
|
Whether to include metadata in parsed output |
False
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of Document objects successfully linked and parsed |
Source code in deet/processors/linker.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
link_reference_parsed_document(reference, parsed_output, original_filepath=None)
staticmethod
Link a reference, in Document format with a parsed document,
in ParsedOutput format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Document
|
the reference, e.g. 'document' from eppi json. |
required |
parsed_output
|
ParsedOutput
|
parser output. |
required |
original_filepath
|
Path | None
|
Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Document |
Document
|
a linked Document with |
Document
|
all required fields populated, and is_linked==True, |
|
Document
|
and required fields' presence validated. |
Source code in deet/processors/linker.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |
DocumentReferenceMapping
pydantic-model
Bases: BaseModel
Data model for incoming, manual mappings of references (via integer ids) to documents, via filename.
Fields:
Validators:
-
ensure_valid_doc_id→document_id -
ensure_file_exists
Source code in deet/processors/linker.py
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 | |
ensure_file_exists()
pydantic-validator
Ensure either md_path or pdf_path are populated, and the associated file exists.
Source code in deet/processors/linker.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
ensure_valid_doc_id(value)
pydantic-validator
Ensure supplied document_id has a valid number of digits.
Source code in deet/processors/linker.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
LinkedInterimPayload
pydantic-model
Bases: DocumentReferenceMapping
Interim output from a linking factory method; extending DocumentReferenceMapping.
Interim as the document may a) still need to be parsed, and b) still needs to be coerced into ParsedOutput.
Fields:
-
document_id(int) -
file_path(Path) -
format(Literal['md', 'pdf'] | None) -
unlinked_document(Document)
Validators:
-
ensure_valid_doc_id→document_id -
ensure_file_exists
Source code in deet/processors/linker.py
86 87 88 89 90 91 92 93 94 95 96 97 | |
LinkingStrategy
Bases: StrEnum
Enum of permitted/implemented ref<>parsed_doc linking strategies.
Source code in deet/processors/linker.py
22 23 24 25 26 27 28 | |
MappingImporter
Tool for importing manual mappings from csv/json to list[DocumentReferenceMapping].
Source code in deet/processors/linker.py
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 | |
__init__(mapping_file_path, document_base_dir=None)
Initialise MappingImporter instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_file_path
|
Path
|
Path to csv/json file containing mappings. |
required |
document_base_dir
|
Path | None
|
Optional directory path |
None
|
Source code in deet/processors/linker.py
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 | |
import_mapping()
Parse a csv/json file to a list od DocumentReferenceMapping objects.
Source code in deet/processors/linker.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
merge_partial_paths(parts_a, parts_b)
staticmethod
Merge partial file path components.
Implements the Knuth-Morris-Pratt (KMP) algorithm. Nice! https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts_a
|
list[str]
|
the longer of the path parts |
required |
parts_b
|
list[str]
|
the shorter of the path parts. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: the merged combined path |
Source code in deet/processors/linker.py
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 | |
parser
Utilities for parsing input files (e.g. pdf) into output files (e.g. md).
DocumentParser
Parse documents from target format to other target format.
Source code in deet/processors/parser.py
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 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 486 487 488 489 490 491 492 493 494 495 496 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 569 570 571 572 573 574 | |
__call__(input_, out_path=None, parser=None, input_type=None, *, return_images=False, return_metadata=False, **kwargs)
Run the parser on one input_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
str | PathLike
|
File(path) or str of input_. |
required |
out_path
|
str | PathLike | None
|
If None, return parsed content as str. |
None
|
parser
|
ParserLibrary | None
|
Defaults to None. If None, uses the default parser. |
None
|
input_type
|
InputFileType | None
|
Defaults to None.
If None, infers file type using |
None
|
return_images
|
bool
|
Defaults to False. Whether to write
parsed images (JPEG) to file, or not. |
False
|
return_metadata
|
bool
|
Defaults to None. Whether to write parsed metadata (json). |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
ParsedOutput
|
ParsedOutput object. |
Source code in deet/processors/parser.py
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 | |
__init__(parsers=DEFAULT_PARSERS)
Initialise instance of DocumentParser with default parsers. Default parsers are in dict.
Source code in deet/processors/parser.py
291 292 293 294 295 296 297 298 299 300 301 302 303 | |
detect_filetype(file, permitted_file_enum_list=None)
staticmethod
Detect file type from a file_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str | PathLike
|
description |
required |
Raises:
| Type | Description |
|---|---|
InvalidInputFileTypeError
|
If file extension isn't permitted. |
Returns:
| Name | Type | Description |
|---|---|---|
InputFileType |
str
|
description |
Source code in deet/processors/parser.py
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 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
parse(input_, parser, *, return_metadata=False, return_images=False, **kwargs)
Parse target file. Wraps around specific parser methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
str | PathLike
|
|
required |
input_type
|
InputFileType
|
|
required |
parser
|
ParserLibrary
|
|
required |
parse_method
|
Callable[[str | PathLike, ParserLibrary], str]
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
ParsedOutput
|
description |
Source code in deet/processors/parser.py
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 | |
write_files(out_path, parser, *, write_metadata, write_images, text, metadata=None, images=None)
staticmethod
Write parsed content to file(s).
NOTE: we are taking existence of out_path as an intention to
write all requested objects to file. out_path can be a file or a dir.
if out_path is a file, we write remaining files to parent dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_path
|
str | PathLike
|
description |
required |
write_metadata
|
bool
|
description |
required |
write_images
|
bool
|
description |
required |
text
|
str
|
description |
required |
metadata
|
dict | None
|
description. Defaults to None. |
None
|
images
|
dict[str, Image] | None
|
description. Defaults to None. |
None
|
Source code in deet/processors/parser.py
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 569 570 571 572 573 574 | |
InputFileType
Bases: StrEnum
Enumeration of permitted input file types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
StrEnum
|
_type_
|
|
required |
Source code in deet/processors/parser.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
MarkerParser
Bases: ParserLibrary
Parser with marker backend.
Source code in deet/processors/parser.py
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 | |
clear_cache()
classmethod
Clear the cached converter.
Source code in deet/processors/parser.py
190 191 192 193 194 | |
parse(input_, *, return_metadata=False, return_images=False, **kwargs)
classmethod
Parse file using marker.
Source code in deet/processors/parser.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
OutputFileType
Bases: StrEnum
Enumeration of permitted output file types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
StrEnum
|
_type_
|
|
required |
Source code in deet/processors/parser.py
53 54 55 56 57 58 59 60 61 62 63 64 | |
PandocParser
Bases: ParserLibrary
Parser with pandoc backend.
Source code in deet/processors/parser.py
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 | |
parse(input_, input_type=None, *, input_is_string=False, return_metadata=False, return_images=False, **kwargs)
classmethod
Parse file using pandoc.
Source code in deet/processors/parser.py
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 | |
ParsedOutput
pydantic-model
Bases: BaseModel
Output returned from the parser() method of subclasses of ParserLibrary.
Contains
text, str: md-formatted parsed text (required) images, pillow.img: pillow-formatted image(s) (optional) metadata, dict: metadata json (optional) timestamp: datetime: auto-populates with now parser_library: str: name of the ParserLibrary implementation used
Config:
arbitrary_types_allowed:True
Fields:
-
text(str) -
images(dict[str, Image] | None) -
metadata(dict | None) -
timestamp(datetime) -
parser_library(Literal['pandoc', 'marker', 'pdfminer', 'unknown'])
Validators:
-
assess_language_quality→text
Source code in deet/processors/parser.py
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 | |
assess_language_quality(value)
pydantic-validator
Assess language quality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Parsed text. |
required |
Raises:
| Type | Description |
|---|---|
MalformedLanguageError
|
If threshold not met. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
parsed text. |
Source code in deet/processors/parser.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
ParserLibrary
Bases: ABC
Base parser class.
Source code in deet/processors/parser.py
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 | |
parse(input_, *, return_metadata=False, return_images=False, **kwargs)
abstractmethod
classmethod
Parse a document. Intentionelly left blank as this should be populated in sub-classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
str | PathLike
|
Path to input file or string of input string. |
required |
return_metadata
|
bool
|
Return json metadata. Defaults to False. |
False
|
return_images
|
bool
|
Return images in doc. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The default, should never actually come. |
Returns:
| Type | Description |
|---|---|
ParsedOutput
|
str | tuple[str, Any, Any]: There will always be str, but sometimes more. |
Source code in deet/processors/parser.py
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 | |
PdfminerParser
Bases: ParserLibrary
Parser with pdfminer.six backend. Fast text extraction, no images or metadata.
Source code in deet/processors/parser.py
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 | |
parse(input_, *, return_metadata=False, return_images=False, **kwargs)
classmethod
Parse file using pdfminer.six (no OCR).
Source code in deet/processors/parser.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 | |
scripts
Scripts for data extraction evaluation toolkit.
cli
A CLI app to run deet pipelines.
export_config_template(output_path=DEFAULT_CONFIG_PATH)
Export the default DataExtractionConfig to a YAML file.
Source code in deet/scripts/cli.py
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 | |
extract_data(gs_data_path, config_path=DEFAULT_CONFIG_PATH, gs_data_format=DEFAULT_IMPORT_FORMAT, prompt_population=None, csv_path=None, linked_document_path=DEFAULT_LINKED_DOCUMENTS_PATH, link_map_path=None, pdf_dir=DEFAULT_PDF_PATH, out_dir=DEFAULT_EXPERIMENT_OUT_DIR, run_name='', custom_evaluation_metrics=None)
Extract data from documents and evaluate.
Load gold standard annotation data, and use an LLM to extract data from the documents in your dataset. Evaluate by comparing the results to the gold standard data.
Source code in deet/scripts/cli.py
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 | |
global_options(*, verbose=typer.Option(default=False, help='Display verbose logs.'))
Set global options for all deet commands.
Source code in deet/scripts/cli.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
init_linkage_mapping_file(gs_data_path, gs_data_format=DEFAULT_IMPORT_FORMAT, link_map_path=DEFAULT_LINK_MAP)
Create a mapping to link documents and their full texts.
Source code in deet/scripts/cli.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
init_prompt_csv(gs_data_path, gs_data_format=DEFAULT_IMPORT_FORMAT, csv_path=DEFAULT_PROMPT_DEFINITION_PATH)
Write a csv to define prompts for your dataset with.
This writes a row for each attribute in your dataset. Edit the prompt column to edit the prompt to be used for that attribute. Attributes without values in the prompt column will not be extracted.
Source code in deet/scripts/cli.py
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 | |
link_documents_fulltexts(gs_data_path, link_map_path=DEFAULT_LINK_MAP, gs_data_format=DEFAULT_IMPORT_FORMAT, pdf_dir=DEFAULT_PDF_PATH, output_path=DEFAULT_LINKED_DOCUMENTS_PATH)
Link documents to their fulltexts.
This creates a document containing the parsed output of its corresponding
fulltext in the folder defined in output_path. Linking will be
attempted using a mapping file, if provided, then by matching the
filename with author and year, then by matching by document id. See
deet.processors.linker for more details.
Source code in deet/scripts/cli.py
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 | |
main()
Run CLI app.
Source code in deet/scripts/cli.py
418 419 420 | |
test_llm_config(config_path=DEFAULT_CONFIG_PATH)
Test llm config.
Source code in deet/scripts/cli.py
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 | |
settings
App settings using pydantic-settings.
DataExtractionSettings
Bases: BaseSettings
Settings model for data extraction behavior and provider credentials.
All fields are fully typed and documented. Unknown environment variables are forbidden to help catch configuration drift early.
Source code in deet/settings.py
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 | |
LLMProvider
Bases: StrEnum
Supported LLM Providers.
Source code in deet/settings.py
21 22 23 24 25 | |
Runtime
Bases: StrEnum
Permitted runtime environments for DEET.
Source code in deet/settings.py
11 12 13 14 15 16 17 18 | |
get_settings()
cached
Return a cached settings instance for reuse across the process.
Source code in deet/settings.py
101 102 103 104 | |
utils
assess_text_quality
Tools for text quality assessments.
EmptyTextError
Bases: Exception
Raise when our text passed to is_english is empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Exception
|
_type_
|
|
required |
Source code in deet/utils/assess_text_quality.py
41 42 43 44 45 46 47 48 49 50 51 52 | |
__init__(msg='Supplied text is empty.', *args, **kwargs)
Init the exception with default message.
Source code in deet/utils/assess_text_quality.py
50 51 52 | |
Language
Bases: Enum
Enum of languages for quality-checking.
Source code in deet/utils/assess_text_quality.py
16 17 18 19 | |
check_language(text, lang=Language.ENGLISH, threshold=0.2)
Assess if text is in the specified language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to assess. |
required |
lang
|
Language
|
Language to check against. |
ENGLISH
|
threshold
|
float
|
Threshold for word overlap. |
0.2
|
Raises:
| Type | Description |
|---|---|
EmptyTextError
|
If text is empty. |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if text matches language, False otherwise. |
Source code in deet/utils/assess_text_quality.py
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 | |
get_bc_brown_words()
Get bc_brown words, cached.
Source code in deet/utils/assess_text_quality.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
is_english(text, threshold=0.2)
Check if text meets minimum English quality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the text to check. |
required |
threshold
|
float
|
Defaults to 0.2. |
0.2
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if 'English', false if not. |
Source code in deet/utils/assess_text_quality.py
90 91 92 93 94 95 96 97 98 99 100 101 102 | |
cli_utils
Utilities to make help integrate cli with rest of the codebase.
echo_and_log(message, **kwargs)
Echo (in typer) and log (via logger) a message simultaenously.
NOTE: pass typer-style stuff via kwargs.
Source code in deet/utils/cli_utils.py
27 28 29 30 31 32 33 34 | |
fail_with_message(message)
Print message and exit CLI.
Source code in deet/utils/cli_utils.py
37 38 39 40 | |
optional_progress(iterable, *, show_progress=False, label='Processing')
Context manager that yields an iterable. If show_progress is True, wraps it in a Typer progress bar. Otherwise, yields it unchanged.
Source code in deet/utils/cli_utils.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
destiny_utils
Utilities for working with destiny data types.
ReferencePresenter
A class to present references in a Streamlit application.
Source code in deet/utils/destiny_utils.py
14 15 16 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 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 | |
abstract
property
Returns the abstract of the reference.
authors
property
Returns the authors of the reference as a semi-colon-separated string.
bibliographic_metadata
property
Returns the bibliographic metadata enhancement of the reference.
doi
property
Returns the DOI of the reference.
first_author
property
Returns the first author of the reference.
location
property
Returns the location enhancement of the reference.
orcids
property
Returns all available ORCIDs for each author of the reference as a semi-colon-separated string.
publication_date
property
Returns the publication date of the reference in 'dd mmm yyyy' format.
publication_links
property
Returns the publication location links of the reference as a semi-colon-separated string.
publication_locations
property
Returns the publication locations of the reference as a semi-colon-separated string.
publication_types
property
Returns the publication types of the reference as a semi-colon-separated string.
publisher
property
Returns the publisher of the reference.
taxonomy
property
Returns the taxonomy labels of the reference as a semi-colon-separated string of tuples.
title
property
Returns the title of the reference.
topic_domains
property
Returns the topic domain labels of the reference and their id links as a semi-colon-separated string of tuples.
topic_fields
property
Returns the topic field labels of the reference and their id links as a semi-colon-separated string of tuples.
topic_sub_fields
property
Returns the topic sub-field labels of the reference and their id links as a semi-colon-separated string of tuples.
topics
property
Returns the topic labels of the reference and their id links as a semi-colon-separated string of tuples.
year
property
Returns the publication year of the reference.
__init__(reference)
Init the ReferencePresenter class.
Source code in deet/utils/destiny_utils.py
17 18 19 | |
to_dict()
Convert the reference to a dictionary suitable for DataFrame representation.
Source code in deet/utils/destiny_utils.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
identifier_utils
Utility functions for creating, validating and manipulating identifiers.
check_if_id_exists(new_id, id_list)
Check if target id (int) is in a list of ids (list[int]).
Source code in deet/utils/identifier_utils.py
55 56 57 | |
hash_n_strings_to_document_id(string_list)
Convert n strings into an integer with MIN_DOCUMENT_ID-MAX_DOCUMENT_ID digits (4-10) using hash-based combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string_list
|
list[str]
|
a list of strings to hash. |
required |
Returns:
| Type | Description |
|---|---|
int
|
An integer with between MIN_DOCUMENT_ID-MAX_DOCUMENT_ID digits |
int
|
(from 1000 to 9999999999). |
Source code in deet/utils/identifier_utils.py
11 12 13 14 15 16 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 | |
tokenisation
Token counting and truncation utilities for LLM context management.
count_tokens(model, text)
Count the number of tokens in text for a given model.
Uses litellm.token_counter with messages format. Falls back to a rough character-based estimate (len/4) for unknown models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model identifier for tokenizer selection. |
required |
text
|
str
|
Text to count tokens for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of tokens. |
Source code in deet/utils/tokenisation.py
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 | |
estimate_cost_usd(model, prompt_tokens=0, completion_tokens=0)
Estimate cost in USD for prompt and completion tokens.
Uses litellm's cost_per_token. Returns (prompt_cost_usd, completion_cost_usd).
Either or both may be None if the model is unknown or the call fails.
Any other Exception from litellm (e.g. provider HTTP errors) is logged
at debug and also yields (None, None) so cost estimation stays
best-effort for callers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model identifier (e.g. "gpt-4o-mini", "azure/gpt-4o-mini"). |
required |
prompt_tokens
|
int
|
Number of input/prompt tokens. |
0
|
completion_tokens
|
int
|
Number of output/completion tokens. |
0
|
Returns:
| Type | Description |
|---|---|
tuple[float | None, float | None]
|
Tuple of (prompt_cost_usd, completion_cost_usd). Either can be None. |
Source code in deet/utils/tokenisation.py
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 | |
get_model_max_tokens(model)
Get the maximum input tokens allowed for a model.
Uses litellm's model registry. Returns None if the model is unknown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model identifier (e.g. "gpt-4o-mini", "azure/gpt-4o-mini"). |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Maximum input tokens, or None if model not found. |
Raises:
| Type | Description |
|---|---|
LitellmModelNotMappedError
|
When litellm raises a bare |
Exception
|
Any other error from litellm is re-raised. |
Source code in deet/utils/tokenisation.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 | |
merge_prompt_completion_cost_usd(prompt_cost_usd, completion_cost_usd)
Combine litellm prompt and completion cost parts into a single total.
Either part may be None when the model table lacks that component or estimation failed for that side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_cost_usd
|
float | None
|
Estimated USD cost for prompt tokens, or None. |
required |
completion_cost_usd
|
float | None
|
Estimated USD cost for completion tokens, or None. |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
Sum when at least one part is known, otherwise None. |
Source code in deet/utils/tokenisation.py
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 | |
truncate_to_token_limit(text, model, max_tokens)
Truncate text to fit within a token limit.
Encodes text, truncates the token list, decodes back to string. Uses char-based fallback when encode/decode unavailable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to truncate. |
required |
model
|
str
|
Model identifier for tokenizer. |
required |
max_tokens
|
int
|
Maximum tokens allowed for the truncated text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Truncated text. |
Source code in deet/utils/tokenisation.py
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 | |