[Fix] Make cpWER calculation identical to meeteval #15573
Open
tango4j wants to merge 7 commits intoNVIDIA-NeMo:mainfrom
Open
[Fix] Make cpWER calculation identical to meeteval #15573tango4j wants to merge 7 commits intoNVIDIA-NeMo:mainfrom
tango4j wants to merge 7 commits intoNVIDIA-NeMo:mainfrom
Conversation
Signed-off-by: taejinp <tango4j@gmail.com>
Signed-off-by: taejinp <tango4j@gmail.com>
Signed-off-by: tango4j <tango4j@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates NeMo’s session-level cpWER computation to match MeetEval’s reference implementation by scoring each (ref speaker, hyp speaker) pair independently with edit distance and selecting the minimum-cost assignment via the Hungarian algorithm.
Changes:
- Reworked
calculate_session_cpWER()to use a padded square edit-distance cost matrix +scipy.optimize.linear_sum_assignment, and computecpWER = sum(pair_errors) / sum(ref_words). - Reworked
calculate_session_cpWER_bruteforce()to use per-pair edit distance over speaker permutations (reference implementation). - Added a new dedicated test suite (
test_cpwer.py) with MeetEval-verified expected values, plus Hungarian vs brute-force agreement checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
nemo/collections/asr/metrics/der.py |
Reimplements cpWER to match MeetEval using per-pair edit distance and Hungarian assignment; updates brute-force reference implementation accordingly. |
tests/collections/speaker_tasks/utils/test_cpwer.py |
Adds comprehensive MeetEval-verified cpWER tests and LSA vs brute-force agreement checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: taejinp <tango4j@gmail.com>
Signed-off-by: taejinp <tango4j@gmail.com>
Signed-off-by: tango4j <tango4j@users.noreply.github.com>
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.
What does this PR do?
This PR fixes the cpWER (concatenated minimum-permutation word error rate) calculation in NeMo to produce results identical to MeetEval, the de-facto reference implementation.
Root cause of the bug: The previous implementation concatenated all words from each speaker pair into a single string and then computed WER on the concatenated result. This allowed edit operations to "cross" speaker boundaries, producing artificially low error rates. For example,
hyp=["the cat sat", "on"]vsref=["the cat", "sat on"]would incorrectly return cpWER=0.0 instead of the correct cpWER=0.5.Fix: Each (ref_speaker, hyp_speaker) pair is now scored independently via edit distance, and cpWER = sum(errors) / sum(ref_word_counts). This matches MeetEval's algorithm exactly. The cost matrix is padded to
max(num_hyp, num_ref)so the Hungarian algorithm (or brute-force search) handles mismatched speaker counts without special-casing.Collection: ASR / Speaker Tasks
Changelog
calculate_session_cpWERto use per-pair edit distance scoring with a padded square cost matrix + Hungarian algorithm (scipy.optimize.linear_sum_assignment), matching MeetEval's cpWERcalculate_session_cpWER_bruteforceto use per-pair edit distance scoring (brute-force permutation search), serving as a reference/verification implementationuse_lsa_onlyparameter fromcalculate_session_cpWER(it was a no-op and is no longer needed since the square cost matrix naturally handles all speaker-count combinations)test_cpwer.py) with all expected values pre-verified against MeetEval'scp_word_error_rateN->num_speakers_padded)Usage
GitHub Actions CI
The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.
The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".
Before your PR is "Ready for review"
Pre checks:
scipyandeditdistanceare existing required dependenciesPR Type:
If you haven't finished some of the above items you can still open "Draft" PR.
Who can review?
Anyone in NeMo Speech AI ASR
Additional Information
test_diar_metrics.pyused manually computed(_ins, _del, _sub)counts that matched the old (incorrect) concatenation-based algorithm. The newtest_cpwer.pytests use expected values verified directly against MeetEval'scp_word_error_rate.use_lsa_onlyparameter removed fromcalculate_session_cpWER. Any callers passing this argument will need to remove it.