-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.py
63 lines (54 loc) · 2.11 KB
/
example.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
from SIF import utils
import SIF.embedding
STS14 = [
'data/sts2014/deft-forum.test.tsv',
'data/sts2014/deft-news.test.tsv',
'data/sts2014/headlines.test.tsv',
'data/sts2014/images.test.tsv',
'data/sts2014/OnWN.test.tsv',
'data/sts2014/tweet-news.test.tsv'
]
STS15 = [
'data/sts2015/answers-forums.test.tsv',
'data/sts2015/answers-students.test.tsv',
'data/sts2015/belief.test.tsv',
'data/sts2015/headlines.test.tsv',
'data/sts2015/images.test.tsv'
]
GLOVE_PATH = './resources/glove.840B.300d.txt'
PSL_PATH = './resources/paragram_300_sl999.txt'
if __name__ == '__main__':
glove = utils.WordToWeight(GLOVE_PATH)
psl = utils.WordToWeight(PSL_PATH)
for embedding_method, name in [
(SIF.embedding.AVG_embedding, 'average weighted'),
(SIF.embedding.W_embedding, 'freq weighted'),
(SIF.embedding.WR_embedding, 'freq weighted + SVD')]:
scores = []
for data in STS14:
res = utils.evaluate(data, embedding_method, glove)
scores.append(res)
print(name, data, res)
print(name, 'STS14 average: ', sum(scores) / len(scores))
scores = []
for data in STS15:
res = utils.evaluate(data, embedding_method, glove)
scores.append(res)
print(name, data, res)
print(name, 'STS15 average: ', sum(scores) / len(scores))
for embedding_method, name in [
(SIF.embedding.AVG_embedding, 'average weighted'),
(SIF.embedding.W_embedding, 'freq weighted'),
(SIF.embedding.WR_embedding, 'freq weighted + SVD')]:
scores = []
for data in STS14:
res = utils.evaluate(data, embedding_method, psl)
scores.append(res)
print(name, data, res)
print(name, 'STS14 average: ', sum(scores) / len(scores))
scores = []
for data in STS15:
res = utils.evaluate(data, embedding_method, psl)
scores.append(res)
print(name, data, res)
print(name, 'STS15 average: ', sum(scores) / len(scores))