Repository navigation
[models] Configurable word confidence aggregation for the recognition models - #2162
Merged
Merged
Conversation
felixdittrich92
marked this pull request as ready for review
October 6, 2026 09:04
felixdittrich92
marked this pull request as draft
October 6, 2026 09:04
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2162 +/- ##
=======================================
Coverage 97.54% 97.55%
=======================================
Files 170 170
Lines 10665 10737 +72
=======================================
+ Hits 10403 10474 +71
- Misses 262 263 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
felixdittrich92
force-pushed
the
aggregation
branch
from
October 9, 2026 07:37
7ec3da7 to
40cf657
Compare
felixdittrich92
marked this pull request as ready for review
October 9, 2026 09:32
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.
Summary
The character probabilities of a recognition model can now be aggregated into the word confidence in different ways:
"mean","min","max","median","geometric_mean"or"harmonic_mean";The method can be set in four places:
confidence_aggregation=...);recognition_predictor,ocr_predictorandkie_predictor(confidence_aggregation=...);--confidence_aggregation);predictor.reco_predictor.model.postprocessor.confidence_aggregation = ....The defaults keep the method each architecture used before:
"min"for CRNN, VIPTR, SAR and MASTER, and"mean"for ViTSTR and PARSeq.Behaviour change of the default confidences
Only the probabilities of the predicted characters are aggregated now:
"min"ran over every frame, blank frames included.0.Decoded words are unchanged. Word confidences only go up, except for empty predictions. ViTSTR and PARSeq are bit-identical to main.
Quality impact on real documents. Setup:
AUROC measures how well the confidence separates correct words from misread ones (higher is better):
Averaged over the 9 models, per method:
min,mean,geometric_meanandharmonic_meanrank errors about equally well, andminis the best calibrated of them.maxandmedianare poor signals, and the docs warn about them.Alternatives that were evaluated and rejected:
Thresholds tuned on the confidences of previous versions may need to be adjusted. The docs contain a note about it.
Changes
doctr/models/_utils.py:aggregate_confidenceand the method resolution.torch.nn.Moduleraise aValueError.groupbyimplementation.<sos>and<pad>decode as multi-character strings.confidence_aggregationis the last argument (aftercfg), so positional calls of previous versions are unchanged.remap_preds/RecognitionPredictor.split_confidence_aggregation("min"by default, as before): aggregates the confidences of the parts of a split wide crop.recognition_predictor,ocr_predictor,kie_predictorand the CLI. A model instance passed to them is modified. Invalid methods are rejected before any model is built.using_models.rst(new section with the behaviour-change note) andusing_cli.rst.Tests
aggregate_confidence: every method, the edge cases and the validation.<pad>, empty words.