docling icon indicating copy to clipboard operation
docling copied to clipboard

FAST TableFormer splits a multiline closing-balance row before cell matching (PDF from #4255)

Open denis-samatov opened this issue 2 weeks ago • 1 comments

Bug

On the single-page PDF from #4255, TableFormerMode.FAST preserves the checked amounts but splits the final logical closing-balance row into two exported rows. The English label is in R19; its amounts are in R20. The Chinese label is also split, with its continuation assigned to the English-label column.

The split is already present in the TableFormer OTSL prediction before cell matching. It reproduces with both the base TableFormer source and the source from docling-project/docling-ibm-models#211. In the FAST run, decoding terminates normally and reached_max_steps is false with that PR.

This report follows the suggestion to track the FAST row split separately. Related: #4255. The ACCURATE decoder-cap/content-loss problem is tracked there; the result here concerns the FAST row structure.

Steps to reproduce

  1. Download the public popmart-2025-annual-report-p331.pdf from #4255 (one page, printed page 330). SHA-256: 5cee0b4b2844533cb9cce9298d7451ebf7d2cfbbcdc33c8ad47767f4321eaf17.
  2. To reproduce my exact source selection, download and extract the PR-head source archive. The comparison run used the base source archive.
  3. Save the following as reproduce_fast_row_split.py. Run it using an existing Docling environment with the versions below:
python -B reproduce_fast_row_split.py docling-ibm-models-14e4e420aa10e2781d26a1745c69d3095900961f popmart-2025-annual-report-p331.pdf fast.json

The source-path override below selects the requested TableFormer source while retaining unrelated backends from the installed package. It does not modify the installed package.

"""Reproduce the FAST closing-row split on the PDF from Docling #4255."""
import json
from pathlib import Path
import sys

import docling_ibm_models

# Select TableFormer source without replacing unrelated installed backends.
source_tree = Path(sys.argv[1]).resolve()
docling_ibm_models.__path__ = [
    str(source_tree / "docling_ibm_models"),
    *docling_ibm_models.__path__,
]

from docling.datamodel.accelerator_options import AcceleratorDevice, AcceleratorOptions
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions, TableFormerMode
from docling.document_converter import DocumentConverter, PdfFormatOption
import docling_ibm_models.tableformer.data_management.tf_predictor as predictor

assert Path(predictor.__file__).is_relative_to(source_tree)
options = PdfPipelineOptions()
options.do_ocr = True
options.do_table_structure = True
options.accelerator_options = AcceleratorOptions(
    device=AcceleratorDevice.CPU, num_threads=4
)
options.table_structure_options.mode = TableFormerMode.FAST
options.table_structure_options.do_cell_matching = True

result = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=options)}
).convert(Path(sys.argv[2]))
document = result.document.export_to_dict()
Path(sys.argv[3]).write_text(json.dumps(document, ensure_ascii=False, indent=2))
data = document["tables"][0]["data"]
print("Shape:", data["num_rows"], data["num_cols"], len(data["table_cells"]))
for cell in data["table_cells"]:
    if cell["start_row_offset_idx"] >= 18:
        print(
            f"R{cell['start_row_offset_idx'] + 1}"
            f"C{cell['start_col_offset_idx'] + 1}: {cell['text']}"
        )

I ran this script on the PR-head source and checked that its complete exported document matched my earlier instrumented FAST run.

Expected and actual behavior

Expected: the closing label At 31 December 2024 and 2025, its complete Chinese counterpart 於2024年及2025年12月31日, and 1,342,943,150 | 135 | 882 | - | - belong to one logical row, preserving their columns. Earlier rows should remain unchanged.

Actual: 20 rows × 7 columns, 74 table cells. All coordinates below are 1-based exported grid coordinates, not physical PDF text-line numbers:

Cell Text
R19C1 At 31 December 2024 and 2025
R19C2 於 2024 年及 2025 年 日
R20C1 12 月 31
R20C3 1,342,943,150
R20C4 135
R20C5 882
R20C6 -
R20C7 -

The PDF has the English label on the upper line and the Chinese continuation and amounts about 14 pt lower within the same logical row. Merely checking whether the amounts are present therefore misses this structural error.

Isolation and verification results

  • Capturing the input to CellMatcher.match_cells showed an OTSL nl between these two predicted rows before matching:

    rhed fcel ecel ecel ecel ecel ecel nl
    ecel fcel fcel fcel fcel fcel fcel nl
    
  • The matcher assigns the English label to R19C1 and the amounts to R20C3–C5. Matching post-processing and row-index compression preserve the split. No closing-row span is predicted.

  • The base source (44197944f438aaf6951ff76ba96ac740ab38e6a2) and PR-head source (14e4e420aa10e2781d26a1745c69d3095900961f) produced identical exported document JSON and identical captured matching-stage traces.

  • The unchanged layout crop passed to TableFormer was [138, 278, 1086, 1222] in 2× coordinates. FAST generated 162 tags / 160 OTSL tokens and reached the end token normally; with PR #211 both returned diagnostic flags were false.

  • Separately, I checked the six previously discussed amounts against the source PDF, including both signed/unsigned occurrences of 5,300,000. Their row/column assignments in the preceding rows were correct. Cell-level check.

  • A PDF-specific, source-confirmed reconstruction merged the closing row into R19: move the five R20 entries to R19 without changing their columns or PDF bounding boxes, join the Chinese continuation into C2, and remove the extra row. The result was 19 × 7 with 73 cells. All 66 cells in R1–R18 and the English label in R19C1 were exactly unchanged; document-schema/grid validation and Markdown export checks passed. This used known cells and source text, including normalization of the Chinese label; it is not a validated general automatic repair.

Earlier evidence: prediction/matching trace, targeted reconstruction check.

Scope: verified only on this attached PDF and the environment below. I have not established a first-bad version for this FAST issue, reproduced it on the latest release, or validated the reconstruction on a broader corpus.

Docling version

  • Docling: 2.123.0
  • docling-core: 2.92.0
  • docling-parse: 7.16.0
  • Installed docling-ibm-models metadata: 3.14.0, with TableFormer source overridden per process to the exact base/PR-head commits listed above (not an unmodified 3.14.0 inference run)
  • torch: 2.13.0
  • TableFormer model artifacts: docling-project/docling-models, revision v2.3.0, cached snapshot fc0f2d45e2218ea24bce5045f58a389aed16dc23
  • CPU, 4 threads; OCR enabled (resolved to EasyOCR); table structure and cell matching enabled
  • Runs used existing cached models with HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1

Python version

Python 3.13.5, macOS arm64.

denis-samatov avatar Nov 18 '26 06:11 denis-samatov

Classification labels added: bug, priority:medium, pdf.

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

github-actions[bot] avatar Nov 18 '26 06:11 github-actions[bot]