ctl commited on
Commit
b353b5b
1 Parent(s): a7b912d

upadte CER

Browse files
Files changed (2) hide show
  1. cer.py +1 -1
  2. 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.5
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
- ref = [u'我能吞下玻璃而不伤身体']
95
- pred = [u' 能吞虾玻璃而 不霜身体啦']
96
  # S = 3, D = 2, I = 0, N = 11
97
  # CER = 5 / 11
98
- char_error_rate = cer.compute(predictions=pred, references=ref)
99
  self.assertTrue(abs(char_error_rate - 0.4545454545) < 1e-6)
100
 
101
- ref = [u'我能吞', u'下玻璃而不伤身体']
102
- pred = [u'我 能 吞 下 玻 璃', u'而不伤身体']
103
  # S = 0, D = 5, I = 0, N = 11
104
  # CER = 5 / 11
105
- char_error_rate = cer.compute(predictions=pred, references=ref)
106
  self.assertTrue(abs(char_error_rate - 0.454545454545) < 1e-6)
107
 
108
- ref = [u'我能吞下玻璃而不伤身体']
109
- char_error_rate = cer.compute(predictions=ref, references=ref)
110
  self.assertFalse(char_error_rate, 0.0)
111
 
112
  def test_cer_empty(self):
113
- ref = ''
114
- pred = 'Hypothesis'
115
  with self.assertRaises(ValueError):
116
- char_error_rate = cer.compute(predictions=pred, references=ref)
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()