upadte CER
Browse files- cer.py +1 -1
- test_cer.py +11 -11
cer.py
CHANGED
@@ -88,7 +88,7 @@ Examples:
|
|
88 |
>>> cer = datasets.load_metric("cer")
|
89 |
>>> cer_score = cer.compute(predictions=predictions, references=references)
|
90 |
>>> print(cer_score)
|
91 |
-
0.
|
92 |
"""
|
93 |
|
94 |
|
|
|
88 |
>>> cer = datasets.load_metric("cer")
|
89 |
>>> cer_score = cer.compute(predictions=predictions, references=references)
|
90 |
>>> print(cer_score)
|
91 |
+
0.34146341463414637
|
92 |
"""
|
93 |
|
94 |
|
test_cer.py
CHANGED
@@ -91,29 +91,29 @@ class TestCER(unittest.TestCase):
|
|
91 |
self.assertTrue(abs(char_error_rate - 0.03571428) < 1e-6)
|
92 |
|
93 |
def test_cer_unicode(self):
|
94 |
-
|
95 |
-
|
96 |
# S = 3, D = 2, I = 0, N = 11
|
97 |
# CER = 5 / 11
|
98 |
-
char_error_rate = cer.compute(predictions=
|
99 |
self.assertTrue(abs(char_error_rate - 0.4545454545) < 1e-6)
|
100 |
|
101 |
-
|
102 |
-
|
103 |
# S = 0, D = 5, I = 0, N = 11
|
104 |
# CER = 5 / 11
|
105 |
-
char_error_rate = cer.compute(predictions=
|
106 |
self.assertTrue(abs(char_error_rate - 0.454545454545) < 1e-6)
|
107 |
|
108 |
-
|
109 |
-
char_error_rate = cer.compute(predictions=
|
110 |
self.assertFalse(char_error_rate, 0.0)
|
111 |
|
112 |
def test_cer_empty(self):
|
113 |
-
|
114 |
-
|
115 |
with self.assertRaises(ValueError):
|
116 |
-
char_error_rate = cer.compute(predictions=
|
117 |
|
118 |
if __name__ == '__main__':
|
119 |
unittest.main()
|
|
|
91 |
self.assertTrue(abs(char_error_rate - 0.03571428) < 1e-6)
|
92 |
|
93 |
def test_cer_unicode(self):
|
94 |
+
refs = [u'我能吞下玻璃而不伤身体']
|
95 |
+
preds = [u' 能吞虾玻璃而 不霜身体啦']
|
96 |
# S = 3, D = 2, I = 0, N = 11
|
97 |
# CER = 5 / 11
|
98 |
+
char_error_rate = cer.compute(predictions=preds, references=refs)
|
99 |
self.assertTrue(abs(char_error_rate - 0.4545454545) < 1e-6)
|
100 |
|
101 |
+
refs = [u'我能吞', u'下玻璃而不伤身体']
|
102 |
+
preds = [u'我 能 吞 下 玻 璃', u'而不伤身体']
|
103 |
# S = 0, D = 5, I = 0, N = 11
|
104 |
# CER = 5 / 11
|
105 |
+
char_error_rate = cer.compute(predictions=preds, references=refs)
|
106 |
self.assertTrue(abs(char_error_rate - 0.454545454545) < 1e-6)
|
107 |
|
108 |
+
refs = [u'我能吞下玻璃而不伤身体']
|
109 |
+
char_error_rate = cer.compute(predictions=refs, references=refs)
|
110 |
self.assertFalse(char_error_rate, 0.0)
|
111 |
|
112 |
def test_cer_empty(self):
|
113 |
+
refs = ''
|
114 |
+
preds = 'Hypothesis'
|
115 |
with self.assertRaises(ValueError):
|
116 |
+
char_error_rate = cer.compute(predictions=preds, references=refs)
|
117 |
|
118 |
if __name__ == '__main__':
|
119 |
unittest.main()
|