Spaces:
Runtime error
Runtime error
Refactoring
#2
by
AlhitawiMohammed22
- opened
wer.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# Copyright 2021 The HuggingFace Evaluate Authors.
|
2 |
#
|
3 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
#
|
5 |
# You may obtain a copy of the License at
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
@@ -30,13 +30,13 @@ _CITATION = """\
|
|
30 |
"""
|
31 |
|
32 |
_DESCRIPTION = """\
|
33 |
-
Word error rate (WER) is a
|
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 |
-
|
40 |
|
41 |
WER = (S + D + I) / N = (S + D + I) / (S + D + C)
|
42 |
|
@@ -53,7 +53,7 @@ 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.
|
@@ -65,7 +65,7 @@ Returns:
|
|
65 |
|
66 |
Examples:
|
67 |
|
68 |
-
>>> predictions = ["this is the prediction", "there is
|
69 |
>>> references = ["this is the reference", "there is another one"]
|
70 |
>>> wer = evaluate.load("wer")
|
71 |
>>> wer_score = wer.compute(predictions=predictions, references=references)
|
@@ -96,11 +96,11 @@ class WER(evaluate.Metric):
|
|
96 |
def _compute(self, predictions=None, references=None, concatenate_texts=False):
|
97 |
if concatenate_texts:
|
98 |
return compute_measures(references, predictions)["wer"]
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
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
|
|
|
30 |
"""
|
31 |
|
32 |
_DESCRIPTION = """\
|
33 |
+
Word error rate (WER) is a standard 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 |
+
The word error rate can then be computed as:
|
40 |
|
41 |
WER = (S + D + I) / N = (S + D + I) / (S + D + C)
|
42 |
|
|
|
53 |
"""
|
54 |
|
55 |
_KWARGS_DESCRIPTION = """
|
56 |
+
Compute the WER score of transcribed segments against references.
|
57 |
|
58 |
Args:
|
59 |
references: List of references for each speech input.
|
|
|
65 |
|
66 |
Examples:
|
67 |
|
68 |
+
>>> predictions = ["this is the prediction", "there is another 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)
|
|
|
96 |
def _compute(self, predictions=None, references=None, concatenate_texts=False):
|
97 |
if concatenate_texts:
|
98 |
return compute_measures(references, predictions)["wer"]
|
99 |
+
|
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
|