-
Notifications
You must be signed in to change notification settings - Fork 0
/
results-readout.py
142 lines (124 loc) · 4.93 KB
/
results-readout.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
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
142
import argparse
import numpy as np
import pandas as pd
gamma = 2
sizes = [5, 11, 20, 35, 80]
seqsignet_sizes = [(3, 5, 3), (3, 5, 6), (3, 5, 11), (3, 5, 26)]
def readout_results_from_csv(csv_filename: str, model_name: str, digits: int):
try:
results_df = pd.read_csv(csv_filename)
print(f"{'#'*10} {model_name} {'#'*10}")
# print overall F1, precision and recall scores
print(f"F1: {round(results_df['f1'].mean(), digits)}")
print(f"Precision: {round(results_df['precision'].mean(), digits)}")
print(f"Recall: {round(results_df['recall'].mean(), digits)}")
# print individual class F1, precision and recall scores averaged
f1_scores_stacked = np.stack(
results_df["f1_scores"].apply(
lambda x: list(np.fromstring(x[1:-1], sep=" "))
)
)
print(
f"F1 scores: {[round(x, digits) for x in f1_scores_stacked.mean(axis=0)]}"
)
precision_scores_stacked = np.stack(
results_df["precision_scores"].apply(
lambda x: list(np.fromstring(x[1:-1], sep=" "))
)
)
print(
f"Precision scores: {[round(x, digits) for x in precision_scores_stacked.mean(axis=0)]}"
)
recall_scores_stacked = np.stack(
results_df["recall_scores"].apply(
lambda x: list(np.fromstring(x[1:-1], sep=" "))
)
)
print(
f"Recall scores: {[round(x, digits) for x in recall_scores_stacked.mean(axis=0)]}"
)
print("\n")
except:
print(f"Error reading {csv_filename}")
def main():
# parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"--results-dir",
"-r",
help="Path to the folder containing the results data.",
type=str,
)
parser.add_argument(
"--digits",
"-d",
help="digits to round to",
type=int,
default=3,
)
args = parser.parse_args()
# these variables are manually set for now:
gamma = 2
sizes = [5, 11, 20, 35]
seqsignet_sizes = [(3, 5, 3), (3, 5, 6), (3, 5, 11)]
# readout FFN
file = f"{args.results_dir}/ffn_current_focal_{gamma}_kfold_best_model.csv"
readout_results_from_csv(file, model_name="FFN with current", digits=args.digits)
# readout FFN with history concatenation
file = f"{args.results_dir}/ffn_mean_history_focal_{gamma}_kfold_best_model.csv"
readout_results_from_csv(
file,
model_name="FFN with mean history concatenated with current",
digits=args.digits,
)
# readout BERT (focal loss)
file = f"{args.results_dir}/bert_classifier_focal.csv"
readout_results_from_csv(file, model_name="BERT (focal)", digits=args.digits)
# readout BERT (ce)
file = f"{args.results_dir}/bert_classifier_ce.csv"
readout_results_from_csv(
file, model_name="BERT (cross-entropy)", digits=args.digits
)
# readout LSTM
for size in sizes:
file = (
f"{args.results_dir}/lstm_history_{size}_focal_{gamma}_kfold_best_model.csv"
)
readout_results_from_csv(
file, model_name=f"BiLSTM (size={size})", digits=args.digits
)
# readout SWNU-Network
for size in sizes:
file = f"{args.results_dir}/swnu_network_umap_focal_{gamma}_{size}_kfold_best_model.csv"
readout_results_from_csv(
file, model_name=f"SWNU-Network (size={size})", digits=args.digits
)
# readout SWMHAU-Network
for size in sizes:
file = f"{args.results_dir}/swmhau_network_umap_focal_{gamma}_{size}_kfold_best_model.csv"
readout_results_from_csv(
file, model_name=f"SWMHAU-Network (size={size})", digits=args.digits
)
# readout SeqSigNet
for shift, window_size, n in seqsignet_sizes:
file = f"{args.results_dir}/seqsignet_umap_focal_{gamma}_{shift}_{window_size}_{n}_kfold_best_model.csv"
k = shift * n + (window_size - shift)
readout_results_from_csv(
file, model_name=f"SeqSigNet (size={k})", digits=args.digits
)
# readout SeqSigNetAttentionBiLSTM
for shift, window_size, n in seqsignet_sizes:
file = f"{args.results_dir}/seqsignet_attention_bilstm_umap_focal_{gamma}_{shift}_{window_size}_{n}_kfold_best_model.csv"
k = shift * n + (window_size - shift)
readout_results_from_csv(
file, model_name=f"SeqSigNetAttentionBiLSTM (size={k})", digits=args.digits
)
# readout SeqSigNetAttentionEncoder
for shift, window_size, n in seqsignet_sizes:
file = f"{args.results_dir}/seqsignet_attention_encoder_umap_focal_{gamma}_{shift}_{window_size}_{n}_kfold_best_model.csv"
k = shift * n + (window_size - shift)
readout_results_from_csv(
file, model_name=f"SeqSigNetAttentionEncoder (size={k})", digits=args.digits
)
if __name__ == "__main__":
main()