-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_results.py
217 lines (192 loc) · 8.68 KB
/
plot_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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
from pathlib import Path
def main():
resultdir = Path('results')
imagedir = Path('results/images')
imagedir.mkdir(exist_ok=True)
full_results = pd.read_csv(resultdir / 'evaluation.csv')
full_results['Model'] = (
full_results['Model']
.replace({
'turku-neural-parser': 'Turku pipeline',
'udpipe-fi-tdt': 'UDPipe',
'spacy-fi_core_news_sm': 'spacy-sm',
'spacy-fi_core_news_md': 'spacy-md',
'spacy-fi_core_news_lg': 'spacy-lg',
'spacy-fi_experimental_web_md': 'spacy-experimental',
'finnpos': 'FinnPos',
'uralicnlp': 'UralicNLP',
'stanza': 'Stanza',
'trankit': 'Trankit',
'voikko': 'Voikko',
'raudikko': 'Raudikko',
}))
full_results = full_results.rename(columns={
'UPOS F1': 'Part-of-speech F1',
'UPOS precision': 'Part-of-speech precision',
'UPOS recall': 'Part-of-speech recall',
'UPOS aligned accuracy': 'Part-of-speech aligned accuracy',
})
# Leave out the FinnPos evaluation on ftb1u, because ftb1u is the
# training set for FinnPos
full_results = full_results[~((full_results['Model'] == 'FinnPos') &
(full_results['Dataset'] == 'ftb1u'))]
results_by_testset = full_results[full_results['Dataset'] != 'concatenated']
results_concatenated = full_results[full_results['Dataset'] == 'concatenated']
model_order = sorted(results_by_testset['Model'].unique())
sns.barplot(x='Model', y='Lemmatization F1', hue='Dataset',
data=results_by_testset, order=model_order)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'lemma_f1_by_dataset.png')
plt.close()
sns.barplot(x='Model', y='Lemmatization precision', data=results_by_testset,
hue='Dataset', order=model_order)
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'lemma_precision_by_dataset.png')
plt.close()
sns.barplot(x='Model', y='Lemmatization recall', data=results_by_testset,
hue='Dataset', order=model_order)
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'lemma_recall_by_dataset.png')
plt.close()
sns.barplot(x='Model', y='Lemmatization aligned accuracy', data=results_concatenated, order=model_order)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'lemma_acc.png')
plt.close()
sns.barplot(x='Model', y='Lemmatization F1', data=results_concatenated, order=model_order)
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'lemma_f1.png')
plt.close()
sns.barplot(x='Model', y='Part-of-speech F1', hue='Dataset',
data=results_by_testset, order=model_order)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'pos_f1_by_dataset.png')
plt.close()
sns.barplot(x='Model', y='Part-of-speech precision', hue='Dataset',
data=results_by_testset, order=model_order)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'pos_precision_by_dataset.png')
plt.close()
sns.barplot(x='Model', y='Part-of-speech recall', hue='Dataset',
data=results_by_testset, order=model_order)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'pos_recall_by_dataset.png')
plt.close()
sns.barplot(x='Model', y='Part-of-speech aligned accuracy', data=results_concatenated, order=model_order)
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'pos_acc.png')
plt.close()
sns.barplot(x='Model', y='Part-of-speech F1', data=results_concatenated, order=model_order)
for tick in plt.gca().xaxis.get_major_ticks():
tick.label.set_fontsize(9)
plt.xticks(rotation=70)
plt.tight_layout()
plt.xlabel('')
plt.savefig(imagedir / 'pos_f1.png')
plt.close()
label_left_lemma = ['Stanza', 'simplemma', 'spacy-lg', 'Raudikko']
sns.relplot(x='Lemmatization F1', y='Tokens per second',
data=results_concatenated, s=80)
for x, y, text in zip(results_concatenated['Lemmatization F1'],
results_concatenated['Tokens per second'],
results_concatenated['Model']):
ha = 'left' if text in label_left_lemma else 'right'
textrelx = 7 if ha == 'left' else -5
plt.annotate(text, (x, y), xytext=(textrelx, 0), textcoords='offset points',
horizontalalignment=ha, verticalalignment='center')
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
plt.yscale('log')
plt.tight_layout()
plt.savefig(imagedir / 'lemma_f1_speed.png')
plt.close()
label_left_lemma = ['FinnPos', 'simplemma', 'spacy-lg', 'Raudikko']
sns.relplot(x='Lemmatization aligned accuracy', y='Tokens per second',
data=results_concatenated, s=80)
for x, y, text in zip(results_concatenated['Lemmatization aligned accuracy'],
results_concatenated['Tokens per second'],
results_concatenated['Model']):
ha = 'left' if text in label_left_lemma else 'right'
textrelx = 7 if ha == 'left' else -5
plt.annotate(text, (x, y), xytext=(textrelx, 0), textcoords='offset points',
horizontalalignment=ha, verticalalignment='center')
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
plt.yscale('log')
plt.tight_layout()
plt.savefig(imagedir / 'lemma_acc_speed.png')
plt.close()
label_left_pos = ['Voikko', 'Raudikko', 'Stanza', 'spacy-lg']
sns.relplot(x='Part-of-speech F1', y='Tokens per second',
data=results_concatenated, s=80)
for x, y, text in zip(results_concatenated['Part-of-speech F1'],
results_concatenated['Tokens per second'],
results_concatenated['Model']):
ha = 'left' if text in label_left_pos else 'right'
textrelx = 7 if ha == 'left' else -5
plt.annotate(text, (x, y), xytext=(textrelx, 0), textcoords='offset points',
horizontalalignment=ha, verticalalignment='center')
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
plt.yscale('log')
plt.tight_layout()
plt.savefig(imagedir / 'pos_f1_speed.png')
plt.close()
sns.relplot(x='Part-of-speech aligned accuracy', y='Tokens per second',
data=results_concatenated, s=80)
for x, y, text in zip(results_concatenated['Part-of-speech aligned accuracy'],
results_concatenated['Tokens per second'],
results_concatenated['Model']):
ha = 'left' if text in label_left_pos else 'right'
textrelx = 7 if ha == 'left' else -5
plt.annotate(text, (x, y), xytext=(textrelx, 0), textcoords='offset points',
horizontalalignment=ha, verticalalignment='center')
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter(1, decimals=0))
plt.yscale('log')
plt.tight_layout()
plt.savefig(imagedir / 'pos_acc_speed.png')
plt.close()
if __name__ == '__main__':
main()