-
Notifications
You must be signed in to change notification settings - Fork 13
/
evaluate_heur_output.py
141 lines (114 loc) · 4.05 KB
/
evaluate_heur_output.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import sys
def format_label(label):
if label == "entailment":
return "entailment"
else:
return "non-entailment"
fi = open(sys.argv[1], "r")
first = True
guess_dict = {}
for line in fi:
if first:
first = False
continue
else:
parts = line.strip().split(",")
guess_dict[parts[0]] = format_label(parts[1])
fi = open("heuristics_evaluation_set.txt", "r")
correct_dict = {}
first = True
heuristic_list = []
subcase_list = []
template_list = []
for line in fi:
if first:
labels = line.strip().split("\t")
idIndex = labels.index("pairID")
first = False
continue
else:
parts = line.strip().split("\t")
this_line_dict = {}
for index, label in enumerate(labels):
if label == "pairID":
continue
else:
this_line_dict[label] = parts[index]
correct_dict[parts[idIndex]] = this_line_dict
if this_line_dict["heuristic"] not in heuristic_list:
heuristic_list.append(this_line_dict["heuristic"])
if this_line_dict["subcase"] not in subcase_list:
subcase_list.append(this_line_dict["subcase"])
if this_line_dict["template"] not in template_list:
template_list.append(this_line_dict["template"])
heuristic_ent_correct_count_dict = {}
subcase_correct_count_dict = {}
template_correct_count_dict = {}
heuristic_ent_incorrect_count_dict = {}
subcase_incorrect_count_dict = {}
template_incorrect_count_dict = {}
heuristic_nonent_correct_count_dict = {}
heuristic_nonent_incorrect_count_dict = {}
for heuristic in heuristic_list:
heuristic_ent_correct_count_dict[heuristic] = 0
heuristic_ent_incorrect_count_dict[heuristic] = 0
heuristic_nonent_correct_count_dict[heuristic] = 0
heuristic_nonent_incorrect_count_dict[heuristic] = 0
for subcase in subcase_list:
subcase_correct_count_dict[subcase] = 0
subcase_incorrect_count_dict[subcase] = 0
for template in template_list:
template_correct_count_dict[template] = 0
template_incorrect_count_dict[template] = 0
for key in correct_dict:
traits = correct_dict[key]
heur = traits["heuristic"]
subcase = traits["subcase"]
template = traits["template"]
guess = guess_dict[key]
correct = traits["gold_label"]
if guess == correct:
if correct == "entailment":
heuristic_ent_correct_count_dict[heur] += 1
else:
heuristic_nonent_correct_count_dict[heur] += 1
subcase_correct_count_dict[subcase] += 1
template_correct_count_dict[template] += 1
else:
if correct == "entailment":
heuristic_ent_incorrect_count_dict[heur] += 1
else:
heuristic_nonent_incorrect_count_dict[heur] += 1
subcase_incorrect_count_dict[subcase] += 1
template_incorrect_count_dict[template] += 1
print("Heuristic entailed results:")
for heuristic in heuristic_list:
correct = heuristic_ent_correct_count_dict[heuristic]
incorrect = heuristic_ent_incorrect_count_dict[heuristic]
total = correct + incorrect
percent = correct * 1.0 / total
print(heuristic + ": " + str(percent))
print("")
print("Heuristic non-entailed results:")
for heuristic in heuristic_list:
correct = heuristic_nonent_correct_count_dict[heuristic]
incorrect = heuristic_nonent_incorrect_count_dict[heuristic]
total = correct + incorrect
percent = correct * 1.0 / total
print(heuristic + ": " + str(percent))
print("")
print("Subcase results:")
for subcase in subcase_list:
correct = subcase_correct_count_dict[subcase]
incorrect = subcase_incorrect_count_dict[subcase]
total = correct + incorrect
percent = correct * 1.0 / total
print(subcase + ": " + str(percent))
print("")
print("Template results:")
for template in template_list:
correct = template_correct_count_dict[template]
incorrect = template_incorrect_count_dict[template]
total = correct + incorrect
percent = correct * 1.0 / total
print(template + ": " + str(percent))