docling icon indicating copy to clipboard operation
docling copied to clipboard

OCR regression in 2.143.1 (TesseractCli, full-page OCR): words and numbers dropped vs 2.143.0

Open meirakalile-ship-it opened this issue 3 weeks ago • 8 comments

Bug

Starting with 2.143.1, full-page OCR with TesseractCliOcrOptions produces a worse Markdown export for a scanned document than 2.143.0:

  • a 2-digit number in the middle of a sentence is dropped;
  • the last ~6 words of a sentence become a 3-token garbage string;
  • a date in a running header is truncated (dd/mm/yyyy → dd/mm/yy) on two pages;
  • some header/footer lines are merged with the next block.

Same word count (2378 → 2371 tokens), 61 fewer characters, 7 fewer lines, 13 changed line blocks. Some changes are improvements (a truncated word completed, a missing space between two numbers restored), but the losses are content.

Bisection on the same document and config, docling-parse fixed at 7.22.4:

version output vs 2.140.0
2.141.0 identical
2.142.1 identical
2.143.0 identical
2.143.1 different (losses above)
2.145.0 same as 2.143.1
2.149.0 same as 2.143.1

The OCR-related changes in 2.143.1 are #5031 ("Pass render resolution to Tesseract CLI") and the table-token commits affa54c, ce6690b, a65b29e. I have not isolated which one causes it.

Steps to reproduce

from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions, TesseractCliOcrOptions

po = PdfPipelineOptions()
po.do_ocr = True
po.ocr_options = TesseractCliOcrOptions(lang=["por"], force_full_page_ocr=True)
conv = DocumentConverter(format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=po)})
md = conv.convert("input.pdf").document.export_to_markdown()

Run with 2.143.0 and 2.143.1 and diff the output.

The input cannot be shared (confidential government document): 5-page A4 scanned PDF, producer PDFium, one RGB JPEG per page at 200 ppi (1654×2340 px), Portuguese text in justified paragraphs, with running headers/footers, stamps and a table.

Synthetic scan-like pages (same size, 150/200/300 ppi JPEG, noise, slight rotation, similar text) give identical output in 2.143.0 and 2.143.1, so it seems to depend on page content (stamps/tables/scan quality), not on the image format. I can test builds of specific commits or patches on this document and report back.

Bisection runs used torch 2.14.1+cpu, torchvision 0.29.1+cpu, pillow 13.0.0 (the 2.141.0 run resolved pillow 12.3.0). 2.143.0 was re-checked with torch 2.15.0+cpu: still identical to 2.140.0.

Docling version

Docling version: 2.143.1
Docling Core version: 2.106.0
Docling IBM Models version: 4.0.4
Docling Parse version: 7.22.4
Python: cpython-312 (3.12.3)
Platform: Linux-6.8.0-149-generic-x86_64-with-glibc2.39

Python version

Python 3.12.3

meirakalile-ship-it avatar Nov 09 '26 13:11 meirakalile-ship-it

Could I help investigate this? I’d compare the render-resolution and OCR changes between 2.143.0 and 2.143.1, then work toward a shareable fixture for the missing digits and text. Since the original document is confidential, would you be able to test isolated patches against it?

darshpatel1052 avatar Nov 10 '26 15:11 darshpatel1052

Thanks, yes, please. I can test patches or specific commits against the confidential document locally and report back with the diff stats (tokens/characters/lines changed and which kind of content was lost), without sharing the text.

A branch or commit hash is enough; I'll install it in an isolated environment (docling-parse 7.22.4, Tesseract CLI, por, full-page OCR, same config as in the issue).

meirakalile-ship-it avatar Nov 11 '26 11:11 meirakalile-ship-it

Update: I bisected at commit level on the confidential document, swapping only the two PDF OCR files changed in 2.143.1 into a 2.143.0 install (installed files verified byte-identical to v2.143.0 on GitHub):

run tesseract_ocr_cli_model.py table_structure_model.py output
R0 v2.143.0 v2.143.0 identical to 2.143.0
R1 481883301e (#5031) v2.143.0 same as 2.143.1 (byte-identical)
R2 v2.143.0 a65b29e004 identical to 2.143.0
R3 v2.143.0 ce6690b67e identical to 2.143.0
R4 v2.143.0 affa54ce1f identical to 2.143.0
R5 v2.143.0 103edefc99 identical to 2.143.0
R6 481883301e 103edefc99 same as 2.143.1

So the regression comes from #5031 alone: saving the page PNG with dpi=(72*scale, 72*scale) before calling Tesseract CLI. Before that change the PNG had no DPI metadata. The table-token commits have no effect on this document.

Happy to test a candidate fix (e.g. making the DPI hint optional) the same way.

meirakalile-ship-it avatar Nov 11 '26 11:11 meirakalile-ship-it

Update: I bisected at commit level on the confidential document, swapping only the two PDF OCR files changed in 2.143.1 into a 2.143.0 install (installed files verified byte-identical to v2.143.0 on GitHub):

run tesseract_ocr_cli_model.py table_structure_model.py output R0 v2.143.0 v2.143.0 identical to 2.143.0 R1 4818833 (#5031) v2.143.0 same as 2.143.1 (byte-identical) R2 v2.143.0 a65b29e identical to 2.143.0 R3 v2.143.0 ce6690b identical to 2.143.0 R4 v2.143.0 affa54c identical to 2.143.0 R5 v2.143.0 103edef identical to 2.143.0 R6 4818833 103edef same as 2.143.1 So the regression comes from #5031 alone: saving the page PNG with dpi=(72*scale, 72*scale) before calling Tesseract CLI. Before that change the PNG had no DPI metadata. The table-token commits have no effect on this document.

Happy to test a candidate fix (e.g. making the DPI hint optional) the same way.

I took another look at this, especially after your commit-level bisect. The difference seems pretty isolated now: TesseractOcrCliModel.__call__ writes the rendered PNG with dpi=(dpi, dpi), including the rotated-image path, whereas the earlier version didn't embed DPI metadata.

I also noticed test_tesseract_ocr_cli_dpi.py explicitly checks for that metadata, so reverting #5031 outright would break the intended behavior.

Would an opt-out for the embedded DPI hint be a reasonable first fix? I'd keep the current behavior as the default, cover both image-save paths in tests, and use the opt-out to restore the pre-2.143.1 behavior for affected scans.

Since you can test this against the original document, we could verify whether it actually recovers the missing text. That said, I'm not sure whether adding an opt-out is something the maintainers would want to support, so I'd prefer to hear their thoughts on the approach before moving ahead with a PR.

darshpatel1052 avatar Nov 12 '26 19:11 darshpatel1052

Classification labels added: priority:critical, pdf.

These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.

github-actions[bot] avatar Nov 16 '26 15:11 github-actions[bot]

Hi maintainers!

I would love to contribute to the OCR regression reported in this issue.

I have experience building Python-based RAG and PDF document-processing applications, and I'm interested in investigating the Tesseract DPI metadata change and its impact on OCR extraction.

I noticed the ongoing investigation and would be happy to help with regression tests, synthetic PDF fixtures, or an independent investigation of the proposed fix.

Please let me know where I could contribute without duplicating ongoing work.

Thank you!

Saloni248694 avatar Nov 16 '26 15:11 Saloni248694

Here is a public document that reproduces a regression starting in 2.143.1, in case it helps because the original one is confidential. In this case the regression shows up in table structure, not only in running text.

Document: Chilean public-procurement tender 1057544-1-LP26 (mercadopublico.cl), attachment Rex. Nº0510 de fecha 29.01.2026 Adjudicacion.pdf.

  • 13 scanned pages, Spanish.
  • sha256 1c8e2890708a21b640f991c0c19004a3ad98b0ea2b56cc71f2b3822d1117759a.

Config: TesseractCliOcrOptions(lang=["spa","eng"], scale=3.0), CPU, 4 threads, no full-page OCR. Each version ran in a fresh venv with docling-ibm-models 4.0.4 and docling-parse 7.27.0 pinned.

docling p2 inadmissibility table p5 award table md table lines
2.129.0 3×4 (ITEM column: 2, 6-7, 3) 4×4 (header row Proveedor / RUT / Valor Neto Adjudicado / …) 117
2.143.0 same as 2.129.0 (byte-identical Markdown) same 117
2.143.1 3×3: ITEM column gone 3×4: header row gone 119
2.150.1 / 2.151.1 same as 2.143.1 same 119

The lost cells are the small, noisy header and number cells. In 2.150.1 the log also shows MatchingPostProcessor WARNING 3 of 52 pdf cells matched neither a row nor a column band of the 6x5 grid and were dropped from the table.

Not every change is a loss. On other pages of the same document, 2.143.1+ recovers more numeric cells in their own cells (percentages, "valor más IVA" amounts). So the new resolution is better overall, but cell matching drops these columns and rows.

Repro:

from docling.datamodel.accelerator_options import AcceleratorDevice, AcceleratorOptions
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions, TesseractCliOcrOptions
from docling.document_converter import DocumentConverter, PdfFormatOption

o = PdfPipelineOptions()
o.accelerator_options = AcceleratorOptions(num_threads=4, device=AcceleratorDevice.CPU)
o.do_ocr = True
o.ocr_options = TesseractCliOcrOptions(lang=["spa", "eng"], scale=3.0)
conv = DocumentConverter(format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=o)})
doc = conv.convert("adjudicacion.pdf").document
for t in doc.tables:
    if t.prov and t.prov[0].page_no in (2, 5):
        print(t.prov[0].page_no, t.data.num_rows, "x", t.data.num_cols, [c.text for c in t.data.grid[0]])

I'm happy to test patches or commits against it.

marcelomatus avatar Nov 20 '26 00:11 marcelomatus

Thanks for #5564. We tested 2.154.0 on the original confidential scan (5 pages, pure image, Portuguese, TesseractCli, force_full_page_ocr=True):

  • With embed_render_dpi=False, 2.154.0 produces output byte-identical to 2.143.0 when both use the same docling-parse. So the opt-out fixes the regression reported here.
  • However, 2.154.0 requires docling-parse>=7.28.0, and docling-parse 7.28.0 on its own (everything else as in our 2.143.0 setup) drops text on the same document: about 3% of the words, including the page-continuation headers and one full sentence; on a second 24-page scanned document, about 16% fewer characters. 7.22.4 does not show this.

We can test a docling-parse build or commit locally if that helps. We cannot share the document.

meirakalile-ship-it avatar Nov 29 '26 22:11 meirakalile-ship-it