-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_utils.py
56 lines (47 loc) · 1.96 KB
/
eval_utils.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
from collections import Counter
import numpy as np
from scipy import stats
def mean_and_95ci(data):
mean = np.mean(data)
sem = stats.sem(data)
confidence_level = 0.95
degrees_freedom = len(data) - 1
t_statistic = stats.t.ppf((1 + confidence_level) / 2, degrees_freedom)
margin_of_error = t_statistic * sem
ci_lower = mean - margin_of_error
ci_upper = mean + margin_of_error
return mean, (ci_lower, ci_upper)
def most_frequent(ls):
count = Counter(ls)
most_common_element = count.most_common(1)[0][0]
return most_common_element
def get_uncertainties(responses, gt, parse_answer):
correct_uncertainties = []
incorrect_uncertainties = []
fail_uncertainties = []
for agent_responses in responses:
for agent_response in agent_responses[1::2]:
parsed = parse_answer(agent_response["content"])
uncertainty = agent_response["uncertainty"]
if parsed is None:
fail_uncertainties.append(uncertainty)
elif parsed == gt:
correct_uncertainties.append(uncertainty)
else:
incorrect_uncertainties.append(uncertainty)
return correct_uncertainties, incorrect_uncertainties, fail_uncertainties
def get_uncertainties_round(responses, gt, parse_answer):
correct_uncertainties = [[], [], []]
incorrect_uncertainties = [[], [], []]
fail_uncertainties = [[], [], []]
for agent_responses in responses:
for i, agent_response in enumerate(agent_responses[1::2]):
parsed = parse_answer(agent_response["content"])
uncertainty = agent_response["uncertainty"]
if parsed is None:
fail_uncertainties[i].append(uncertainty)
elif parsed == gt:
correct_uncertainties[i].append(uncertainty)
else:
incorrect_uncertainties[i].append(uncertainty)
return correct_uncertainties, incorrect_uncertainties, fail_uncertainties