Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-186

Word Error Rate

Problem

Return the word error rate: the Levenshtein distance between reference and hypothesis token lists divided by the reference length.

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

Hint

Use the standard edit-distance DP and normalize by the number of reference words.

Test cases

case 1
in: [["a","b","c"],["a","b","c"]]
expected: 0
case 2
in: [["a","b","c"],["a","c"]]
expected: 0.3333333333333333
case 3
in: [["a","b"],[]]
expected: 1
case 4
in: [[],[]]
expected: 0
case 5
in: [[],["x"]]
expected: 1
Starter codePython
def wer(reference, hypothesis):
    # Your code here
    pass

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