Move pymupdf4llm layout labels to the mapper layer; native HTML table grounding#3
Open
veget-able wants to merge 1 commit into
Open
Conversation
…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>
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
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.
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_pagesarchitecture (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.boxclasslabels; a registeredPyMuPDF4LLMLabelMapper(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.<table>(e.g. a pipeline opting intotable_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._SCALE=1000round-trip (numeric no-op, proven to 1e-9; matches peer adapters).Verification
create_layout_adapter_for_resulton 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
mappers.py/adapters.py: clean with both Add pymupdf4llm_html_tables pipeline (thread table_output=html through the provider) #1 and Shape PyMuPDF4LLM OCR config for upstream: reactive failure, declarative config #2.