jfkirk / tensorrec

A TensorFlow recommendation algorithm and framework in Python.
Apache License 2.0
1.28k stars 222 forks source link

Is it possible to add a new user with interactions to a trained model and receive recommendations? #116

Open SkylarWolfLA opened 5 years ago

SkylarWolfLA commented 5 years ago

I have been playing with TensorRec for the last few days and am very impressed! Thank you for your hard work on this!

Question: As far as I understand it is possible to input a new user into a trained model and receive recommendations/predictions for items based on the user features. Is it possible to also input the interactions for the new user as well? I may be misunderstanding but it seems to me that without the interactions (ratings for items in my case), that the system will basically be a content-based recommender. I was hoping to create an on-line hybrid system using both the user features and user-item ratings for a new user. After seeing the comments you made on https://github.com/jfkirk/tensorrec/issues/93 I started thinking that I could add the user-item ratings into the user features but then I don't really understand what the interactions would be? Maybe I am just trying to use TensorRec for something it was never intended for? I am currently serving the results of the predict_similar_items function but would love to be able to serve customized predictions for a new user. Any help would be much appreciated :)

Background: I am trying to create an on-line hybrid recommender system using TensorRec and thus far I have managed to import my own user features, item features, and interactions in the form of ratings. My ratings are binary (currently -1 for dislike and 1 for like but I may normalize that differently after reading advice you gave another person). I have trained my model with about 1 million users and 17 million ratings on about 15,000 items. I still have to play around with the different tuning functions so that is left to do. I have managed to train and save a model, then load the trained model into a Flask server for serving via an api (I had to ensure the server was single threaded).

jfkirk commented 5 years ago

Hey @teetwoex ! Great question, and thank you for providing your reasoning and context.

You're on the right path and the intuitions you've outlined are largely correct: it's not possible to train from interactions for a user that you did not have at training-time, but you may be able to meaningfully predict from them.

For your system, there are a couple paths you could go down:

You could use only only metadata features for your users. This would mean that a new user would be represented only by their metadata (and not by an indicator/unique feature or their interactions). If your metadata features are rich and descriptive, this could be effective but, as you've highlighted, this would ignore their interactions. Regarding this point I may be misunderstanding but it seems to me that without the interactions (ratings for items in my case), that the system will basically be a content-based recommender.: I wouldn't say that this is a content-based recommender per-se (because you can still have item indicator features), but I would say that this recommender wouldn't be personalizing content for users -- it is simply predicting good recommendations based purely on user metadata.

Similar to what I suggested over in #93 , you could use a user's previous interactions as their user features and use their future interactions as interactions. This will allow you to make use of the new user's interactions, even though you were not able to train the model on that user. This is similar to how many matrix-factorization collaborative filters work but with the big exception that it doesn't simply give you items that are similar to previous items you've liked. For example, if I've already purchased a crib for my baby, I don't just want more cribs recommended but I might want to purchase diapers in the future. You can still use other user metadata features by concatenating them together with interactions.

That said, TensorRec isn't particularly optimized for these sequence-based or session-based recommendation problems and, if you find that this isn't effective, I'd encourage you to search around for some models that fit your use case more directly.

Please let me know either way! I'll leave this issue open for more questions you may have.

SkylarWolfLA commented 5 years ago

@jfkirk thank you so much for your response it is really helpful. I guess my only question so far is that in your example you are only dealing with a user that has visited a few items. It seems like for every item the user has interacted with we need a row in the users matrix and a row in the interactions matrix. In the case of a user who has say interacted with thousands of items what would you do? It seems to me like if you add 1000 rows for 1 user then their interactions will be over-represented right? I was thinking I could sample the interactions over time and limit to some X number of rows per user but was wondering if you had any thoughts on that?

Thank you again!