Spaces:
Sleeping
Sleeping
Update Space (evaluate main: 828c6327)
Browse files
README.md
CHANGED
@@ -1,12 +1,137 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.0.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
|
|
|
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
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,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# TODO: fix github to release
|
2 |
+
git+https://github.com/huggingface/evaluate.git@b6e6ed7f3e6844b297bff1b43a1b4be0709b9671
|
3 |
+
datasets~=2.0
|
4 |
+
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.EvaluationModule):
|
79 |
+
def _info(self):
|
80 |
+
return evaluate.EvaluationModuleInfo(
|
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
|