# Spaces: evaluate-metric /wer Running

lvwerra
HF staff
commited on
Commit
f21e916
1 Parent(s): e8b2823

# Update Space (evaluate main: 828c6327)

Files changed (4) hide show
2. app.py +6 -0
3. requirements.txt +4 -0
4. wer.py +106 -0
 1 --- 2 + title: WER 3 + emoji: 🤗 4 + colorFrom: blue 5 + colorTo: red 6 sdk: gradio 7 sdk_version: 3.0.2 8 app_file: app.py 9 pinned: false 10 + tags: 11 + - evaluate 12 + - metric 13 --- 14 15 + # Metric Card for WER 16 + 17 + ## Metric description 18 + Word error rate (WER) is a common metric of the performance of an automatic speech recognition (ASR) system. 19 + 20 + The general difficulty of measuring the performance of ASR systems lies in the fact that the recognized word sequence can have a different length from the reference word sequence (supposedly the correct one). The WER is derived from the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance), working at the word level. 21 + 22 + This problem is solved by first aligning the recognized word sequence with the reference (spoken) word sequence using dynamic string alignment. Examination of this issue is seen through a theory called the power law that states the correlation between [perplexity](https://huggingface.co/metrics/perplexity) and word error rate (see [this article](https://www.cs.cmu.edu/~roni/papers/eval-metrics-bntuw-9802.pdf) for further information). 23 + 24 + Word error rate can then be computed as: 25 + 26 + WER = (S + D + I) / N = (S + D + I) / (S + D + C) 27 + 28 + where 29 + 30 + S is the number of substitutions, 31 + 32 + D is the number of deletions, 33 + 34 + I is the number of insertions, 35 + 36 + C is the number of correct words, 37 + 38 + N is the number of words in the reference (N=S+D+C). 39 + 40 + 41 + ## How to use 42 + 43 + The metric takes two inputs: references (a list of references for each speech input) and predictions (a list of transcriptions to score). 44 + 45 + 46 + python 47 + from evaluate import load 48 + wer = load("wer") 49 + wer_score = wer.compute(predictions=predictions, references=references) 50 +  51 + ## Output values 52 + 53 + This metric outputs a float representing the word error rate. 54 + 55 +  56 + print(wer_score) 57 + 0.5 58 +  59 + 60 + This value indicates the average number of errors per reference word. 61 + 62 + The **lower** the value, the **better** the performance of the ASR system, with a WER of 0 being a perfect score. 63 + 64 + ### Values from popular papers 65 + 66 + This metric is highly dependent on the content and quality of the dataset, and therefore users can expect very different values for the same model but on different datasets. 67 + 68 + For example, datasets such as [LibriSpeech](https://huggingface.co/datasets/librispeech_asr) report a WER in the 1.8-3.3 range, whereas ASR models evaluated on [Timit](https://huggingface.co/datasets/timit_asr) report a WER in the 8.3-20.4 range. 69 + See the leaderboards for [LibriSpeech](https://paperswithcode.com/sota/speech-recognition-on-librispeech-test-clean) and [Timit](https://paperswithcode.com/sota/speech-recognition-on-timit) for the most recent values. 70 + 71 + ## Examples 72 + 73 + Perfect match between prediction and reference: 74 + 75 + python 76 + from evaluate import load 77 + wer = load("wer") 78 + predictions = ["hello world", "good night moon"] 79 + references = ["hello world", "good night moon"] 80 + wer_score = wer.compute(predictions=predictions, references=references) 81 + print(wer_score) 82 + 0.0 83 +  84 + 85 + Partial match between prediction and reference: 86 + 87 + python 88 + from evaluate import load 89 + wer = load("wer") 90 + predictions = ["this is the prediction", "there is an other sample"] 91 + references = ["this is the reference", "there is another one"] 92 + wer_score = wer.compute(predictions=predictions, references=references) 93 + print(wer_score) 94 + 0.5 95 +  96 + 97 + No match between prediction and reference: 98 + 99 + python 100 + from evaluate import load 101 + wer = load("wer") 102 + predictions = ["hello world", "good night moon"] 103 + references = ["hi everyone", "have a great day"] 104 + wer_score = wer.compute(predictions=predictions, references=references) 105 + print(wer_score) 106 + 1.0 107 +  108 + 109 + ## Limitations and bias 110 + 111 + WER is a valuable tool for comparing different systems as well as for evaluating improvements within one system. This kind of measurement, however, provides no details on the nature of translation errors and further work is therefore required to identify the main source(s) of error and to focus any research effort. 112 + 113 + ## Citation 114 + 115 + bibtex 116 + @inproceedings{woodard1982, 117 + author = {Woodard, J.P. and Nelson, J.T., 118 + year = {1982}, 119 + journal = Ẅorkshop on standardisation for speech I/O technology, Naval Air Development Center, Warminster, PA}, 120 + title = {An information theoretic measure of speech recognition performance} 121 + } 122 +  123 + 124 + bibtex 125 + @inproceedings{morris2004, 126 + author = {Morris, Andrew and Maier, Viktoria and Green, Phil}, 127 + year = {2004}, 128 + month = {01}, 129 + pages = {}, 130 + title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.} 131 + } 132 +  133 + 134 + ## Further References 135 + 136 + - [Word Error Rate -- Wikipedia](https://en.wikipedia.org/wiki/Word_error_rate) 137 + - [Hugging Face Tasks -- Automatic Speech Recognition](https://huggingface.co/tasks/automatic-speech-recognition)