Skip to content

feat(metrics): add Character Error Rate (CER) metric#3710

Open
Manimaran-tech wants to merge 1 commit into
pytorch:masterfrom
Manimaran-tech:feature/cer-metric
Open

feat(metrics): add Character Error Rate (CER) metric#3710
Manimaran-tech wants to merge 1 commit into
pytorch:masterfrom
Manimaran-tech:feature/cer-metric

Conversation

@Manimaran-tech

Copy link
Copy Markdown
Contributor

Description

This PR adds a new NLP metric, CharacterErrorRate, to Ignite.

Character Error Rate (CER) measures the normalized edit distance between predicted and reference strings at the character level.

What’s included

  • Adds CharacterErrorRate metric implementation
  • Uses Levenshtein edit distance to compute character-level errors
  • Supports batch-wise updates and distributed usage
  • Follows Ignite metric API conventions used by existing NLP metrics

Why

CER is a standard evaluation metric for ASR/OCR and other sequence-to-text tasks where character-level accuracy is important.

Fixes #{issue_number}

Checklist

  • New tests are added (if a new feature is added)
  • New docstrings are added and in RST format
  • Documentation is updated (if required)

Add CharacterErrorRate metric for NLP tasks that measures the edit
distance at the character level between predicted and reference strings.

Features:
- Implements Levenshtein distance algorithm for edit distance computation
- Supports batch processing and distributed computation
- Follows same API pattern as other NLP metrics

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the module: metrics Metrics module label Apr 1, 2026
@aniketpandey05

aniketpandey05 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

@Manimaran-tech, could you link the issue number for this PR , also the Empty reference strings aren't handled in update and Distributed integration tests are missing as the other metric bleu and rogue have this

@aniketpandey05

aniketpandey05 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

@vfdev-5 should i update the pr or this one is good to be merged?

Comment on lines +108 to +116
for p, r in zip(y_pred, y):
p_chars = list(p)
r_chars = list(r)

errors += _edit_distance(r_chars, p_chars)
refs += len(r_chars)

self._num_errors += torch.tensor(errors, device=self._device)
self._num_refs += torch.tensor(refs, device=self._device)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should add a check for p and r is string or not .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: metrics Metrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants