recommenders-team/recommenders

[ASK] How to get top recommendations for a given user id - LSTURModel

Open

#1,999 opened on 2023年9月26日

GitHub で見る
 (4 comments) (0 reactions) (0 assignees)Python (2,972 forks)batch import
help wanted

Repository metrics

Stars
 (17,706 stars)
PR merge metrics
 (平均マージ 6d 16h) (30d で 10 merged PRs)

説明

Description

Hi , I am trying to get top 10 news recommendations for given user id . Below is the code which i am using for it :

iterator = MINDIterator
model = LSTURModel(hparams, iterator, seed=seed)
print(model.run_eval(valid_news_file, valid_behaviors_file))
model.fit(train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file)


news_vecs = model.run_news(valid_news_file)
user_vecs = model.run_user(valid_news_file, valid_behaviors_file)

uid = list(user_vecs.keys())[10] # This a random test user id for which i need news recommendations
user_vec = user_vecs[uid]
scores = {news_id: np.dot(user_vec, news_vec) for news_id, news_vec in news_vecs.items()}
top_10_news = sorted(scores, key=scores.get, reverse=True)[:10]

print("Top 10 news recommendations for user:", uid)
print(top_10_news)

So the output i get is an array of id's like this : [12580, 10755, 13550, 2500, 5302, 4810, 18519, 18187, 3741, 13954]

I am looking to convert these id's to Actual New item id's like : N15366 , N18191 etc -- using which i could get the News titles .

Any help would be greatly appreciated .

コントリビューターガイド