Repository navigation
fix(metrics): score utterances with an empty reference in funasr.metrics.wer - #3779
Merged
LauraGPT merged 1 commit intoOct 18, 2026
Merged
Conversation
…ics.wer print_cer_detail divided by the reference word count, so a single utterance with an empty reference (for example a silent clip) raised ZeroDivisionError and aborted the whole report before the %WER/%SER summary was written. Report that utterance's rates against one word instead; the overall WER is unchanged.
LauraGPT
approved these changes
Oct 18, 2026
LauraGPT
left a comment
Collaborator
There was a problem hiding this comment.
Validated exact head 9ff47d29e1007c0cb6e6677641bb6bdf46cb178b and synthetic merge 33c746408ea2482bd49b9087b41aa60e3a24d18d over protected main e5be9c9827ee139a158c9e87f893275f34ca5e9d.
- Base plus the submitted regression tests: 2 failed with the reproduced
ZeroDivisionError. - Exact head: 2/2 submitted WER regressions and 2/2 adjacent RapidFuzz tests passed.
- Synthetic merge: the same 4/4 tests passed.
- Changed-file compileall and recursive tree reconciliation passed; exactly
funasr/metrics/wer.pyandtests/test_metrics_wer.pydiffer from main.
This is a CPU-only metrics change; no model loading, ASR inference, or GPU runtime behavior is involved. The validation is targeted, not a claim that the full repository suite ran.
The two search matches, closed PRs #3105 and #3114, changed funasr/metrics/common.py aggregate metrics; this PR fixes the separate per-utterance formatter in funasr/metrics/wer.py.
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
python -m funasr.metrics.wercrashes when any utterance in the reference file has an empty transcript (for example a silent clip written as justutt2).print_cer_detaildivides the per-utterance correct/error counts by the number of reference words, which is 0 for that line. TheZeroDivisionErroraborts the run before the%WER/%SERsummary is written, so a single empty reference loses the whole report.This reports that utterance's rates against one word instead. The counts in the detail line, and the overall WER/SER, are unchanged.
Reproduction:
Before:
out.werstops afterutt1, with no summary.After (
out.wer):Type of change
Validation
python -m compileall funasr examples testsDocs or links checked
Runtime/deployment command tested
pytest tests/test_metrics_wer.py: 2 passed; both fail withZeroDivisionErrorwithout the fix. No model or audio is needed.pytest tests/test_metrics_common_rapidfuzz.py: passes.Ran
python -m funasr.metrics.weron the files above before and after the change (Windows 11 / Python 3.13).black --line-length=100(24.4.0, as pinned in pre-commit) on the changed lines and the new test.User impact
Anyone scoring a model with
funasr.metrics.wer(as inexamples/industrial_data_pretraining/paraformer/lora_cer.sh) on a test set containing a silent or untranscribed utterance gets a complete CER/WER report instead of a traceback.Notes for reviewers
Only the per-utterance percentages in
print_cer_detailchange, and only when the reference is empty: the cer shown is then the number of inserted words x 100%. The aggregate%WERalready handled this case (it divides by the total word count), so it is unchanged. The recipe copies underexamples/aishell/*/utils/compute_wer.pyhave the same division and are not touched here.