shruti-coreml / source /tests /test_score.py
bingokingooo's picture
Publish experimental 22-language Shruti Core ML conversion
32942d4 verified
Raw History Blame Contribute Delete
1.18 kB
import unittest
from shruti_coreml.score import edit_distance, score_paired, words
class ScoreTests(unittest.TestCase):
def test_nfc_lowercase_punctuation_and_numbers(self):
self.assertEqual(words(" E\u0301CO, 200! चालीस। "), ["éco", "200", "चालीस"])
def test_token_insert_delete_and_replace(self):
self.assertEqual(edit_distance(["a", "b", "c"], ["a", "d", "e", "f"]), 3)
self.assertEqual(edit_distance(["a"], []), 1)
self.assertEqual(edit_distance([], ["a", "b"]), 2)
def test_weighting_and_pairing(self):
rows = [
{"reference": "one two", "baseline": {"text": "one"}, "coreml": {"text": "one two"}},
{"reference": "three", "baseline": {"text": "three"}, "coreml": {"text": "three"}},
]
scored = score_paired(rows)
self.assertAlmostEqual(scored["difference_wer_points"], -100 / 3)
self.assertEqual(scored["exact_text_matches"], 1)
def test_silence_counts_words(self):
scored = score_paired([{"reference": "", "baseline": {"text": ""}, "coreml": {"text": "one two"}}])
self.assertEqual(scored["coreml_words_on_silence"], 2)