-
Notifications
You must be signed in to change notification settings - Fork 2
/
evaluate.py
57 lines (37 loc) · 1.33 KB
/
evaluate.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
import argparse
import numpy as np
from sklearn.metrics import precision_recall_fscore_support, accuracy_score
from src import config
parser = argparse.ArgumentParser()
parser.add_argument('--corpus', type=str,
help='prob files from which to generate the predictions')
parser.add_argument('--predictions', type=str,
help='Name of output file')
parser.add_argument('--all', action='store_true')
args = parser.parse_args()
corpus_name = args.corpus
corpus_labels_dict = config.label_dict[corpus_name]
true_labels = []
with open(corpus_labels_dict['test']) as f:
for line in f.readlines():
if line != '':
label = int(line.strip())
true_labels.append(label)
pred_labels = []
with open(args.predictions) as f:
for line in f.readlines():
if line != '':
prediction = int(line.strip())
pred_labels.append(prediction)
pred_labels = np.array(pred_labels)
true_labels = np.array(true_labels)
p, r, f1, s = precision_recall_fscore_support(true_labels,
pred_labels,
labels=[0, 1],
average='macro')
print(f1)
if args.all:
print(p)
print(r)
a = accuracy_score(true_labels, pred_labels)
print(a)