-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.py
executable file
·271 lines (255 loc) · 9.57 KB
/
config.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
class Config(object):
""" Model Configuration
[use_img_feat] options control how we use image features
None not using image features (default)
"concat_bf_lstm" concatenate image feature before LSTM
"concat_af_lstm" concatenate image feature after LSTM
"only_img" image feature only
[combine_typ] how do we combine context feature with candidate feature
"bilinpool" using binlinear pooling (default)
"concat" concatenate features directly
[cls_hidden] number of hidden layers for classifer (all with size 256)
"""
learning_rate = 0.001
learning_rate_decay = 0.9
max_epoch = 30
grad_clip = 1.0
num_layers = 1
num_steps = 15
hidden_size = 512
dropout_prob = 0.5
batch_size = 100
vocab_size = 10004
embedding_size = 300
num_input = 2
use_lstm = True
# How to use Image Feature :
# None | 'concat_bf_lstm' | 'concat_af_lstm' | 'only_img'
use_img_feat= 'concat_af_lstm'
# How to combine context feature:
# 'bilinpool' | 'concat'
combine_typ = 'concat'
# 0 for basic linear classifier
cls_hidden = 0
use_residual = False # Whether use residual connection in LSTM
use_random_human = True # Whether using random human captions transformations
use_random_word = True # Whether using random word replacement
use_word_permutation = True # Whehter using random word permutations
use_mc_samples = True # Whether using Monte Carlo Sampled Captions
def set_no_da(config):
# not using data augmentation durng training.
config.use_random_human = False
config.use_random_word = False
config.use_word_permutation = False
config.use_mc_samples = False
return config
def config_model_coco(config, model_architecture):
config.num_layers = 1 # using 1 LSTM layer
# Linear models
if model_architecture == 'concat_no_img_1_512_0':
config.use_img_feat = None
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 0
elif model_architecture == 'concat_img_1_512_0':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 0
elif model_architecture == 'concat_only_img_1_512_0':
config.use_img_feat = 'only_img'
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 0
elif model_architecture == 'concat_img_1_512_0_noda':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 0
config = set_no_da(config)
# Non-linear models with Compact Bilinear Pooling
elif model_architecture == 'bilinear_img_1_512_0':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.hidden_size = 512
config.cls_hidden = 0
elif model_architecture == 'bilinear_no_img_1_512_0':
config.use_img_feat = None
config.combine_typ = 'bilinpool'
config.hidden_size = 512
config.cls_hidden = 0
elif model_architecture == 'bilinear_only_img_1_512_0':
config.use_img_feat = 'only_img'
config.combine_typ = 'bilinpool'
config.hidden_size = 512
config.cls_hidden = 0
elif model_architecture == 'bilinear_img_1_512_0_noda':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.hidden_size = 512
config.cls_hidden = 0
config = set_no_da(config)
# Non-linear models with MLP
elif model_architecture == 'mlp_1_img_1_512_0':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 1
elif model_architecture == 'mlp_1_no_img_1_512_0':
config.use_img_feat = None
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 1
elif model_architecture == 'mlp_1_only_img_1_512_0':
config.use_img_feat = 'only_img'
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 1
elif model_architecture == 'mlp_1_img_1_512_0_noda':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'concat'
config.hidden_size = 512
config.cls_hidden = 1
config = set_no_da(config)
else:
raise Exception("Invalid architecture name:%s"%model_architecture)
return config
def config_model_flickr(config, model_architecture):
config.use_random_human = True
config.use_random_word = False
config.use_word_permutation = False
config.use_mc_samples = False
config.batch_size = 50
config.max_epoch = 100
config.learning_rate_decay = 0.98
config.learning_rate = 0.001
config.batch_size = 100
config.test_batch_size = 15000
config.vocab_size = 3441 # Without lemmatization
if model_architecture == 'baseline':
return config
if model_architecture == 'baseline_mlp':
config.use_img_feat = None
config.combine_typ = 'concat'
config.cls_hidden = 1
return config
if model_architecture == 'bilinear':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 1
config.cls_hidden = 0
return config
if model_architecture == 'bilinear_moreLSTM':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 0
return config
if model_architecture == 'bilinear_clf_moreLSTM':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
return config
if model_architecture == 'bilinear_sm':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 1
config.cls_hidden = 0
config.hidden_size = 128
return config
if model_architecture == 'bilinear_moreLSTM_sm':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 0
config.hidden_size = 128
return config
if model_architecture == 'bilinear_clf_moreLSTM':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
return config
if model_architecture == 'bilinear_clf_moreLSTM_sm':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
return config
if model_architecture == 'bilinear_bilinear':
config.use_img_feat = 'bilinpool'
config.combine_typ = 'bilinpool'
config.num_layers = 1
config.cls_hidden = 0
config.hidden_size = 128
return config
# Different Dropout
if model_architecture == 'bilinear_clf_moreLSTM_dropout0.3':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.dropout_prob = 0.3
return config
if model_architecture == 'bilinear_clf_moreLSTM_dropout0.1':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.dropout_prob = 0.3
return config
# Turn the learning rate
if model_architecture == 'bilinear_clf_moreLSTM_lr0.001':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.learning_rate = 0.001
return config
if model_architecture == 'bilinear_clf_moreLSTM_lr0.002':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.learning_rate = 0.002
return config
if model_architecture == 'bilinear_clf_moreLSTM_lr0.0008':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.learning_rate = 0.0008
return config
if model_architecture == 'bilinear_clf_moreLSTM_lr0.0005':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.learning_rate = 0.0005
return config
if model_architecture == 'bilinear_clf_moreLSTM_lr0.0002':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.learning_rate = 0.0002
return config
if model_architecture == 'bilinear_clf_moreLSTM_lr0.0001':
config.use_img_feat = 'concat_af_lstm'
config.combine_typ = 'bilinpool'
config.num_layers = 2
config.cls_hidden = 1
config.hidden_size = 128
config.learning_rate = 0.0001
return config
raise Exception("%s not found"%model_architecture)