raw_data['max_item'], name='Test', num_negatives=500) train_sampler = StratifiedPointwiseSampler(pos_ratio=0.2, batch_size=batch_size, dataset=train_dataset, num_process=5) val_sampler = EvaluationSampler(batch_size=batch_size, dataset=val_dataset) test_sampler = EvaluationSampler(batch_size=batch_size, dataset=test_dataset) model = PMF(batch_size=batch_size, total_users=train_dataset.total_users(), total_items=train_dataset.total_items(), dim_user_embed=dim_embed, dim_item_embed=dim_embed, save_model_dir='pmf_recommender/', train=True, serve=True) auc_evaluator = AUC() recall_evaluator = Recall(recall_at=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) model_trainer = ModelTrainer(model=model) model_trainer.train(total_it=total_it, eval_it=eval_it, save_it=save_it, train_sampler=train_sampler, eval_samplers=[val_sampler, test_sampler], evaluators=[auc_evaluator, recall_evaluator])
pos_ratio=pos_ratio) #Model Trainer eval_save_prefix = '/home/ubuntu/openrec/models/fhmf_models/{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}/'.format( sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[7], sys.argv[8], sys.argv[9], sys.argv[10]) if dataset_name == "amazon_book": eval_save_prefix = None model_trainer = ImplicitModelTrainer(batch_size=batch_size, test_batch_size=test_batch_size, train_dataset=train_dataset, model=fhmf_model, sampler=sampler, eval_save_prefix=eval_save_prefix) #Evaluators auc_evaluator = AUC() recall_evaluator = Recall(recall_at=[10, 50, 100, 300]) #mse_evaluator = MSE() #Train model_trainer.train(num_itr=num_itr, display_itr=display_itr, eval_datasets=[focused_val_set, focused_test_set], evaluators=[auc_evaluator, recall_evaluator], num_negatives=num_negatives) elif recommender == "PMF": model = PMF(batch_size=batch_size, max_user=train_dataset.max_user(), max_item=train_dataset.max_item(), dim_embed=50, opt='Adam',
trainset_path = "/Users/xuan/Documents/Specialization Project/openrec/dataset/citeulike/user_data_train.npy" ### # trainset = np.load(trainset_path) trainset = trainset['user_id'] frequency = dict() for i in trainset: if i in frequency: frequency[i] += 1 else: frequency[i] = 1 # auc_evaluator = AUC() recall_evaluator = Recall(recall_at=[10]) precision_evaluator = Precision(precision_at=[10]) ndcg_evaluator = NDCG(ndcg_at=[10]) f = open(infilename, 'rb') p = pickle.load(f) f.close() score_per_user = dict() count_per_user = dict() for user in p['users']: neg_scores = p['results'][user][:p['num_negatives']] for i in range(len(p['user_items'][user][p['num_negatives'] : ])): pos_score = p['results'][user][p['num_negatives'] + i] rank_above = np.array([ float(np.sum(neg_scores > pos_score)) ])
total_items, sortby='ts', name='Test') train_sampler = TemporalSampler(batch_size=batch_size, max_seq_len=max_seq_len, dataset=train_dataset, num_process=1) test_sampler = TemporalEvaluationSampler(dataset=test_dataset, max_seq_len=max_seq_len) model = VanillaYouTubeRec(batch_size=batch_size, total_items=train_dataset.total_items(), max_seq_len=max_seq_len, dim_item_embed=dim_item_embed, save_model_dir='vanilla_youtube_recommender/', train=True, serve=True) model_trainer = ModelTrainer(model=model) auc_evaluator = AUC() recall_evaluator = Recall(recall_at=[100, 200, 300, 400, 500]) model_trainer.train(total_iter=total_iter, eval_iter=eval_iter, save_iter=save_iter, train_sampler=train_sampler, eval_samplers=[test_sampler], evaluators=[auc_evaluator, recall_evaluator])
total_users=total_users, total_items=total_items, sortby='ts', name='Test') train_sampler = TemporalSampler(batch_size=batch_size, max_seq_len=max_seq_len, dataset=train_dataset, num_process=1) test_sampler = TemporalEvaluationSampler(dataset=test_dataset, max_seq_len=max_seq_len) rnn_model = RNNRec(batch_size=batch_size, dim_item_embed=dim_item_embed, max_seq_len=max_seq_len, total_items=train_dataset.total_items(), num_units=num_units, save_model_dir='rnn_recommender/', train=True, serve=True) model_trainer = ModelTrainer(model=rnn_model) auc_evaluator = AUC() recall_evaluator = Recall(recall_at=[100, 500]) model_trainer.train(total_iter=total_iter, eval_iter=eval_iter, save_iter=save_iter, train_sampler=train_sampler, eval_samplers=[test_sampler], evaluators=[auc_evaluator, recall_evaluator])