-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult_analysis.py
59 lines (50 loc) · 1.55 KB
/
result_analysis.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
"""
python result_analysis.py trials/pdtb/cell_units one_v_all --metric val_f1
"""
from pprint import pprint
import json
import codecs
import argparse
def best(results, dataset, metric):
""" Returns the best for each relation type based on metric """
best = {}
for r in results:
# Check task
if "dataset_name" not in r["params"]:
continue
if r["params"]["dataset_name"] != dataset:
continue
relation = r["params"]["relation"]
# Skip if line does not have metric
if metric not in r["metrics"]:
continue
score = float(r["metrics"][metric])
if relation in best:
if score > float(best[relation]["metrics"][metric]):
best[relation] = r
else:
best[relation] = r
return best
def graph(results, param):
""" y as f1, x as varying parameter """
pass
def load(filepath):
""" Returns list of dictionaries from file """
results = []
with open(filepath, encoding='utf8') as pdfile:
for line in pdfile:
j = json.loads(line)
results += [j]
return results
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="analyze results")
parser.add_argument('filepath', help='file path of results')
parser.add_argument('dataset', help='"one_v_all" or "conll"')
parser.add_argument('--metric', help='metric to check for best result',
default='val_f1')
args = parser.parse_args()
results = load(args.filepath)
print('-' * 80)
print('Printing the best results based on metric: ', args.metric)
print('-' * 80)
pprint(best(results, args.dataset, args.metric))