-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathkeyword_based_test.py
More file actions
61 lines (52 loc) · 1.68 KB
/
keyword_based_test.py
File metadata and controls
61 lines (52 loc) · 1.68 KB
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
"""Tests for keyword_based.py."""
import unittest
from baselines import keyword_based
class TfIdfMethodTest(unittest.TestCase):
def test_train_test(self):
"""Check that it can correctly rank a simple example."""
method = keyword_based.TfIdfMethod()
method.train(
["hello how are you", "hello how are"],
["hello how", "hello"]
)
predictions = method.rank_responses(
["hello", "how", "are", "you"],
["you", "are", "how", "hello"]
)
self.assertEqual(
list(predictions),
[3, 2, 1, 0]
)
def test_train_test_idf(self):
"""Check that the keyword with higher idf counts for more."""
method = keyword_based.TfIdfMethod()
method.train(
["hello how are you", "hello how are"],
["hello how", "hello"]
)
predictions = method.rank_responses(
["hello you", "hello you"],
["hello", "you"]
)
self.assertEqual(
list(predictions),
[1, 1] # you is more informative than 'hello'.
)
class BM25MethodTest(unittest.TestCase):
def test_train_test_bm25(self):
"""Check that bm25 can correctly rank a simple example."""
method = keyword_based.BM25Method()
method.train(
["hello how are you", "hello how are"],
["hello how", "hello"]
)
predictions = method.rank_responses(
["hello", "how", "are"],
["are", "how", "hello"]
)
self.assertEqual(
list(predictions),
[2, 1, 0]
)
if __name__ == "__main__":
unittest.main()