-
Notifications
You must be signed in to change notification settings - Fork 220
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
How to use TensorRec for a session-based scenario? #93
Comments
Hey @hodaraad ! This is a really interesting problem. I think one way you could tackle it would be to use the items in the session so-far at time T as "user features," then use the next (or all) interactions after time T as interactions values. This would give you data shapes like: user_features = [n_session_time_pairs x n_items] <- interactions up to time T This would allow you to predict ad-hoc during a session that you've never seen before. You'd just assemble the set of items which have already been interacted in the session, and predict for them as if they are "user features". What do you think? I'm very interested to know if you try this out and how it works. I'll leave the issue open for a while. |
Thank you so much James for taking time to answer my question. What I had pictured first was something simpler which would be to get item_embeddings for all visited items of the test session, get their average and take this as user representation for that session. Then, find similar items from the training set to that average item-embedding vector. Then, I thought maybe instead of just the above nearest neighbour search, we can actually use those item representations (either in some aggregated form such as average, or consider them as a set) as user_features which was my question in this post. Your answer seems to be inline with my second approach (actually using item_embeddings as user_feature parameter). But, still I don't fully get it. Would you mind elaborate more on it? what is "n_session_time_pairs" and do you use user_features with set of observed items in the training as well or just use identity matrix for them (assuming we have no user or item features). If you can provide some psduo-code or point to specific methods in the repo, it will be wonderful. Also, let me know if the first simple nearest neighbour option would make sense as another alternative to you or not. Thanks |
oh, also forgot to ask: Do you need to provide the interaction matrix at the prediction when trying to recommend similar items for a given user and item? I thought the interface would be to get a trained mode, and a pair of user/item features (or just their ids in case we don't have any content features for them) and get a ranked list of items. Does the system get any use of other interacted items of this user at prediction time? I'm asking this because you had mentioned the following in your answer: interactions = [n_session_time_pairs x n_items] <- interactions after time T |
@hodaraad How about you post some code for your use case? |
Hey @hodaraad -- I like your first approach, which could be written as a post-process around TensorRec:
If you wanted try to tackle this internal to the model, you could try an approach like: User features = Interactions = In this case there are two "session time pairs". Does this make sense? You do not need to provide interactions at prediction time -- only user/item features. |
Thank you so much James for taking time to answer. It does make sense. So, after training, providing that user_features in your example, should give similar items for item_0 first, then items that are similar to both item_0 and item_5, and so on. I don't know how much the list of similar items as we proceed in the session will be different, or how much this aggregated way of representing sessions will be useful (we are assuming all or most items visited within a session are related). But, I was going to implement it and will share the code once I got it done. I was also thinking I could do a similar user-based approach by exporting user representation after the model is trained, and look for similar users (sessions), then weight relatedness of each item for the current test session by its apprearance in similar sessions and their similarity levels: score(i, s) = sum (sim(s, s') * imp(i, s')) where i is an item, s is the test session, s' is one of the similar sessions to s, and imp(i,s') is a function representing how important i is for session s'. In simple case, it can be just a binary function representing whether i appeared in s'. In more advance cases, we can assign higher weights to more recent appeared items of each session. I will let you know if I could get anything with either of these approaches. Finally, I still don't get why in your example, you have Interactions matrix as well. If this is for prediction time, you said we don't need to provide that (though I checked the code, and I think for some evaluation metrics we need to provide that as a sort of ground truth). If it's for training, then we provide full sessions and don't need to give each state of the session as a new instance. What am I missing then? Thanks again. This discussion was very helpful for me. |
This Airbnb blog by Mihajlo on finding similar listings has some ideas that might help |
Hi James,
Sorry I have another question for using TensorRec for the session-based case.
As you may know in session-based recommendation systems, the assumption is we cannot track users and we only work at the session-level. So, each new session is assumed to be a new user.
Given a session that has progressed to some level (some items have already been visited in that session), I wanted to predict the other interesting items for that session. I thought I could just assign a new user-id to each session and build the interaction matrix from the training data (it will probably be a sparse one). But then at prediction, given a new session I was confused how to proceed given it will be a new user-id not seen in the training data. I know there is no requirement in TensorRec and LightFM frameworks to use them with users from training data as we can represent users with their features and it does not matter if these features are for a new user or not. But, for my case I don't use any feature for sessions and items right now other than their ids.
So I'm wondering if there is any way to represent new sessions using the current observed items and then find the most similar items to the last item of this session and its item-based representation (so user features will be the set of observed items of the session up to now).
Thanks
p.s: I asked this question in LightFM repos as well and have not received any answer yet. I hope I get some advice from you as the libraries are quite similar and effective for my current need.
The text was updated successfully, but these errors were encountered: