forked from borchand/SecondYearProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignificance_testing.py
More file actions
141 lines (97 loc) · 3.53 KB
/
significance_testing.py
File metadata and controls
141 lines (97 loc) · 3.53 KB
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
import pickle
import numpy as np
import glob
from pprint import pprint
import matplotlib.pyplot as plt
from scipy import stats
from deepsig import aso, multi_aso
def check_seeds():
paths = {
"Baseline": "list_baseline",
"Discriminate": "list_discriminate_lr",
}
seeds = dict()
for name, path in paths.items():
with open(f"{path}", "rb") as f:
runs = pickle.load(f)
seeds[name] = []
for run in runs:
seeds[name].append(run.at[0, "Seed"])
print(f"{name}: {len(set(seeds[name]))}")
return seeds
def read_results(folder_path, metric="span_f1"):
# Use glob to get all files in path
paths = {
"Baseline": "list_baseline",
"Discriminate": "list_discriminate_lr",
}
results = {
"english": {
"Baseline": [],
"Discriminate": [],
},
"german": {
"Baseline": [],
"Discriminate": [],
},
"danish": {
"Baseline": [],
"Discriminate": [],
},
"hungarian": {
"Baseline": [],
"Discriminate": [],
}
}
metric = f"eval_{metric}"
for name, path in paths.items():
with open(f"{folder_path}/{path}", "rb") as f:
runs = pickle.load(f)
for j, run in enumerate(runs):
if j == 7:
continue
for i, lang in enumerate(results.keys()):
result = run.at[i, metric]
if metric == "eval_loss":
result = -result
if result == 0:
print(run)
results[lang][name].append(result)
print(f"Read {name} results")
return results
def evaluate_aso(path="eval_lists", metric="span_f1", seed=123, **kwargs):
results = read_results(path, metric=metric)
my_model_scores_per_dataset = []
baseline_scores_per_dataset = []
for lang in results.keys():
print(f"Language: {lang}")
for name, result in results[lang].items():
print(f"{name}: {np.mean(result):.4f} +- {np.std(result): .4f}")
print((np.mean(results[lang]['Baseline']) - np.mean(results[lang]['Discriminate'])) / np.mean(results[lang]['Baseline']) * 100)
my_model_scores_per_dataset.append(results[lang]['Discriminate'])
baseline_scores_per_dataset.append(results[lang]['Baseline'])
# aso_result = aso(results[lang]['Discriminate'], results[lang]['Baseline'], confidence_level=0.9875, seed=seed, **kwargs)
# print(f"ASO: \n{aso_result}")
eps_min = [aso(b, a, confidence_level=0.95, num_comparisons=4, seed=seed) for a, b in zip(my_model_scores_per_dataset, baseline_scores_per_dataset)]
print(f"eps_min: {eps_min}")
return
def main():
# pprint(read_results("pickled_evals"))
# pprint(check_seeds())
evaluate_aso(metric="span_f1", seed=123)
results = read_results("eval_lists", metric="span_f1")
fig = plt.figure(figsize=(10, 10))
for i, lang in enumerate(results.keys()):
plt.subplot(2, 2, i+1)
plt.title(lang)
for name, result in results[lang].items():
mu = np.mean(result)
sigma = np.std(result)
# plot kde of results
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)
kde = stats.gaussian_kde(result)
plt.plot(x, kde(x), label=name)
plt.legend()
plt.show()
if __name__ == '__main__':
main()