-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_templates.py
339 lines (298 loc) · 9.54 KB
/
config_templates.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import argparse
config_elliot = """experiment:
backend: pytorch
data_config:
strategy: fixed
train_path: ../data/{{0}}/train_indexed.tsv
validation_path: ../data/{{0}}/val_indexed.tsv
test_path: ../data/{{0}}/test_indexed.tsv
side_information:
- dataloader: VisualAttribute
visual_features: ../data/{{0}}/visual_embeddings_indexed_{batch_size}/{visual_path}
- dataloader: TextualAttribute
textual_features: ../data/{{0}}/textual_embeddings_indexed_{batch_size}/{textual_path}
dataset: {dataset}
top_k: 20
evaluation:
cutoffs: [ 20 ]
simple_metrics: [ Recall, Precision, nDCG, HR ]
gpu: 0
external_models_path: ../external/models/__init__.py
models:
external.VBPR:
meta:
hyper_opt_alg: grid
verbose: True
save_weights: False
save_recs: False
validation_rate: 10
validation_metric: Recall@20
restore: False
lr: [ 0.0001, 0.0005, 0.001, 0.005, 0.01 ]
modalities: ('visual', 'textual')
epochs: 200
factors: 64
batch_size: 1024
l_w: [ 1e-5, 1e-2 ]
comb_mod: concat
loaders: ('VisualAttribute', 'TextualAttribute')
seed: 123
external.BM3:
meta:
hyper_opt_alg: grid
verbose: True
save_weights: False
save_recs: False
validation_rate: 10
validation_metric: Recall@20
restore: False
lr: [ 0.0001, 0.0005, 0.001, 0.005, 0.01 ]
multimod_factors: 64
reg_weight: [ 0.1, 0.01 ]
cl_weight: 2.0
dropout: 0.3
n_layers: 2
modalities: ('visual', 'textual')
loaders: ('VisualAttribute', 'TextualAttribute')
epochs: 200
factors: 64
lr_sched: (1.0,50)
batch_size: 1024
seed: 123
external.FREEDOM:
meta:
hyper_opt_alg: grid
verbose: True
save_weights: False
save_recs: False
validation_rate: 10
validation_metric: Recall@20
restore: False
lr: [ 0.0001, 0.0005, 0.001, 0.005, 0.01 ]
factors: 64
epochs: 200
l_w: [ 1e-5, 1e-2 ]
n_layers: 1
n_ui_layers: 2
top_k: 10
factors_multimod: 64
modalities: ('visual', 'textual')
loaders: ('VisualAttribute', 'TextualAttribute')
mw: (0.1,0.9)
drop: 0.8
lr_sched: (1.0,50)
batch_size: 1024
seed: 123
external.NGCFM:
meta:
hyper_opt_alg: grid
verbose: True
save_weights: False
save_recs: False
validation_rate: 10
validation_metric: Recall@20
restore: False
lr: [ 0.0001, 0.0005, 0.001, 0.005, 0.01 ]
epochs: 200
n_layers: 3
factors: 64
weight_size: 64
node_dropout: 0.1
message_dropout: 0.1
batch_size: 1024
modalities: ('visual', 'textual')
loaders: ('VisualAttribute','TextualAttribute')
normalize: True
l_w: [ 1e-5, 1e-2 ]
seed: 123
external.GRCN:
meta:
hyper_opt_alg: grid
verbose: True
save_weights: False
save_recs: False
validation_rate: 10
validation_metric: Recall@20
restore: False
lr: [0.0001, 0.001, 0.01, 0.1, 1]
epochs: 200
num_layers: 2
num_routings: 3
factors: 64
factors_multimod: 128
batch_size: 1024
aggregation: add
weight_mode: confid
pruning: True
has_act: False
fusion_mode: concat
modalities: ('visual', 'textual')
l_w: [1e-5, 1e-2]
seed: 123
external.LATTICE:
meta:
hyper_opt_alg: grid
verbose: True
save_weights: False
save_recs: False
validation_rate: 10
validation_metric: Recall@20
restore: False
epochs: 200
batch_size: 1024
factors: 64
lr: [0.0001, 0.0005, 0.001, 0.005, 0.01]
l_w: [1e-5, 1e-2]
n_layers: 1
n_ui_layers: 2
top_k: 20
l_m: 0.7
factors_multimod: 64
modalities: ('visual', 'textual')
seed: 123
"""
config_ducho = """dataset_path: ./local/data/demo_{dataset}
gpu list: 0
visual:
items:
input_path: images
output_path: visual_embeddings_{batch_size}
model: [
{{ model_name: ResNet50, output_layers: avgpool, reshape: [224, 224], preprocessing: zscore, backend: torch, batch_size: {batch_size}}},
{{ model_name: ./demos/demo_{dataset}/MMFashion.pt, output_layers: avgpool, reshape: [224, 224], preprocessing: zscore, backend: torch, batch_size: {batch_size}}},
]
textual:
items:
input_path: meta.tsv
item_column: asin
text_column: description
output_path: textual_embeddings_{batch_size}
model: [
{{ model_name: sentence-transformers/all-mpnet-base-v2, output_layers: 1, clear_text: False, backend: sentence_transformers, batch_size: {batch_size}}},
]
visual_textual:
items:
input_path: {{visual: images, textual: meta.tsv}}
item_column: asin
text_column: description
output_path: {{visual: visual_embeddings_{batch_size}, textual: textual_embeddings_{batch_size}}}
model: [
{{ model_name: openai/clip-vit-base-patch16, backend: transformers, output_layers: 1, batch_size: {batch_size}}},
{{ model_name: kakaobrain/align-base, backend: transformers, output_layers: 1, batch_size: {batch_size}}},
{{ model_name: BAAI/AltCLIP, backend: transformers, output_layers: 1, batch_size: {batch_size}}},
]
"""
split_config = '''
experiment:
backend: pytorch
data_config:
strategy: dataset
dataset_path: ../data/{{0}}/reviews.tsv
splitting:
save_on_disk: True
save_folder: ../data/{{0}}_splits/
test_splitting:
strategy: random_subsampling
test_ratio: 0.2
validation_splitting:
strategy: random_subsampling
test_ratio: 0.1
dataset: {dataset}
top_k: 20
evaluation:
cutoffs: [ 10, 20 ]
simple_metrics: [ Recall, nDCG ]
gpu: 0
external_models_path: ../external/models/__init__.py
models:
MostPop:
meta:
verbose: True
save_recs: True
'''
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', choices=['baby', 'office', 'music', 'toys', 'beauty'], help="Dataset name.", required=True)
parser.add_argument('--batch_size', type=int, help="Batch size.", required=True)
args = parser.parse_args()
demo_1 = {
"visual_path": "torch/ResNet50/avgpool",
"textual_path": "sentence_transformers/sentence-transformers/all-mpnet-base-v2/1"
}
elliot_1 = config_elliot.format(
batch_size=args.batch_size,
dataset=args.dataset,
visual_path=demo_1["visual_path"],
textual_path=demo_1["textual_path"]
)
elliot_dir = f"./config_files/{args.dataset}_1_{args.batch_size}.yml"
with open(elliot_dir, 'w') as conf_file:
conf_file.write(elliot_1)
del elliot_1, demo_1, elliot_dir
demo_2 = {
"visual_path": "transformers/openai/clip-vit-base-patch16/1",
"textual_path": "transformers/openai/clip-vit-base-patch16/1"
}
elliot_2 = config_elliot.format(
batch_size=args.batch_size,
dataset=args.dataset,
visual_path=demo_2["visual_path"],
textual_path=demo_2["textual_path"]
)
elliot_dir = f"./config_files/{args.dataset}_2_{args.batch_size}.yml"
with open(elliot_dir, 'w') as conf_file:
conf_file.write(elliot_2)
del elliot_2, demo_2, elliot_dir
demo_3 = {
"visual_path": "torch/MMFashion/avgpool",
"textual_path": "sentence_transformers/sentence-transformers/all-mpnet-base-v2/1"
}
elliot_3 = config_elliot.format(
batch_size=args.batch_size,
dataset=args.dataset,
visual_path=demo_3["visual_path"],
textual_path=demo_3["textual_path"]
)
elliot_dir = f"./config_files/{args.dataset}_3_{args.batch_size}.yml"
with open(elliot_dir, 'w') as conf_file:
conf_file.write(elliot_3)
del elliot_3, demo_3, elliot_dir
demo_4 = {
"visual_path": "transformers/kakaobrain/align-base/1",
"textual_path": "transformers/kakaobrain/align-base/1"
}
elliot_4 = config_elliot.format(
batch_size=args.batch_size,
dataset=args.dataset,
visual_path=demo_4["visual_path"],
textual_path=demo_4["textual_path"]
)
elliot_dir = f"./config_files/{args.dataset}_4_{args.batch_size}.yml"
with open(elliot_dir, 'w') as conf_file:
conf_file.write(elliot_4)
del elliot_4, demo_4, elliot_dir
demo_5 = {
"visual_path": "transformers/BAAI/AltCLIP/1",
"textual_path": "transformers/BAAI/AltCLIP/1"
}
elliot_5 = config_elliot.format(
batch_size=args.batch_size,
dataset=args.dataset,
visual_path=demo_5["visual_path"],
textual_path=demo_5["textual_path"]
)
elliot_dir = f"./config_files/{args.dataset}_5_{args.batch_size}.yml"
with open(elliot_dir, 'w') as conf_file:
conf_file.write(elliot_5)
del elliot_5, demo_5, elliot_dir
split_dir = f"./config_files/split_{args.dataset}.yml"
with open(split_dir, 'w') as conf_file:
conf_file.write(split_config.format(dataset=args.dataset))
del split_dir
ducho = config_ducho.format(
dataset=args.dataset,
batch_size=args.batch_size
)
ducho_dir = f"./Ducho/demos/demo_{args.dataset}/config.yml"
with open(ducho_dir, 'w') as conf_file:
conf_file.write(ducho)