Spaces:
Running
Running
Update Space (evaluate main: b39b2669)
Browse files- requirements.txt +1 -1
- wer.py +22 -10
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
git+https://github.com/huggingface/evaluate@
|
| 2 |
jiwer
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/evaluate@b39b26694046961b9ae97a0458b290fc992df2b1
|
| 2 |
jiwer
|
wer.py
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
""" Word Error Ratio (WER) metric. """
|
| 15 |
|
| 16 |
import datasets
|
| 17 |
-
|
| 18 |
|
| 19 |
import evaluate
|
| 20 |
|
|
@@ -94,13 +94,25 @@ class WER(evaluate.Metric):
|
|
| 94 |
)
|
| 95 |
|
| 96 |
def _compute(self, predictions=None, references=None, concatenate_texts=False):
|
| 97 |
-
if
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
else:
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
""" Word Error Ratio (WER) metric. """
|
| 15 |
|
| 16 |
import datasets
|
| 17 |
+
import jiwer
|
| 18 |
|
| 19 |
import evaluate
|
| 20 |
|
|
|
|
| 94 |
)
|
| 95 |
|
| 96 |
def _compute(self, predictions=None, references=None, concatenate_texts=False):
|
| 97 |
+
if hasattr(jiwer, "compute_measures"):
|
| 98 |
+
if concatenate_texts:
|
| 99 |
+
return jiwer.compute_measures(references, predictions)["wer"]
|
| 100 |
+
else:
|
| 101 |
+
incorrect = 0
|
| 102 |
+
total = 0
|
| 103 |
+
for prediction, reference in zip(predictions, references):
|
| 104 |
+
measures = jiwer.compute_measures(reference, prediction)
|
| 105 |
+
incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
|
| 106 |
+
total += measures["substitutions"] + measures["deletions"] + measures["hits"]
|
| 107 |
+
return incorrect / total
|
| 108 |
else:
|
| 109 |
+
if concatenate_texts:
|
| 110 |
+
return jiwer.process_words(references, predictions).wer
|
| 111 |
+
else:
|
| 112 |
+
incorrect = 0
|
| 113 |
+
total = 0
|
| 114 |
+
for prediction, reference in zip(predictions, references):
|
| 115 |
+
measures = jiwer.process_words(reference, prediction)
|
| 116 |
+
incorrect += measures.substitutions + measures.deletions + measures.insertions
|
| 117 |
+
total += measures.substitutions + measures.deletions + measures.hits
|
| 118 |
+
return incorrect / total
|