-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_analysis.py
More file actions
53 lines (37 loc) · 1.52 KB
/
result_analysis.py
File metadata and controls
53 lines (37 loc) · 1.52 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
import pickle
import numpy as np
import wandb
from tqdm import tqdm
def get_metric_history(run, metric: str):
return [row[metric] for row in run.scan_history(keys=[metric])]
LINKS_F1_METRIC = 'dev/links/f1_epoch'
PREPOSITIONS_F1_METRIC = 'dev/prepositions/custom_f1_epoch'
def load_metrics():
api = wandb.Api()
# Project is specified by <entity/project-name>
runs = api.runs("roeehendel/TNE", filters={'group': 'experiments_5'})
runs_results = dict()
for run in tqdm(runs):
runs_results[run.name] = dict(
links_f1=get_metric_history(run, LINKS_F1_METRIC),
prepositions_f1=get_metric_history(run, PREPOSITIONS_F1_METRIC)
)
run_metrics = [(run_name,
np.mean(run_results['prepositions_f1'][-10:]) * 100,
np.mean(run_results['links_f1'][-10:]) * 100)
for run_name, run_results in runs_results.items()]
run_metrics = sorted(run_metrics, key=lambda x: x[1], reverse=True)
# save results to pickle
with open('results.pkl', 'wb') as f:
pickle.dump(run_metrics, f)
load_metrics()
# load results from pickle
with open('results.pkl', 'rb') as f:
run_metrics = pickle.load(f)
# print the metrics in latex table format
for run_name, prepositions_f1, links_f1 in run_metrics:
run_name.replace('-base', '')
run_name.replace('advnaced-', 'A &')
run_name.replace('roberta-', 'rob &')
run_name.replace('spanbert-', 'spa &')
print(f'{run_name} & {prepositions_f1:.2f} & {links_f1:.2f} \\\\')