Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sivaramaaa opened this issue Sep 26, 2023 · 4 comments
Open
Labels
help wanted Need help from developers

Comments

@sivaramaaa
Copy link

sivaramaaa commented Sep 26, 2023

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 .

@sivaramaaa sivaramaaa added the help wanted Need help from developers label Sep 26, 2023
@sivaramaaa
Copy link
Author

sivaramaaa commented Sep 26, 2023

Are these id's same as News id's present in MIND dataset with the "N" removed ?

I also feel the way i am getting userid is not the ideal way , i am just inputting a Vector index . So i would like to know how to give user id like 'U28498' as input to perform the prediction .

@sivaramaaa sivaramaaa changed the title [ASK] How to convert News Vector from run_news to News id [ASK] How to get top recommendations for a given user id - LSTURModel Sep 26, 2023
@cclinet
Copy link
Contributor

cclinet commented Nov 3, 2023

In the MINDIterator, there are two attributes, uid2index and nid2index, which respectively keep track of mappings from user IDs to indices and news IDs to indices. It's important to note that the numbers you input and obtain are indeed indices. To retrieve the corresponding user ID or news ID, you should use these dictionaries for mapping.

@sivaramaaa
Copy link
Author

Hi @cclinet :

Thanks a lot for the reply , but i had tried accessing nid2index at the time of filling this issue itself , it was not accessible as i guess it's a private property which is not exposed :

iterator = MINDIterator
nid2index = iterator.nid2index
index2nid = {index: nid for nid, index in nid2index.items()}
top_10_news_ids = [index2nid[index] for index in top_10_news]
print("Top 10 news recommendations for user:", uid)
print(top_10_news_ids)

This is the error i got :

AttributeError: type object 'MINDIterator' has no attribute 'nid2index'

If possible can you let me know if there is a way to access this property .

@cclinet
Copy link
Contributor

cclinet commented Nov 8, 2023

Try to get the iterator using model.train_iterator or model.test_iterator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Need help from developers
Projects
None yet
Development

No branches or pull requests

2 participants