Skip to content

Handle all-empty reference batches in WER and CER - #895

Open
snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:fix/jiwer-empty-reference-batches
Open

snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:fix/jiwer-empty-reference-batches

Conversation

@snygginghani

Copy link
Copy Markdown

Summary

The default segmented WER and CER paths sum the errors and reference lengths returned by JiWER, then divide by the total reference length. An all-silence batch can therefore raise ZeroDivisionError even though JiWER 4 supports empty references.

Apply JiWER 4's empty-reference behavior when the batch has no reference words or characters. This returns zero for correct silence and counts words or characters inserted into silence. Mixed batches still use the total reference length.

Validation

With JiWER 4.0.0, the following returns 3 for WER and 11 for CER. Both calls raised on the baseline.

import evaluate

for name in ("wer", "cer"):
    metric = evaluate.load(f"./metrics/{name}")
    print(metric.compute(references=["", ""], predictions=["alpha beta", "a"]))
  • python -m pytest tests/test_speech_metrics.py -q passed all eight cases, including empty, whitespace-only, and mixed reference batches. Six cases failed on the baseline.
  • A JiWER 3.1.0 smoke check returned the expected WER and CER on nonempty references.
  • Black, isort, flake8, and git diff --check passed on the changed files.

AI assistance was used to prepare the patch and tests.

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran WER and CER with all-empty references (['a b'] vs [''], two empty refs, empty vs empty). Without concatenate_texts, main raised ZeroDivisionError; here both modes match jiwer 4.0.0 (2, 3, 3, 4, 0, 0). Mixed empty and non-empty references are unchanged.

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.

2 participants