Skip to content

fix: deduplicate nested layout regions after disjoint candidates - #536

Open
pcbeingused333 wants to merge 2 commits into
Unstructured-IO:mainfrom
pcbeingused333:fix/c3713-layout-dedup
Open

pcbeingused333 wants to merge 2 commits into
Unstructured-IO:mainfrom
pcbeingused333:fix/c3713-layout-dedup

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 18, 2026 •

Copy link
Copy Markdown

Layout deduplication stops when the largest candidate contains no later regions. A smaller candidate can still contain duplicates, so a disjoint larger region causes those nested duplicates to survive. This also affects class-specific cleanup.

Remove the early exit in both cleanup loops so remaining candidates are examined. Add regression coverage for both helpers and the detection model's deduplication entry point, checking coordinates, text, and class IDs. Update the dense reference and allocation assertions to account for visiting all remaining candidates. Bump the version and changelog as required by the contribution checklist.

For example, boxes [0, 0, 100, 100], [110, 0, 130, 20], and [111, 1, 112, 2] form one padded detection group. Cleanup now keeps the first two and removes the nested third box.

Removing the early exit means N disjoint regions in one group require N−1 bounded comparisons instead of one (measured locally with 10,000 disjoint regions: about 3 ms → 0.8 s); memory remains linear.

Testing and validation

  • Three regression cases fail before the fix and pass afterward.
  • Focused cleanup, allocation, element, and attribute tests: 138 passed, 1 skipped, including test_detection_model_pipeline_preserves_connected_regions_and_routing.
  • Command: PYTHONPATH=. python -m pytest -q test_unstructured_inference/inference/test_layout_cleanup_nested.py test_unstructured_inference/inference/test_layout_cleanup_memory.py test_unstructured_inference/inference/test_layout_element.py test_unstructured_inference/test_elements.py.

AI assistance was used to prepare this change and its tests.

View guided diff

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