Skip to content

Move pymupdf4llm layout labels to the mapper layer; native HTML table grounding#3

Open
veget-able wants to merge 1 commit into
pymupdf:pymupdf4llm-ocr-layoutfrom
veget-able:pymupdf4llm-vg-mapper
Open

Move pymupdf4llm layout labels to the mapper layer; native HTML table grounding#3
veget-able wants to merge 1 commit into
pymupdf:pymupdf4llm-ocr-layoutfrom
veget-able:pymupdf4llm-vg-mapper

Conversation

@veget-able

Copy link
Copy Markdown

Note

Companion to #1 / #2 - independent branches off pymupdf4llm-ocr-layout. New files merge clean with both; the provider/test files have the anticipated trivial adjacency conflicts (resolution notes below).

Summary

Keeps the inline layout_pages architecture (the upstream idiom - reducto/textract/landingai/etc. all do this) and fixes the three places the visual-grounding path diverged from upstream conventions. One commit, 5 files, +241/-64.

  • Class map moves to the label-mapper layer. The provider now emits raw pymupdf4llm boxclass labels; a registered PyMuPDF4LLMLabelMapper (superset of the previous 11-class map) owns label semantics and fails loud (UnknownRawLayoutLabelError) on unknown labels instead of silently dropping them. This matches the adapters=shape / mappers=label-semantics split every other provider uses.
  • Native HTML tables pass through untouched. If grounding content already contains a native <table> (e.g. a pipeline opting into table_output="html", see Add pymupdf4llm_html_tables pipeline (thread table_output=html through the provider) #1), it is used verbatim; the markdown2 conversion remains only as the pipe-table fallback. Attribution token-F1 then scores real table structure rather than a markdown round-trip.
  • Real page dimensions in the layout adapter instead of the synthetic _SCALE=1000 round-trip (numeric no-op, proven to 1e-9; matches peer adapters).

Verification

  • 18 provider/mapper tests pass (14 new); broader providers/parse + evaluation sweep: 179 passed.
  • End-to-end smoke through create_layout_adapter_for_result on a real PDF: raw labels -> canonical classes projected via the mapper; injected unknown label raises; native-<table> preserved verbatim vs pipe-table converted.

Merge notes

…eal dims

Upstream-readiness fixes to the pymupdf4llm visual-grounding path, keeping
the inline layout_pages architecture.

- Provider now emits RAW pymupdf4llm boxclass labels on layout segments and
  no longer drops unknown classes. The DocLayNet class map is removed from
  the provider; label semantics move to the evaluation label-mapper layer.
- Register PyMuPDF4LLMLabelMapper (keys: "pymupdf4llm",
  "model:pymupdf4llm_layout"). It maps raw boxclass labels to CanonicalLabel
  and raises UnknownRawLayoutLabelError on any genuinely unknown class, so a
  new upstream label fails loud at evaluation instead of vanishing.
- Table grounding content: if the sliced content already contains a native
  <table> (e.g. a pipeline opting into table_output="html"), pass it through
  untouched; only fall back to the markdown2 pipe-table conversion otherwise.
  Pure string check, no hard dependency on the table-output branch.
- PyMuPDF4LLMLayoutAdapter now scales segments by the real page dimensions and
  exposes them as image_width/height (mirrors DoclingParseLayoutAdapter),
  replacing the synthetic _SCALE=1000. Numerically a no-op for the normalized
  round-trip.
- Tests: provider emits raw labels + keeps unknowns; native-<table> passthrough
  vs pipe-table conversion; new mapper test (registered, maps known labels,
  raises on unknown, resolver wiring by provider-name and model key).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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