-
Notifications
You must be signed in to change notification settings - Fork 16
/
cross_validation_results.py
76 lines (54 loc) · 1.83 KB
/
cross_validation_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
71
72
73
74
75
76
from pytablewriter import MarkdownTableWriter
import json
import os
result_dir = os.environ["RESULT_DIR"]
def intent_table():
writer = MarkdownTableWriter()
writer.table_name = "Intent Cross-Validation Results"
try:
with open(f"{result_dir}/intent_report.json", "r") as f:
data = json.loads(f.read())
except FileNotFoundError:
print("File not accessible.")
cols = ["support", "f1-score", "confused_with"]
writer.headers = ["class"] + cols
data.pop("accuracy", None)
classes = list(data.keys())
classes.sort(key=lambda x: data[x].get("support", 0), 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"
try:
with open(f"{result_dir}/DIETClassifier_report.json", "r") as f:
data = json.loads(f.read())
except FileNotFoundError:
print("File not accessible.")
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()
print(intents)
print("\n\n\n")
print(entities)