-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.py
39 lines (28 loc) · 966 Bytes
/
eval.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
import argparse
import sys
from sys import stdin
import numpy as np
from utils import read_eval_file
def get_score(prop, props, power):
try:
i_prop = props.index(prop)
except ValueError:
i_prop = len(props)
score = (1 - (i_prop / len(props)) ** power)**(1/power)
return score
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('eval_file', type=str, help='Evaluation file.')
parser.add_argument('-p', '--power', default=2, type=int, help='Minkowski power.')
args, _ = parser.parse_known_args(sys.argv[1:])
eval_data = read_eval_file(args.eval_file)
words = stdin.read().split('\n')
words.remove('')
scores = []
for line in words:
line = line.split('\t')
word = line[0]
props = line[1:]
score = max((get_score(target, props, args.power) for target in eval_data[word]))
scores.append(score)
print(np.mean(scores))