unstructured icon indicating copy to clipboard operation
unstructured copied to clipboard

fix: avoid false-positive Title classification for long no-space text

Open claytonlin1110 opened this issue 7 months ago • 2 comments

Summary

  • add a no-space length guard in is_possible_title() to handle CJK text better
  • introduce UNSTRUCTURED_TITLE_MAX_NO_SPACE_LENGTH (default: 40) for tuning
  • add regression tests for Chinese text without spaces (short heading vs long body) Closes #3930

Why

Chinese OCR output often has no spaces, so long narrative text could be interpreted as a single "word" and incorrectly classified as Title. This change reduces those false positives while preserving expected short-title behavior.

Test plan

  • [x] Added unit test coverage in test_unstructured/partition/test_text_type.py
  • [ ] Run: pytest -q test_unstructured/partition/test_text_type.py -k "title or chinese"
  • [ ] Verify OCR-only PDF flow no longer maps long Chinese body text to Title
  • [ ] Sanity-check English title classification is unchanged

[!NOTE] Medium Risk Changes is_possible_title() heuristics for Han-ideograph text, which can affect downstream element classification and chunking behavior; env-default tuning mismatch could surprise users if relied upon implicitly.

Overview Reduces false-positive Title classification for long whitespace-free CJK/Han text by adding a Han-ideograph regex and a max-length guard in is_possible_title() (configurable via UNSTRUCTURED_TITLE_MAX_NO_SPACE_LENGTH).

Adds regression tests covering short Chinese headings vs long Chinese body text and ensuring the new guard doesn’t apply to other no-space scripts. Bumps version to 0.22.28 and documents the fix in CHANGELOG.md.

Reviewed by Cursor Bugbot for commit eda9fe4606dd2f58afb249fd2a06318b0209d418. Bugbot is set up for automated code reviews on this repo. Configure here.

claytonlin1110 avatar Apr 28 '26 20:04 claytonlin1110

@SudSampath Would you please review?

claytonlin1110 avatar May 05 '26 03:05 claytonlin1110

@cragwolfe Would you please review?

claytonlin1110 avatar May 06 '26 06:05 claytonlin1110