dalmeow mamta commited on
Commit
a505be2
·
0 Parent(s):

Duplicate from evaluate-metric/wer

Browse files

Co-authored-by: Mamta Narang <[email protected]>

Files changed (5) hide show
  1. .gitattributes +27 -0
  2. README.md +170 -0
  3. app.py +6 -0
  4. requirements.txt +2 -0
  5. wer.py +106 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.onnx filter=lfs diff=lfs merge=lfs -text
13
+ *.ot filter=lfs diff=lfs merge=lfs -text
14
+ *.parquet filter=lfs diff=lfs merge=lfs -text
15
+ *.pb filter=lfs diff=lfs merge=lfs -text
16
+ *.pt filter=lfs diff=lfs merge=lfs -text
17
+ *.pth filter=lfs diff=lfs merge=lfs -text
18
+ *.rar filter=lfs diff=lfs merge=lfs -text
19
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
20
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
21
+ *.tflite filter=lfs diff=lfs merge=lfs -text
22
+ *.tgz filter=lfs diff=lfs merge=lfs -text
23
+ *.wasm filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: WER
3
+ emoji: 🤗
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.19.1
8
+ app_file: app.py
9
+ pinned: false
10
+ tags:
11
+ - evaluate
12
+ - metric
13
+ description: >-
14
+ Word error rate (WER) is a common metric of the performance of an automatic
15
+ speech recognition system.
16
+
17
+ The general difficulty of measuring performance lies in the fact that the
18
+ recognized word sequence can have a different length from the reference word
19
+ sequence (supposedly the correct one). The WER is derived from the Levenshtein
20
+ distance, working at the word level instead of the phoneme level. The WER is a
21
+ valuable tool for comparing different systems as well as for evaluating
22
+ improvements within one system. This kind of measurement, however, provides no
23
+ details on the nature of translation errors and further work is therefore
24
+ required to identify the main source(s) of error and to focus any research
25
+ effort.
26
+
27
+ This problem is solved by first aligning the recognized word sequence with the
28
+ reference (spoken) word sequence using dynamic string alignment. Examination
29
+ of this issue is seen through a theory called the power law that states the
30
+ correlation between perplexity and word error rate.
31
+
32
+ Word error rate can then be computed as:
33
+
34
+ WER = (S + D + I) / N = (S + D + I) / (S + D + C)
35
+
36
+ where
37
+
38
+ S is the number of substitutions, D is the number of deletions, I is the
39
+ number of insertions, C is the number of correct words, N is the number of
40
+ words in the reference (N=S+D+C).
41
+
42
+ This value indicates the average number of errors per reference word. The
43
+ lower the value, the better the performance of the ASR system with a WER of 0
44
+ being a perfect score.
45
+ duplicated_from: evaluate-metric/wer
46
+ ---
47
+
48
+ # Metric Card for WER
49
+
50
+ ## Metric description
51
+ Word error rate (WER) is a common metric of the performance of an automatic speech recognition (ASR) system.
52
+
53
+ 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.
54
+
55
+ 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).
56
+
57
+ Word error rate can then be computed as:
58
+
59
+ `WER = (S + D + I) / N = (S + D + I) / (S + D + C)`
60
+
61
+ where
62
+
63
+ `S` is the number of substitutions,
64
+
65
+ `D` is the number of deletions,
66
+
67
+ `I` is the number of insertions,
68
+
69
+ `C` is the number of correct words,
70
+
71
+ `N` is the number of words in the reference (`N=S+D+C`).
72
+
73
+
74
+ ## How to use
75
+
76
+ The metric takes two inputs: references (a list of references for each speech input) and predictions (a list of transcriptions to score).
77
+
78
+
79
+ ```python
80
+ from evaluate import load
81
+ wer = load("wer")
82
+ wer_score = wer.compute(predictions=predictions, references=references)
83
+ ```
84
+ ## Output values
85
+
86
+ This metric outputs a float representing the word error rate.
87
+
88
+ ```
89
+ print(wer_score)
90
+ 0.5
91
+ ```
92
+
93
+ This value indicates the average number of errors per reference word.
94
+
95
+ The **lower** the value, the **better** the performance of the ASR system, with a WER of 0 being a perfect score.
96
+
97
+ ### Values from popular papers
98
+
99
+ 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.
100
+
101
+ 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.
102
+ 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.
103
+
104
+ ## Examples
105
+
106
+ Perfect match between prediction and reference:
107
+
108
+ ```python
109
+ from evaluate import load
110
+ wer = load("wer")
111
+ predictions = ["hello world", "good night moon"]
112
+ references = ["hello world", "good night moon"]
113
+ wer_score = wer.compute(predictions=predictions, references=references)
114
+ print(wer_score)
115
+ 0.0
116
+ ```
117
+
118
+ Partial match between prediction and reference:
119
+
120
+ ```python
121
+ from evaluate import load
122
+ wer = load("wer")
123
+ predictions = ["this is the prediction", "there is an other sample"]
124
+ references = ["this is the reference", "there is another one"]
125
+ wer_score = wer.compute(predictions=predictions, references=references)
126
+ print(wer_score)
127
+ 0.5
128
+ ```
129
+
130
+ No match between prediction and reference:
131
+
132
+ ```python
133
+ from evaluate import load
134
+ wer = load("wer")
135
+ predictions = ["hello world", "good night moon"]
136
+ references = ["hi everyone", "have a great day"]
137
+ wer_score = wer.compute(predictions=predictions, references=references)
138
+ print(wer_score)
139
+ 1.0
140
+ ```
141
+
142
+ ## Limitations and bias
143
+
144
+ 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.
145
+
146
+ ## Citation
147
+
148
+ ```bibtex
149
+ @inproceedings{woodard1982,
150
+ author = {Woodard, J.P. and Nelson, J.T.,
151
+ year = {1982},
152
+ journal = {Workshop on standardisation for speech I/O technology, Naval Air Development Center, Warminster, PA},
153
+ title = {An information theoretic measure of speech recognition performance}
154
+ }
155
+ ```
156
+
157
+ ```bibtex
158
+ @inproceedings{morris2004,
159
+ author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
160
+ year = {2004},
161
+ month = {01},
162
+ pages = {},
163
+ title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
164
+ }
165
+ ```
166
+
167
+ ## Further References
168
+
169
+ - [Word Error Rate -- Wikipedia](https://en.wikipedia.org/wiki/Word_error_rate)
170
+ - [Hugging Face Tasks -- Automatic Speech Recognition](https://huggingface.co/tasks/automatic-speech-recognition)
app.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import evaluate
2
+ from evaluate.utils import launch_gradio_widget
3
+
4
+
5
+ module = evaluate.load("wer")
6
+ launch_gradio_widget(module)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/huggingface/evaluate@775555d80af30d83dc6e9f42051840d29a34f31b
2
+ jiwer
wer.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 The HuggingFace Evaluate Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """ Word Error Ratio (WER) metric. """
15
+
16
+ import datasets
17
+ from jiwer import compute_measures
18
+
19
+ import evaluate
20
+
21
+
22
+ _CITATION = """\
23
+ @inproceedings{inproceedings,
24
+ author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
25
+ year = {2004},
26
+ month = {01},
27
+ pages = {},
28
+ title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
29
+ }
30
+ """
31
+
32
+ _DESCRIPTION = """\
33
+ Word error rate (WER) is a common metric of the performance of an automatic speech recognition system.
34
+
35
+ The general difficulty of measuring performance 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, working at the word level instead of the phoneme level. The 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.
36
+
37
+ 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 and word error rate.
38
+
39
+ Word error rate can then be computed as:
40
+
41
+ WER = (S + D + I) / N = (S + D + I) / (S + D + C)
42
+
43
+ where
44
+
45
+ S is the number of substitutions,
46
+ D is the number of deletions,
47
+ I is the number of insertions,
48
+ C is the number of correct words,
49
+ N is the number of words in the reference (N=S+D+C).
50
+
51
+ This value indicates the average number of errors per reference word. The lower the value, the better the
52
+ performance of the ASR system with a WER of 0 being a perfect score.
53
+ """
54
+
55
+ _KWARGS_DESCRIPTION = """
56
+ Compute WER score of transcribed segments against references.
57
+
58
+ Args:
59
+ references: List of references for each speech input.
60
+ predictions: List of transcriptions to score.
61
+ concatenate_texts (bool, default=False): Whether to concatenate all input texts or compute WER iteratively.
62
+
63
+ Returns:
64
+ (float): the word error rate
65
+
66
+ Examples:
67
+
68
+ >>> predictions = ["this is the prediction", "there is an other sample"]
69
+ >>> references = ["this is the reference", "there is another one"]
70
+ >>> wer = evaluate.load("wer")
71
+ >>> wer_score = wer.compute(predictions=predictions, references=references)
72
+ >>> print(wer_score)
73
+ 0.5
74
+ """
75
+
76
+
77
+ @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
78
+ class WER(evaluate.Metric):
79
+ def _info(self):
80
+ return evaluate.MetricInfo(
81
+ description=_DESCRIPTION,
82
+ citation=_CITATION,
83
+ inputs_description=_KWARGS_DESCRIPTION,
84
+ features=datasets.Features(
85
+ {
86
+ "predictions": datasets.Value("string", id="sequence"),
87
+ "references": datasets.Value("string", id="sequence"),
88
+ }
89
+ ),
90
+ codebase_urls=["https://github.com/jitsi/jiwer/"],
91
+ reference_urls=[
92
+ "https://en.wikipedia.org/wiki/Word_error_rate",
93
+ ],
94
+ )
95
+
96
+ def _compute(self, predictions=None, references=None, concatenate_texts=False):
97
+ if concatenate_texts:
98
+ return compute_measures(references, predictions)["wer"]
99
+ else:
100
+ incorrect = 0
101
+ total = 0
102
+ for prediction, reference in zip(predictions, references):
103
+ measures = compute_measures(reference, prediction)
104
+ incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
105
+ total += measures["substitutions"] + measures["deletions"] + measures["hits"]
106
+ return incorrect / total