-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevaluation.py
175 lines (141 loc) · 6.27 KB
/
evaluation.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import pandas as pd
import re
import numpy as np
from sklearn.metrics import classification_report, confusion_matrix
from args import *
def extract_prediction(response):
try:
prediction = re.search("\[(.*?)\]", response).group(1)
return prediction
except:
# print(response)
# print("#" * 20)
pass
def compute_accuracy(prediction_list, gold_list):
correct = 0
for prediction, gold in zip(prediction_list, gold_list):
if prediction == gold:
correct = correct + 1
accuracy = correct / len(gold_list)
return accuracy
if __name__ == "__main__":
if args.dataset == "hover":
with open(f"./HoVerDev/out/aggregate/{args.model}_aggregate_{args.prompt_strategy}_{args.hover_num_hop}_{args.version}.json") as f1:
df = pd.read_json(f1)
""" Print Label Distribution """
# num_support = len(df[df.label == "SUPPORTED"])
# num_not_support = len(df[df.label == "NOT_SUPPORTED"])
# print(f"# SUPPORTED: {num_support}")
# print(f"# NOT_SUPPORTED: {num_not_support}")
""" Get Prediction """
prediction_list = []
for response in df["response"]:
prediction = extract_prediction(response)
prediction_list.append(prediction)
gold_list = df["label"].to_list()
final_pred, final_gold = [], []
for i in range(len(prediction_list)):
if prediction_list[i] == "SUPPORTED" or prediction_list[i] == "NOT_SUPPORTED":
final_pred.append(prediction_list[i])
final_gold.append(gold_list[i])
print(f"Total # of predictions: {len(final_pred)}")
acc = compute_accuracy(final_pred, final_gold)
print(f"Accuracy: {acc: .2f}")
target_names = ["NOT_SUPPORTED", "SUPPORTED"]
label_map = {"NOT_SUPPORTED": 0, "SUPPORTED": 1}
labels = [label_map[e] for e in final_gold]
predictions = [label_map[e] for e in final_pred]
print("Classification Report")
print("=" * 60)
print(classification_report(labels, predictions,
target_names=target_names, digits=4))
print(confusion_matrix(labels, predictions))
""" Lookup Wrong """
wrong = []
for i in range(len(predictions)):
if predictions[i] + labels[i] == 1:
wrong.append(i)
print("Got Wrong:")
print(wrong)
if args.dataset == "feverous":
with open(f"./FeverousDev/out/aggregate/{args.model}_aggregate_{args.prompt_strategy}_{args.feverous_challenge}_{args.version}.json") as f1:
df = pd.read_json(f1)
remap = dict = {"SUPPORTS": "SUPPORTED", "REFUTES": "NOT_SUPPORTED"}
df = df.replace({"label": remap})
print(df)
""" Print Label Distribution """
num_support = len(df[df.label == "SUPPORTED"])
num_not_support = len(df[df.label == "NOT_SUPPORTED"])
print(f"# SUPPORTED: {num_support}")
print(f"# NOT_SUPPORTED: {num_not_support}")
""" Get Prediction """
prediction_list = []
for response in df["response"]:
prediction = extract_prediction(response)
prediction_list.append(prediction)
gold_list = df["label"].to_list()
final_pred, final_gold = [], []
for i in range(len(prediction_list)):
if prediction_list[i] == "SUPPORTED" or prediction_list[i] == "NOT_SUPPORTED":
final_pred.append(prediction_list[i])
final_gold.append(gold_list[i])
print(f"Total # of predictions: {len(final_pred)}")
acc = compute_accuracy(final_pred, final_gold)
print(f"Accuracy: {acc: .2f}")
target_names = ["NOT_SUPPORTED", "SUPPORTED"]
label_map = {"NOT_SUPPORTED": 0, "SUPPORTED": 1}
labels = [label_map[e] for e in final_gold]
predictions = [label_map[e] for e in final_pred]
print("Classification Report")
print("=" * 60)
print(classification_report(labels, predictions,
target_names=target_names, digits=4))
print(confusion_matrix(labels, predictions))
""" Lookup Wrong """
wrong = []
for i in range(len(predictions)):
if predictions[i] + labels[i] == 1:
wrong.append(i)
print("Got Wrong:")
print(wrong)
if args.dataset == "scifact":
with open(f"./SciFact-Open/out/aggregate/{args.model}_aggregate_{args.prompt_strategy}_{args.version}.json") as f1:
df = pd.read_json(f1)
remap = dict = {"SUPPORT": "SUPPORTED", "CONTRADICT": "NOT_SUPPORTED"}
df = df.replace({"label": remap})
print(df)
""" Print Label Distribution """
num_support = len(df[df.label == "SUPPORTED"])
num_not_support = len(df[df.label == "NOT_SUPPORTED"])
print(f"# SUPPORTED: {num_support}")
print(f"# NOT_SUPPORTED: {num_not_support}")
""" Get Prediction """
prediction_list = []
for response in df["response"]:
prediction = extract_prediction(response)
prediction_list.append(prediction)
gold_list = df["label"].to_list()
final_pred, final_gold = [], []
for i in range(len(prediction_list)):
if prediction_list[i] == "SUPPORTED" or prediction_list[i] == "NOT_SUPPORTED":
final_pred.append(prediction_list[i])
final_gold.append(gold_list[i])
print(f"Total # of predictions: {len(final_pred)}")
acc = compute_accuracy(final_pred, final_gold)
print(f"Accuracy: {acc: .2f}")
target_names = ["NOT_SUPPORTED", "SUPPORTED"]
label_map = {"NOT_SUPPORTED": 0, "SUPPORTED": 1}
labels = [label_map[e] for e in final_gold]
predictions = [label_map[e] for e in final_pred]
print("Classification Report")
print("=" * 60)
print(classification_report(labels, predictions,
target_names=target_names, digits=4))
print(confusion_matrix(labels, predictions))
""" Lookup Wrong """
wrong = []
for i in range(len(predictions)):
if predictions[i] + labels[i] == 1:
wrong.append(i)
print("Got Wrong:")
print(wrong)