Skip to content

test LSTM choice wrapping independently of OCR scores - #392

Merged
sirfz merged 1 commit into
sirfz:masterfrom
mvanhorn:fix/295-lstm-choice-wrapper-test
Oct 22, 2026
Merged

sirfz merged 1 commit into
sirfz:masterfrom
mvanhorn:fix/295-lstm-choice-wrapper-test

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Background

The LSTM symbol-choice test fails on Tesseract 5 when an alternative score is about 3.6, which is above a hard ceiling of 2. The same check passes with Tesseract 4.1. On some Tesseract 4 setups the test instead errors because a timestep comes back with no alternatives.

The test treated recognizer output as part of the wrapper contract. Every score had to fall inside a fixed range, and each word was rebuilt by taking the first symbol of every timestep and compared with the recognized text.

Those ratings and characters come from the engine and its model, and Tesseract 5 reports larger raw ratings, so the old ceiling fails. The first-symbol read also assumes every timestep list is non-empty. In the tree being changed that ceiling is already commented out, while the remaining score floor and string comparison still follow OCR results.

Summary of the fix

  • The test still requires the page-level choice list to have the same length as the recognized words, and that length must be greater than zero.
  • It walks the word iterator, collects each word's LSTM choices, and requires that list to equal the page-level result.
  • Score bounds and rebuilding each word from its top symbol are removed.
  • Both results are checked as lists of per-word lists of per-timestep (symbol, score) pairs, with the symbol a string and the score a float. Empty inner lists are allowed, and the fixture must yield at least one pair.

Verification

Tests for the tesserocr change live in tests/test_api.py.

Fixes #295

The test still requires the page-level choice list to have the same
length as the recognized words, and that length must be greater than
zero. It also walks the word iterator, collects each word's LSTM
choices, and requires that list to equal the page-level result. Score
bounds and rebuilding each word from its top symbol are removed. Both
results are checked as lists of per-word lists of per-timestep (symbol,
score) pairs, with the symbol a string and the score a float; empty
inner lists are allowed, and the fixture must yield at least one pair.

Refs sirfz#295
@sirfz
sirfz merged commit e2398b9 into sirfz:master Oct 22, 2026
@sirfz

sirfz commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thanks

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.

Tesseract 5.0.1 test_LSTM_choices(...) fails

2 participants