-
Notifications
You must be signed in to change notification settings - Fork 20
/
test_yules_i.py
61 lines (49 loc) · 2.26 KB
/
test_yules_i.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
from gem_metrics.yules_i import Yules_I
from gem_metrics.texts import Predictions
from tests.test_referenceless import TestReferenceLessMetric
from tests.inputs import TestData
from tests.utils import assertDeepAlmostEqual
class TestYULES_I(TestReferenceLessMetric, unittest.TestCase):
def setUp(self):
super().setUp()
self.metric = Yules_I()
def test_yules_i_metric_basic(self):
"""Tests for the base case."""
expected_metrics = {"yules_i": 16.962}
calculated_metrics = self.metric.compute({}, TestData.predictions)
assertDeepAlmostEqual(self, expected_metrics, calculated_metrics)
def test_yules_i_metric_empty(self):
"""Tests with empty inputs"""
text = ["", ""]
calculated_metrics = self.metric.compute({}, Predictions({"values": text}))
self.assertAlmostEqual(calculated_metrics[f"yules_i"], 0)
def test_yules_i_disjoint_tokens(self):
"""Tests for Yules_I with disjoint tokens."""
text = [
"one two three four five six seven eight nine ten",
"eleven twelve thirteen fourteen fifteen sixteen",
]
metric = Yules_I()
calculated_metrics = metric.compute({}, Predictions({"values": text}))
self.assertAlmostEqual(calculated_metrics[f"yules_i"], 0.0)
def test_yules_i_mixed_tokens(self):
"""Tests for Yules_I with disjoint tokens."""
text = [
"one two one two three four five six five six",
"six seven eight eight nine ten ten ten ten",
]
metric = Yules_I()
calculated_metrics = metric.compute({}, Predictions({"values": text}))
self.assertAlmostEqual(calculated_metrics[f"yules_i"], 2.857)
def test_yules_i_identical_tokens(self):
"""Tests for Yules_I with identical tokens (low diversity)."""
text = [
"token token token token token token token token token token token token token",
"token token token token token token token token token token token token token",
]
metric = Yules_I()
calculated_metrics = metric.compute({}, Predictions({"values": text}))
self.assertAlmostEqual(calculated_metrics[f"yules_i"], 0.001)
if __name__ == "__main__":
unittest.main()