Last active
June 1, 2019 08:06
-
-
Save singhrahuldps/6ff6a512f56e2cbcecc9ba8dd20f79c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def recommend_item_for_user(model, user_id): | |
| m = model.eval().cpu() | |
| user_ids = torch.LongTensor([user2idx[u] for u in [user_id]*len(items)]) | |
| item_ids = torch.LongTensor([item2idx[b] for b in items]) | |
| remove = set(ratings[ratings[user_col] == user_id][item_col].values) | |
| preds = m(user_ids,item_ids).detach().numpy() | |
| pred_item = [(p,b) for p,b in sorted(zip(preds,items), reverse = True) if b not in remove] | |
| return pred_item | |
| def recommend_user_for_item(model, item_id): | |
| m = model.eval().cpu() | |
| user_ids = torch.LongTensor([user2idx[u] for u in users]) | |
| book_ids = torch.LongTensor([item2idx[b] for b in [item_id]*len(users)]) | |
| remove = set(ratings[ratings[item_col] == book_id][user_col].values) | |
| preds = m(user_ids,item_ids).detach().numpy() | |
| pred_user = [(p,u) for p,u in sorted(zip(preds,users), reverse = True) if u not in remove] | |
| return pred_user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment