-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_latex_tables.py
183 lines (151 loc) · 6.61 KB
/
generate_latex_tables.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
import argparse
import pandas as pd
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Plot results")
parser.add_argument("-p", "--data-path", type=str, help="path to the csv.")
parser.add_argument("-o", "--output-path", type=str, help="path to a txt.")
args = parser.parse_args()
df = pd.read_csv(args.data_path, sep=',')
corpus = args.data_path.lower().split()[-1].split('.')[0]
print(corpus)
accs_comm = df['ACC']
accs_layman = df['ACC Layman']
accs_clf = df['ACC Classifier']
accs_bow = df['ACC BOW Classifier']
if corpus == 'sst':
ks = [3, 3, 6]
elif corpus == 'snli':
ks = [3, 3, 6]
elif corpus in ['agnews', 'imdb']:
ks = [4, 4, 6]
elif corpus in ['yelp']:
ks = [3, 3, 3]
else:
raise Exception('corpus not found')
acc_rnn_softmax = accs_clf[0]
acc_rnn_sparsemax = accs_clf[3]
acc_rnn_entmax = accs_clf[6]
acc_bow = accs_bow[0]
def get_accs(for_layman=False):
# which acc will be plotted
if for_layman:
accs = accs_layman
else:
accs = accs_comm
# get accs for each corpus (manually for now)
if corpus in ['sst', 'snli']:
accs_encoded_attn_softmax = [accs[0], accs[1], accs[2]]
accs_encoded_attn_sparsemax = [accs[3], accs[4], accs[5]]
accs_encoded_attn_entmax = [accs[6], accs[7], accs[8]]
accs_gradient_softmax = [accs[9], accs[10], accs[11]]
accs_gradient_sparsemax = [accs[12], accs[13], accs[14]]
accs_gradient_entmax = [accs[15], accs[16], accs[17]]
accs_random_softmax = [accs[18], accs[19], accs[20],
accs[21], accs[22], accs[23]]
accs_random_sparsemax = [accs[24], accs[25], accs[26],
accs[27], accs[28], accs[29]]
accs_random_entmax = [accs[30], accs[31], accs[32],
accs[33], accs[34], accs[35]]
elif corpus in ['agnews', 'imdb']:
accs_encoded_attn_softmax = [accs[0], accs[1], accs[2], accs[3]]
accs_encoded_attn_sparsemax = [accs[4], accs[5], accs[6], accs[7]]
accs_encoded_attn_entmax = [accs[8], accs[9], accs[10], accs[11]]
accs_gradient_softmax = [accs[12], accs[13], accs[14], accs[15]]
accs_gradient_sparsemax = [accs[16], accs[17], accs[18], accs[19]]
accs_gradient_entmax = [accs[20], accs[21], accs[22], accs[23]]
accs_random_softmax = [accs[24], accs[25], accs[26],
accs[27], accs[28], accs[29]]
accs_random_sparsemax = [accs[30], accs[31], accs[32],
accs[33], accs[34], accs[35]]
accs_random_entmax = [accs[36], accs[37], accs[38],
accs[39], accs[40], accs[41]]
elif corpus in ['yelp']:
accs_encoded_attn_softmax = [accs[0], accs[1], accs[2]]
accs_encoded_attn_sparsemax = [accs[3], accs[4], accs[5]]
accs_encoded_attn_entmax = [accs[6], accs[7], accs[8]]
accs_gradient_softmax = [accs[9], accs[10], accs[11]]
accs_gradient_sparsemax = [accs[12], accs[13], accs[14]]
accs_gradient_entmax = [accs[15], accs[16], accs[17]]
accs_random_softmax = [accs[18], accs[19], accs[20]]
accs_random_sparsemax = [accs[21], accs[22], accs[23]]
accs_random_entmax = [accs[24], accs[25], accs[26]]
else:
raise Exception('corpus not available: {}'.format(corpus))
return (accs_encoded_attn_softmax,
accs_encoded_attn_sparsemax,
accs_encoded_attn_entmax,
accs_gradient_softmax,
accs_gradient_sparsemax,
accs_gradient_entmax,
accs_random_softmax,
accs_random_sparsemax,
accs_random_entmax)
accs = get_accs(for_layman=False)
accs_encoded_attn_softmax_c = accs[0]
accs_encoded_attn_sparsemax_c = accs[1]
accs_encoded_attn_entmax_c = accs[2]
accs_gradient_softmax_c = accs[3]
accs_gradient_sparsemax_c = accs[4]
accs_gradient_entmax_c = accs[5]
accs_random_softmax_c = accs[6]
accs_random_sparsemax_c = accs[7]
accs_random_entmax_c = accs[8]
accs = get_accs(for_layman=True)
accs_encoded_attn_softmax_l = accs[0]
accs_encoded_attn_sparsemax_l = accs[1]
accs_encoded_attn_entmax_l = accs[2]
accs_gradient_softmax_l = accs[3]
accs_gradient_sparsemax_l = accs[4]
accs_gradient_entmax_l = accs[5]
accs_random_softmax_l = accs[6]
accs_random_sparsemax_l = accs[7]
accs_random_entmax_l = accs[8]
x = 'RNN baseline \t& $n$ \t& & - \t& - \t& - \t& & {:.4f} \t& {:.4f} \t& {:.4f} \\\\'
print(x.format(acc_rnn_softmax, acc_rnn_sparsemax, acc_rnn_entmax))
x = 'BoW baseline \t& $n$ \t& & - \t& - \t& - \t& & {:.4f} \t& {:.4f} \t& {:.4f} \\\\'
print(x.format(acc_bow, acc_bow, acc_bow))
print('\\midrule')
def to_str(v):
return ['%.4f' % x for x in v]
for i in range(ks[0]):
c1 = ' \t& '.join(to_str([
accs_encoded_attn_softmax_c[i],
accs_encoded_attn_sparsemax_c[i],
accs_encoded_attn_entmax_c[i]
]))
c2 = ' \t& '.join(to_str([
accs_encoded_attn_softmax_l[i],
accs_encoded_attn_sparsemax_l[i],
accs_encoded_attn_entmax_l[i]
]))
print('Encoded attention \t& {} \t& & {} \t& & {} \\\\'.format(i + 1, c1, c2))
print('\\midrule')
for i in range(ks[1]):
c1 = ' \t& '.join(to_str([
accs_gradient_softmax_c[i],
accs_gradient_sparsemax_c[i],
accs_gradient_entmax_c[i]
]))
c2 = ' \t& '.join(to_str([
accs_gradient_softmax_l[i],
accs_gradient_sparsemax_l[i],
accs_gradient_entmax_l[i]
]))
print('Gradient based \t& {} \t& & {} \t& & {} \\\\'.format(i + 1, c1, c2))
print('\\midrule')
random_names = ['Uniform', 'Beta', 'Shuffle',
'Zero-max-out', 'First states', 'Last states']
for i in range(ks[2]):
c1 = ' \t& '.join(to_str([
accs_random_softmax_c[i],
accs_random_sparsemax_c[i],
accs_random_entmax_c[i]
]))
c2 = ' \t& '.join(to_str([
accs_random_softmax_l[i],
accs_random_sparsemax_l[i],
accs_random_entmax_l[i]
]))
name = random_names[i]
print('{} \t& {} \t& & {} \t& & {} \\\\'.format(name, i + 1, c1, c2))
print('\\midrule')