-
Notifications
You must be signed in to change notification settings - Fork 2
Assign OCR to Predictions #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…n overlap algorithm
Scott771
approved these changes
Oct 20, 2025
cd77477 to
68c407d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR expands the
resultsandetloutputAPIs to make it easier use OCR information in Auto Review and Custom Output. This is staged for a newv7.2.2release of the toolkit.Enhancements
The
DocumentExtractionclass has gainedtokens,tables, andcellsattributes that are set byPredictionList.assign_ocr(etl_outputs)using the predictions' spans.Shorthand convenience properties for singular
token,table, andcellaccess like that ofspanare also available.These attributes and properties default to falsey
NULL_TOKEN,NULL_TABLE, andNULL_CELLconstants rather thanNone. This reduces the number of conditional checks needed to make code type-safe, and simplifies the use of.where()and.groupby().Using this API, OCR is assigned once early in code execution, and then accessed directly from predictions thereafter. Tokens and Tables OCR can be selectively assigned to a filtered
PredictionListwhen performance is a concern. OCR can be reassigned if needed after splitting predictions or manipulating spans.Token, Table, and Cell lookups are fast. They jump to a specific page of the document, then bisect the tokens or table cells on that page using span information.
AR/CO Code Comparison
Prior to this PR, predictions and OCR were entirely separate. They were awkward to combine in code,
needed many
with suppress(...):blocks, and duplicated a lot of boilerplate in each function.Particularly common and egregious were the one-liners to sort predictions by OCR bounding box order. This is now greatly simplified. (Code examples assume
predictions.assign_ocr(etl_outputs)has already been called.)Before:
After:
Expanding predictions to their cell's full text is common for dense tabular data. Previously it required many statements to access ETL Output, tokens, tables, and cells. Now it's straightforward.
Before:
After:
Splitting a prediction along cell boundaries was previously very difficult (and required more functions than I'd like to include here). Now it's simple enough for a single function.
After:
Previously some useful operations like "group by table, then by row" could not be expressed using the
PredictionList.groupby()API. Doing so required statements that must be written separately. Only grouping by line was straightforward. The updated API makes both possible and easy to do.Before:
After: