import os import sys sys.path.append(os.getcwd()) from openrec import ImplicitModelTrainer from openrec.utils import ImplicitDataset from openrec.recommenders import WCML from openrec.utils.evaluators import AUC from openrec.utils.samplers import NPairwiseSampler import dataloader raw_data = dataloader.load_citeulike() batch_size = 2000 test_batch_size = 100 display_itr = 500 train_dataset = ImplicitDataset(raw_data['train_data'], raw_data['max_user'], raw_data['max_item'], name='Train') val_dataset = ImplicitDataset(raw_data['val_data'], raw_data['max_user'], raw_data['max_item'], name='Val') test_dataset = ImplicitDataset(raw_data['test_data'], raw_data['max_user'], raw_data['max_item'], name='Test') model = WCML(batch_size=batch_size, max_user=train_dataset.max_user(), max_item=train_dataset.max_item(), dim_embed=20, neg_num=5, l2_reg=None, opt='Adam', sess_config=None) sampler = NPairwiseSampler(batch_size=batch_size, dataset=train_dataset, negativenum=5, num_process=5) model_trainer = ImplicitModelTrainer(batch_size=batch_size, test_batch_size=test_batch_size, train_dataset=train_dataset, model=model, sampler=sampler) auc_evaluator = AUC() model_trainer.train(num_itr=int(1e5), display_itr=display_itr, eval_datasets=[val_dataset], evaluators=[auc_evaluator], num_negatives=200)
print 'nah' raw_data = dataloader.load_music() print 'yah' batch_size = 1000 test_batch_size = 100 display_itr = 10000 print 'yuck' train_dataset = ImplicitDataset(raw_data['train_data'], raw_data['max_user'], raw_data['max_item'], name='Train') print 'h' val_dataset = ImplicitDataset(raw_data['val_data'], raw_data['max_user'], raw_data['max_item'], name='Val') print 'e' test_dataset = ImplicitDataset(raw_data['test_data'], raw_data['max_user'], raw_data['max_item'], name='Test') print 'here 1' youtube_model = YoutubeRec(batch_size=batch_size, max_user=train_dataset.max_user(), max_item=train_dataset.max_item(), dim_embed=20, sess_config=sess_config, opt='Adam') # bpr_model = FeatureBasedBPR(batch_size=batch_size, max_user=train_dataset.max_user(), max_item=train_dataset.max_item(), # dim_embed=20, opt='Adam', sess_config=sess_config) print 'here 2' sampler = GeneralSampler(batch_size=batch_size, dataset=train_dataset, num_process=1, genre_f = raw_data['song_to_genre']) print 'here 3' model_trainer = ImplicitModelTrainer(batch_size=batch_size, test_batch_size=test_batch_size, train_dataset=train_dataset, model=youtube_model, sampler=sampler) print 'here 4' auc_evaluator = AUC() print 'here 5' model_trainer.train(num_itr=int(1e6), display_itr=display_itr, eval_datasets=[val_dataset, test_dataset], evaluators=[auc_evaluator])
display_itr = 10 train_dataset = ImplicitDataset(raw_data['train_data'], raw_data['max_user'], raw_data['max_item'], name='Train') val_dataset = ImplicitDataset(raw_data['val_data'], raw_data['max_user'], raw_data['max_item'], name='Val') test_dataset = ImplicitDataset(raw_data['test_data'], raw_data['max_user'], raw_data['max_item'], name='Test') max_user = train_dataset.max_user() max_item = train_dataset.max_item() # bpr_model = BPR(batch_size=batch_size, max_user=train_dataset.max_user(), max_item=train_dataset.max_item(), # dim_embed=20, opt='Adam', sess_config=sess_config) # sampler = PairwiseSampler(batch_size=batch_size, # dataset=train_dataset, num_process=5) # model_trainer = ImplicitModelTrainer(batch_size=batch_size, test_batch_size=test_batch_size, # train_dataset=train_dataset, model=bpr_model, sampler=sampler) # auc_evaluator = AUC() # model_trainer.train(num_itr=int(10), display_itr=display_itr, eval_datasets=[val_dataset, test_dataset], # evaluators=[auc_evaluator]) # print("Save") # bpr_model.save("./model", 1)
import os import sys sys.path.append(os.getcwd()) from openrec import ImplicitModelTrainer from openrec.utils import ImplicitDataset from openrec.recommenders import BPR from openrec.utils.evaluators import AUC from openrec.utils.samplers import PairwiseSampler from config import sess_config import dataloader raw_data = dataloader.load_citeulike() batch_size = 1000 test_batch_size = 100 display_itr = 10000 train_dataset = ImplicitDataset(raw_data['train_data'], raw_data['max_user'], raw_data['max_item'], name='Train') val_dataset = ImplicitDataset(raw_data['val_data'], raw_data['max_user'], raw_data['max_item'], name='Val') test_dataset = ImplicitDataset(raw_data['test_data'], raw_data['max_user'], raw_data['max_item'], name='Test') bpr_model = BPR(batch_size=batch_size, max_user=train_dataset.max_user(), max_item=train_dataset.max_item(), dim_embed=20, opt='Adam', sess_config=sess_config) sampler = PairwiseSampler(batch_size=batch_size, dataset=train_dataset, num_process=1) model_trainer = ImplicitModelTrainer(batch_size=batch_size, test_batch_size=test_batch_size, train_dataset=train_dataset, model=bpr_model, sampler=sampler) auc_evaluator = AUC() model_trainer.train(num_itr=int(1e6), display_itr=display_itr, eval_datasets=[val_dataset, test_dataset], evaluators=[auc_evaluator])