Skip to content

feat: Layout-driven OCR pipeline with configurable OCR modes and refactoring of the OCR GT dir structures#3710

Open
nikos-livathinos wants to merge 60 commits into
mainfrom
nli/layout_driven_pipelines
Open

feat: Layout-driven OCR pipeline with configurable OCR modes and refactoring of the OCR GT dir structures#3710
nikos-livathinos wants to merge 60 commits into
mainfrom
nli/layout_driven_pipelines

Conversation

@nikos-livathinos

@nikos-livathinos nikos-livathinos commented Jun 26, 2026

Copy link
Copy Markdown
Member

Reorders the standard PDF pipeline to be layout-driven and introduces a configurable OcrMode that controls which document regions are fed to the OCR engine. Layout prediction now runs before OCR, so OCR can be targeted at the clusters that actually need it, and layout post-processing is split out into its own pipeline stage.

  • Refactor the code to decouple the layout model and the layout post-processing as separate pipeline stages.
  • Redesign the StandardPdfPipeline to run: Preprocess -> Layout -> OCR -> Layout post-processing -> Table -> Assembly.
  • Introduce OcrMode with the options:
    • FULL_PAGE: Run OCR on the full page. No layout clusters or PDF cells are taken into account.
    • LAYOUT_REGIONS: All detected bounding boxes from the layout model are fed as input to the OCR. No PDF cells are taken into account.
    • PDF_AWARE_LAYOUT_REGIONS: Start with all layout detections and eliminate the ones that overlap with PDF cells that contain exclusively text. If there is any non-text overlapping PDF cell, the layout bbox is not eliminated. Non-overlapping layout bboxes are kept. All non eliminated bboxes are fed as input to the OCR.
    • DEFAULT: Placeholder value. Currently hard-wired to PDF_AWARE_LAYOUT_REGIONS.
  • Refactor the BaseOcrModel.post_process_cells() to introduce the optional parameter priority that controls how the detected OCR cells and the pre-existing PDF cells are merged into the final page cells:
    • PDF_FIRST: PDF_FIRST: The OCR cells are used only if they do not overlap with any PDF cell.
    • OCR_FIRST: The opposite. The PDF cells are used only if they do not overlap with any OCR cell.
    • When priority is not provided (None), it is auto-selected from the OcrMode: OCR_FIRST for LAYOUT_REGIONS, and PDF_FIRST for PDF_AWARE_LAYOUT_REGIONS.
    • The priority parameter is NOT exposed to the OcrOptions.
  • Remove the OcrOptions.bitmap_area_threshold
  • Deprecate the OcrOptions.force_full_page_ocr parameter. Now it is superseded by OcrMode.FULL_PAGE
  • Expose the OcrMode to the CLI via the --ocr-mode parameter:
    • The old --force-ocr is still supported but deprecated.
    • In case both --ocr-mode and --force-ocr are set, --force-ocr wins.

Additionally the OCR ground-truth files were reorganized from a flat, loosely-tagged layout into a structured per-engine / per-mode hierarchy:

  • Renamed tests/data/scanned/ as tests/data/ocr/.
  • GT files now live under groundtruth/<engine>/<mode>/ and are named <doc>.<engine>.<mode>.<suffix> (e.g. ocr_test.tesseract.full_page.json), for each of the four artifacts: .json, .md, .doctags.txt, .pages.meta.json.
  • Regenerated/added GT across the OCR engines and modes.

Update documentation.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…re into the BaseOcrModel

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos self-assigned this Jun 26, 2026
@nikos-livathinos nikos-livathinos marked this pull request as draft June 26, 2026 09:15
@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @nikos-livathinos, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

… separate model

LayoutPostProcessingModel that runs as a separate pipeline stage

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…ore the OCR and the layout

post-processing after the OCR

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos force-pushed the nli/layout_driven_pipelines branch from 57ab040 to 092ef5a Compare June 30, 2026 09:25
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…map cells in green

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@cau-git cau-git changed the title feat: Redesign docling's pipelines feat: Redesign docling PDF pipelines for better OCR Jun 30, 2026
…f cells

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…df cells for generating OCR input

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…n for each OCR mode

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
- PDF_BITMAPS_ONLY: Only bitmaps embedded inside a programmatic PDF
- LAYOUT_DETECTIONS: Layout detections which can bear text
- LAYOUT_DETECTIONS_WITHOUT_PDF_TEXT: Layout detections, without the ones that overlap with
                                      text-bearing pdf cells

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…t clusters

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…de the CODE and FORMULA labels

Make the FILTER_OUT_OVERLAPPING_CLUSTERS a constant in the class rather than an option

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…eter and replace it with the

`OcrOptions.mode == OcrMode.FORCE_FULL_PAGE`

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…S_ONLY

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos force-pushed the nli/layout_driven_pipelines branch from c897627 to a515f28 Compare July 8, 2026 08:41
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…undtruth_paths.py and test_e2e_nemotron_ocr_conversion.py

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
….py and the actual tests to use it

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…R mode

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos changed the title feat: Redesign StandardPdfPipeline pipeline for better OCR feat: Redesign StandardPdfPipeline pipeline for better OCR and refactor test GT files Jul 13, 2026
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos changed the title feat: Redesign StandardPdfPipeline pipeline for better OCR and refactor test GT files feat: Layout-driven OCR pipeline with configurable OCR modes and refactoring of the OCR GT dir structures Jul 13, 2026
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…ly not exposed in API. WIP

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos force-pushed the nli/layout_driven_pipelines branch from 6f6a059 to cae07ea Compare July 13, 2026 16:25
…. Rename code elements.

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…EGIONS OcrMode

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
…g in test_cli.py

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos marked this pull request as ready for review July 15, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant