forked from RUCAIBox/RecBole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test_example.py
373 lines (358 loc) · 9.01 KB
/
run_test_example.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# @Time : 2020/7/23
# @Author : Shanlei Mu
# @Email : [email protected]
# UPDATE:
# @Time : 2020/9/16, 2020/9/10
# @Author : Yupeng Hou, Yushuo Chen
# @Email : [email protected], [email protected]
import traceback
from time import time
from recbole.quick_start import run_recbole
closed_examples = ['Test GRU4RecKG', 'Test S3Rec', 'Test DIN']
test_examples = {
'Test Eval Metric': {
'model': 'BPR',
'dataset': 'ml-100k',
'epochs': 1,
'valid_metric': 'Recall@10',
'eval_setting': 'RO_RS, full',
'training_neg_sample_num': 1,
'metrics': ['Precision', 'Hit', 'Recall', 'MRR', 'NDCG'],
'topk': [5, 10, 20],
},
'Test Real Time Full Sort': {
'model': 'BPR',
'dataset': 'ml-100k',
'epochs': 1,
'valid_metric': 'Recall@10',
'metrics': ['Recall'],
'topk': [10],
'eval_setting': 'RO_RS, full',
'real_time_process': True
},
'Test Pre Full Sort': {
'model': 'BPR',
'dataset': 'ml-100k',
'epochs': 1,
'valid_metric': 'Recall@10',
'metrics': ['Recall'],
'topk': [10],
'eval_setting': 'RO_RS, full',
'real_time_process': False
},
'Test Real Time Neg Sample By': {
'model': 'BPR',
'dataset': 'ml-100k',
'epochs': 1,
'valid_metric': 'Recall@10',
'metrics': ['Recall'],
'topk': [10],
'eval_setting': 'RO_RS, uni100',
'real_time_process': True
},
'Test Pre Neg Sample By': {
'model': 'BPR',
'dataset': 'ml-100k',
'epochs': 1,
'valid_metric': 'Recall@10',
'metrics': ['Recall'],
'topk': [10],
'eval_setting': 'RO_RS, uni100',
'real_time_process': False
},
'Test Leave One Out': {
'model': 'BPR',
'dataset': 'ml-100k',
'epochs': 1,
'valid_metric': 'Recall@10',
'metrics': ['Recall'],
'topk': [10],
'eval_setting': 'RO_LS, full',
'leave_one_num': 2,
'real_time_process': True
},
# General Recommendation
'Test BPR': {
'model': 'BPR',
'dataset': 'ml-100k',
},
'Test NeuMF': {
'model': 'NeuMF',
'dataset': 'ml-100k',
},
'Test DMF': {
'model': 'DMF',
'dataset': 'ml-100k',
},
'Test NAIS': {
'model': 'NAIS',
'dataset': 'ml-100k',
},
'Test GCMC': {
'model': 'GCMC',
'dataset': 'ml-100k',
},
'Test NGCF': {
'model': 'NGCF',
'dataset': 'ml-100k',
},
'Test LightGCN': {
'model': 'LightGCN',
'dataset': 'ml-100k',
},
'Test DGCF': {
'model': 'DGCF',
'dataset': 'ml-100k',
},
'Test FISM': {
'model': 'FISM',
'dataset': 'ml-100k'
},
'Test SpectralCF': {
'model': 'SpectralCF',
'dataset': 'ml-100k'
},
'Test POP': {
'model': 'Pop',
'dataset': 'ml-100k',
},
'Test ItemKNN': {
'model': 'ItemKNN',
'dataset': 'ml-100k',
},
'Test ConvNCF': {
'model': 'ConvNCF',
'dataset': 'ml-100k',
},
'Test LINE': {
'model': 'LINE',
'dataset': 'ml-100k',
},
'Test MultiDAE': {
'model': 'MultiDAE',
'dataset': 'ml-100k',
},
'Test MultiVAE': {
'model': 'LINE',
'dataset': 'ml-100k',
},
'Test MacridVAE': {
'model': 'MacridVAE',
'dataset': 'ml-100k',
},
# Context-aware Recommendation
'Test FM': {
'model': 'FM',
'dataset': 'ml-100k',
},
'Test DCN': {
'model': 'DCN',
'dataset': 'ml-100k',
},
'Test xDeepFM': {
'model': 'xDeepFM',
'dataset': 'ml-100k',
},
'Test AFM': {
'model': 'AFM',
'dataset': 'ml-100k',
},
'Test AUTOINT': {
'model': 'AutoInt',
'dataset': 'ml-100k',
},
'Test DeepFM': {
'model': 'DeepFM',
'dataset': 'ml-100k',
},
'Test DSSM': {
'model': 'DSSM',
'dataset': 'ml-100k',
},
'Test FFM': {
'model': 'FFM',
'dataset': 'ml-100k',
},
'Test FNN': {
'model': 'FNN',
'dataset': 'ml-100k',
},
'Test FwFM': {
'model': 'FwFM',
'dataset': 'ml-100k',
},
'Test LR': {
'model': 'LR',
'dataset': 'ml-100k',
},
'Test NFM': {
'model': 'NFM',
'dataset': 'ml-100k',
},
'Test PNN': {
'model': 'PNN',
'dataset': 'ml-100k',
},
'Test WideDeep': {
'model': 'WideDeep',
'dataset': 'ml-100k',
},
# Sequential Recommendation
'Test GRU4Rec': {
'model': 'GRU4Rec',
'dataset': 'ml-100k',
},
'Test FPMC': {
'model': 'FPMC',
'dataset': 'ml-100k',
},
'Test Caser': {
'model': 'Caser',
'dataset': 'ml-100k',
'reproducibility': False,
},
'Test TransRec': {
'model': 'TransRec',
'dataset': 'ml-100k',
},
'Test SASRec': {
'model': 'SASRec',
'dataset': 'ml-100k',
},
'Test BERT4Rec': {
'model': 'BERT4Rec',
'dataset': 'ml-100k',
},
'Test STAMP': {
'model': 'STAMP',
'dataset': 'ml-100k',
},
'Test NARM': {
'model': 'NARM',
'dataset': 'ml-100k',
},
'Test NextItNet': {
'model': 'NextItNet',
'dataset': 'ml-100k',
'reproducibility': False,
},
'Test SRGNN': {
'model': 'SRGNN',
'dataset': 'ml-100k',
'MAX_ITEM_LIST_LENGTH': 3,
},
'Test GCSAN': {
'model': 'GCSAN',
'dataset': 'ml-100k',
'MAX_ITEM_LIST_LENGTH': 3,
},
'Test GRU4RecF': {
'model': 'GRU4RecF',
'dataset': 'ml-100k',
},
'Test SASRecF': {
'model': 'SASRecF',
'dataset': 'ml-100k',
},
'Test FDSA': {
'model': 'FDSA',
'dataset': 'ml-100k',
},
'Test S3Rec': {
},
'Test GRU4RecKG': {
'model': 'GRU4RecKG',
'dataset': 'ml-1m',
'TIME_FIELD': 'timestamp',
'HEAD_ENTITY_ID_FIELD': 'head_id',
'TAIL_ENTITY_ID_FIELD': 'tail_id',
'RELATION_ID_FIELD': 'relation_id',
'ENTITY_ID_FIELD': 'entity_id',
'MAX_ITEM_LIST_LENGTH': 50,
'LIST_SUFFIX': '_list',
'ITEM_LIST_LENGTH_FIELD': 'item_length',
'load_col': {
'inter': ['user_id', 'item_id', 'rating', 'timestamp'],
'feature': ['ent_id', 'ent_feature']
},
'additional_feat_suffix': ['feature'],
'fields_in_same_space': [['entity_id', 'ent_id']],
'preload_weight': {
'ent_id': 'ent_feature'
}
},
'Test DIN': {
'model': 'DIN',
'dataset': 'ml-100k',
'training_neg_sample_num': 1,
'eval_setting': 'TO_LS, uni100',
'load_col': {'inter': ['user_id', 'item_id', 'rating', 'timestamp'],
'user': ['user_id', 'age', 'gender', 'occupation'],
'item': ['item_id', 'release_year']},
'threshold': {'rating': 4},
'valid_metric': 'AUC',
'metrics': ['AUC'],
'eval_batch_size': 10000,
},
# Knowledge-based Recommendation
'Test CKE': {
'model': 'CKE',
'dataset': 'ml-100k',
},
'Test KTUP': {
'model': 'KTUP',
'dataset': 'ml-100k',
'train_rec_step': 1,
'train_kg_step': 1,
'epochs': 2,
},
'Test CFKG': {
'model': 'CFKG',
'dataset': 'ml-100k',
},
'Test KGAT': {
'model': 'KGAT',
'dataset': 'ml-100k',
},
'Test RippleNet': {
'model': 'RippleNet',
'dataset': 'ml-100k',
},
'Test MKR': {
'model': 'MKR',
'dataset': 'ml-100k',
},
'Test KGCN': {
'model': 'KGCN',
'dataset': 'ml-100k',
},
'Test KGNNLS': {
'model': 'KGNNLS',
'dataset': 'ml-100k',
},
}
def run_test_examples():
test_start_time = time()
success_examples, fail_examples = [], []
n_examples = len(test_examples.keys())
for idx, example in enumerate(test_examples.keys()):
if example in closed_examples:
continue
print('\n\n Begin to run %d / %d example: %s \n\n' % (idx + 1, n_examples, example))
try:
config_dict = test_examples[example]
if 'epochs' not in config_dict:
config_dict['epochs'] = 1
run_recbole(config_dict=config_dict, saved=False)
print('\n\n Running %d / %d example successfully: %s \n\n' % (idx + 1, n_examples, example))
success_examples.append(example)
except Exception:
print(traceback.format_exc())
fail_examples.append(example)
test_end_time = time()
print('total test time: ', test_end_time - test_start_time)
print('success examples: ', success_examples)
print('fail examples: ', fail_examples)
print('\n')
if __name__ == '__main__':
run_test_examples()