-
Notifications
You must be signed in to change notification settings - Fork 153
/
format_results.py
70 lines (50 loc) · 1.71 KB
/
format_results.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
from pytablewriter import MarkdownTableWriter
import json
def intent_table():
writer = MarkdownTableWriter()
writer.table_name = "Intent Cross-Validation Results (5 folds)"
with open("results/intent_report.json", "r") as f:
data = json.loads(f.read())
cols = ["support", "f1-score", "confused_with"]
writer.headers = ["class"] + cols
classes = list(data.keys())
try:
classes.remove("accuracy")
except:
pass
classes.sort(key=lambda x: data[x]["support"], reverse=True)
def format_cell(data, c, k):
if not data[c].get(k):
return "N/A"
if k == "confused_with":
return ", ".join([f"{k}({v})" for k, v in data[c][k].items()])
else:
return data[c][k]
writer.value_matrix = [
[c] + [format_cell(data, c, k) for k in cols] for c in classes
]
return writer.dumps()
def entity_table():
writer = MarkdownTableWriter()
writer.table_name = "Entity Cross-Validation Results (5 folds)"
with open("results/DIETClassifier_report.json", "r") as f:
data = json.loads(f.read())
cols = ["support", "f1-score", "precision", "recall"]
writer.headers = ["entity"] + cols
classes = list(data.keys())
classes.sort(key=lambda x: data[x]["support"], reverse=True)
def format_cell(data, c, k):
if not data[c].get(k):
return "N/A"
else:
return data[c][k]
writer.value_matrix = [
[c] + [format_cell(data, c, k) for k in cols] for c in classes
]
return writer.dumps()
intents = intent_table()
entities = entity_table()
with open("results.md", "w") as f:
f.write(intents)
f.write("\n\n\n")
f.write(entities)