Closed Lucky168-1222 closed 1 year ago
When generating a list of recommendations, we need to avoid recommending items that have already been interacted with. The code is used to achieve this goal.
When generating a list of recommendations, we need to avoid recommending items that have already been interacted with. The code is used to achieve this goal.
Thank you for your answer!
When generating a list of recommendations, we need to avoid recommending items that have already been interacted with. The code is used to achieve this goal.
Thank you for your answer!
Hi @zyang1580 , one more related question here. In Create_Recommendation, why adding the "batch_ratings" and "sparse_clicked_matrix" together? In this line
self.main_branchRec_rating = tf.sparse.add(self.Recommender.batch_ratings, self.sparse_cliked_matrix)
Thanks a lot!
The value of 'self.sparse_clicked_matrix' for clicked items is “-np.inf”. Adding it means adjusting the predictions of clicked items in the training set to “-np.inf”.
@zyang1580 get it, thanks for your timely reply!
I want to know the reason of using sparse_clicked_matrix.
def generator_Rec_result_fast(self, model, sess, rec_type): i = 0 result = [] ttt1 = time() for batch_user in self.list_batch_user: batch_item = list(range(ITEM_NUM)) index, row_num, valu_num = self.list_batch_index[i] if self.testing_popularity is not None: pos_pop = self.testing_popularity[batch_item] else: pos_pop = None sparse_cliked_matrix = ( index, np.array([-np.inf] * valu_num).astype(np.float32), np.array([row_num, ITEM_NUM]).astype(np.int64)) batch_topk = model.do_recommendation(sess, batch_user, batch_item, rec_type, pos_pop=pos_pop, sparse_cliked_matrix=sparse_cliked_matrix) i += 1 yield (batch_user, batch_topk)
And when getting main_branch result(for model don't consider injecting predicted popularity (PD/BPRMF)), it remain exist.
self.main_branchRec_rating = tf.sparse.add(self.Recommender.batch_ratings, self.sparse_cliked_matrix) # remove history _, self.main_brach_topk_idx = tf.nn.top_k(self.main_branchRec_rating, topk_max) # topk
If there is something unclear, please point it out. And I sincerely look forward to your answer.