fix: correct graphics-to-captions assignment in reading order#166
fix: correct graphics-to-captions assignment in reading order#166indoorhill wants to merge 11 commits into
Conversation
|
❌ DCO Check Failed Hi @indoorhill, your pull request has failed the Developer Certificate of Origin (DCO) check. This repository supports remediation commits, so you can fix this without rewriting history — but you must follow the required message format. 🛠 Quick Fix: Add a remediation commitRun this command: git commit --allow-empty -s -m "DCO Remediation Commit for Ethan Hill <5614778+indoorhill@users.noreply.github.com>
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 9e89b7199f5341e6e0373b82595f8979c008b026
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 74311cdc8063bd8e6433249c265b869ed02886fd
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: d7a24c898679de2d7843f9ffedd3fa9ef5d079f4
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 4aad0647cf0db2a7adac1d9bd6b4b75571a5555b
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: a80affc08f9a2243b3b34d0ba58e7a94a6afc865
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 76189231db71c60286ca0b0baa92a41dfdaa478e
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: f43ff6fe4112fe41bd25540706c6060a486e4d51
I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 21f6617ee83ac13c9dd7031b9362bc9641d9756f"
git push🔧 Advanced: Sign off each commit directlyFor the latest commit: git commit --amend --signoff
git push --force-with-leaseFor multiple commits: git rebase --signoff origin/main
git push --force-with-leaseMore info: DCO check report |
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
…ly.github.com> I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 9e89b71 I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 74311cd I, Ethan Hill <5614778+indoorhill@users.noreply.github.com>, hereby add my Signed-off-by to this commit: d7a24c8 Signed-off-by: Ethan Hill <5614778+indoorhill@users.noreply.github.com>
Signed-off-by: Ethan Hill <5614778+indoorhill@users.noreply.github.com>
Signed-off-by: Ethan Hill <5614778+indoorhill@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@indoorhill thanks for this contribution, it looks promising. Can I ask you to create one extra proof please:
Many thanks. |
Replace strict pairwise adjacency with run-scanning in both directions from each caption, then greedily assign by (distance, preceding-first, cid). The nearest graphic wins, ties break toward the preceding graphic; pictures and tables are treated identically. This stops a nearer/lower-cid table from stealing a picture's caption and stops captions from being dropped in dense figure clusters. Tests distilled from the 2203.01017v2.pdf ground truth (docling).
_find_to_captions re-sorted page_elements by cid before pairing. cids are assigned in parse order, so that sort dropped unrelated elements (a table, a page number, a page_footer) between a caption and the graphic it belongs to, orphaning 7 of 15 pictures in 2203.01017v2.pdf. page_elements already arrives in reading order with each caption next to its graphic, so use it as-is. Adds reproductions captured from a real conversion of that PDF (page 1 and the page-13 figure cluster).
|
@cau-git , nice callout. Running the tests that way caught some issues. It does ultimately produce a difference in the GT generated, but i think that the difference is actually more correct than it was prior. I will add a comment with a breakdown of why that is here once I finalize my new edits/refactors. |
- replace the manual probe/step/while walk with reversed/enumerate slices fed to itertools.takewhile - drop the redundant matched_graphics set (to_captions keys already track used graphics) - remove the now-unused defaultdict import Behavior-preserving: identical output on 20k randomized differential cases vs the prior implementation and on the real 2203.01017v2.pdf conversion.
Sort candidates on (distance, side) via itemgetter and rely on the stable sort to keep ties in reading order, instead of sorting the full tuple where the parse-order cids appeared to participate. Proven equivalent: 0 differing results across 50k randomized cases. Makes explicit that reading-order proximity drives pairing and cids never break a tie.
|
alright @cau-git, here is the change. The old groundtruth was missing some caption links that this now fills in/completes for I spot checked two of |
|
@indoorhill thanks for the check! Can you post that test PR to https://github.com/docling-project/docling/pulls so we can inspect the test delta too? (not with the intent to be merged, just for verification. You can make it a draft PR). |
|
@cau-git done :) hopefully thats what you were looking for, let me know if not |
|
@indoorhill I assume you are relating to this: docling-project/docling#3872 The reason why I asked for this is that I wanted to see the changed GT files. Could you please commit the changed GT files you created with the docling-ibm-models update into this draft PR for inspection purposes? Thanks. |
_find_to_captionsfix (#148)Change Description
Rewrites
_find_to_captionsto fix incorrect caption<->figure assignment.The old multi-pass graphic gathering + deduplication could silently drop a caption flanked by graphics on both sides, and let a one-sided caption greedily claim a neighbor's graphic, orphaning the caption between them. This change is the same interface and intended logic as the original implementation.
Notably, this fix
_find_to_captions_remove_overlapping_indexesPerformance -
ds4sd/docling-dpbench(test_readingorder)Sidenote
I use PyCharm and I noticed that the
.gitignoredidn't filter JetBrains IDEs project folder, so I added.idea/to the ignore.Issue resolved by this Pull Request
Resolves #148
Checklist