forked from facebookresearch/ParlAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_starspace.py
67 lines (57 loc) · 2.28 KB
/
test_starspace.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
62
63
64
65
66
67
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import unittest
import parlai.utils.testing as testing_utils
from parlai.scripts.build_candidates import BuildCandidates
class TestStarspace(unittest.TestCase):
def test_training_bs1(self):
valid, test = testing_utils.train_model(
{'model': 'starspace', 'task': 'integration_tests', 'num_epochs': 1.0}
)
assert valid['hits@1'] > 0.5
assert test['hits@1'] > 0.5
def test_training_otheropt(self):
valid, test = testing_utils.train_model(
{
'model': 'starspace',
'task': 'integration_tests',
'num_epochs': 1.0,
'input_dropout': 0.1,
'share_embeddings': False,
'lins': 1,
'tfidf': True,
}
)
assert valid['hits@1'] > 0.25
assert test['hits@1'] > 0.25
def test_training_fixedcand(self):
with testing_utils.tempdir() as tmpdir:
valid, test = testing_utils.train_model(
{
'model': 'starspace',
'task': 'integration_tests',
'num_epochs': 1.0,
'dict_file': os.path.join(tmpdir, 'model.dict'),
'model_file': os.path.join(tmpdir, 'model'),
}
)
assert valid['accuracy'] > 0.25
assert test['accuracy'] > 0.25
cand = os.path.join(tmpdir, 'cands.txt')
BuildCandidates.main(task='integration_tests', outfile=cand)
valid, test = testing_utils.eval_model(
{
'model': 'starspace',
'task': 'integration_tests:nocandidate',
'model_file': os.path.join(tmpdir, 'model'),
'dict_file': os.path.join(tmpdir, 'model.dict'),
'fixed_candidates_file': os.path.join(tmpdir, 'cands.txt'),
}
)
assert valid['f1'] >= 0.5
assert test['f1'] >= 0.5
assert valid['accuracy'] == 0.0
assert test['accuracy'] == 0.0