AlhitawiMohammed22 commited on
Commit
48e2361
1 Parent(s): 7ffa193

script for evaluation on WER

Browse files
Files changed (3) hide show
  1. eval_wer.py +97 -0
  2. run.py +5 -0
  3. test_eval_wer.py +0 -0
eval_wer.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ Word Error Ratio (WER) metric. """
2
+
3
+ import datasets
4
+ from jiwer import compute_measures
5
+
6
+ import evaluate
7
+
8
+ _CITATION = """\
9
+ @inproceedings{inproceedings,
10
+ author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
11
+ year = {2004},
12
+ month = {01},
13
+ pages = {},
14
+ title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
15
+ }
16
+ """
17
+
18
+ _DESCRIPTION = """\
19
+ Word error rate (WER) is a common metric of the performance of an automatic speech recognition system.
20
+ 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.
21
+ 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.
22
+ Word error rate can then be computed as:
23
+ WER = (S + D + I) / N = (S + D + I) / (S + D + C)
24
+ where
25
+ S is the number of substitutions,
26
+ D is the number of deletions,
27
+ I is the number of insertions,
28
+ C is the number of correct words,
29
+ N is the number of words in the reference (N=S+D+C).
30
+ This value indicates the average number of errors per reference word. The lower the value, the better the
31
+ performance of the ASR system with a WER of 0 being a perfect score.
32
+ """
33
+
34
+ _KWARGS_DESCRIPTION = """
35
+ Compute WER score of transcribed segments against references.
36
+ Args:
37
+ references: List of references for each speech input.
38
+ predictions: List of transcriptions to score.
39
+ concatenate_texts (bool, default=False): Whether to concatenate all input texts or compute WER iteratively.
40
+ Returns:
41
+ (float): the word error rate
42
+ Examples:
43
+ 1- Hungarain
44
+ >>> predictions = ["ez a jóslat", "van egy másik minta"]
45
+ >>> references = ["ez a hivatkozás", "van még egy"]
46
+ >>> wer = evaluate.load("wer")
47
+ >>> wer_score = wer.compute(predictions=predictions, references=references) * 100
48
+ >>> print(wer_score,'%')
49
+ 84.61538461538461 %
50
+
51
+ 2- English
52
+ >>> predictions = ["this is the prediction", "there is an other sample"]
53
+ >>> references = ["this is the reference", "there is another one"]
54
+ >>> wer = evaluate.load("wer")
55
+ >>> wer_score = wer.compute(predictions=predictions, references=references) * 100
56
+ >>> print(wer_score,'%')
57
+ 0.5
58
+ """
59
+
60
+
61
+ @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
62
+ class WER(evaluate.Metric):
63
+ def _info(self):
64
+ return evaluate.MetricInfo(
65
+ description=_DESCRIPTION,
66
+ citation=_CITATION,
67
+ inputs_description=_KWARGS_DESCRIPTION,
68
+ features=datasets.Features(
69
+ {
70
+ "predictions": datasets.Value("string", id="sequence"),
71
+ "references": datasets.Value("string", id="sequence"),
72
+ }
73
+ ),
74
+ codebase_urls=["https://github.com/jitsi/jiwer/"],
75
+ reference_urls=[
76
+ "https://en.wikipedia.org/wiki/Word_error_rate",
77
+ ],
78
+ )
79
+
80
+ def _compute(self, predictions=None, references=None, concatenate_texts=False):
81
+ if concatenate_texts:
82
+ return compute_measures(references, predictions)["wer"]
83
+ total = 0
84
+ for prediction, reference in zip(predictions, references):
85
+ measures = compute_measures(reference, prediction)
86
+ incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
87
+ total += measures["substitutions"] + measures["deletions"] + measures["hits"]
88
+ return incorrect / total
89
+
90
+ # else:
91
+ # incorrect = 0
92
+ # total = 0
93
+ # for prediction, reference in zip(predictions, references):
94
+ # measures = compute_measures(reference, prediction)
95
+ # incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
96
+ # total += measures["substitutions"] + measures["deletions"] + measures["hits"]
97
+ # return incorrect / total
run.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import evaluate
2
+ from evaluate.utils import launch_gradio_widget
3
+
4
+ module = evaluate.load("wer")
5
+ launch_gradio_widget(module)
test_eval_wer.py ADDED
File without changes