Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-187

Character Error Rate

Problem

Return the character error rate: the Levenshtein distance between the reference and hypothesis strings divided by the reference length.

An empty reference gives 0.0 for an empty hypothesis and 1.0 otherwise.

Hint

This is the same DP as WER but over characters instead of tokens.

Test cases

case 1
in: ["abc","abc"]
expected: 0
case 2
in: ["abc","ac"]
expected: 0.3333333333333333
case 3
in: ["ab",""]
expected: 1
case 4
in: ["",""]
expected: 0
case 5
in: ["","x"]
expected: 1
Starter codePython
def cer(reference, hypothesis):
    # Your code here
    pass

5 test cases · run your code against them in the editor