lyst / lightfm

A Python implementation of LightFM, a hybrid recommendation algorithm.
Apache License 2.0
4.77k stars 691 forks source link

How can I learn the latent vectors of a new user? #371

Closed dimitris93 closed 3 years ago

dimitris93 commented 6 years ago

Hello. I have a question regarding your library.

Let's suppose that I have already trained a hybrid model using a user-item rating matrix for training, and also included some user_features during training.

How can I quickly get the latent features for a new test user (for whom I also have user-features)? And how to provide top-n recommendations for that new user? Would I have to re-train the model? That would be really slow, right? How does this work exactly?

DoronGi commented 6 years ago

I found this helpful #210.

Basically in the hybrid model each user is represented by an identity feature, together with all other relevant features for that user. The latent representation is then just the sum of all the feature's representations. For a new user you don't have an identity feature, but everything else is exactly the same.

You can create a new user_features sparse matrix of size (1, num_of_features) for the new user, and use it in predict. In that case use user_id=0 when calling the function to indicate that you want to use the first (and only) row in your user_features matrix.

dimitris93 commented 6 years ago

I'm not sure that you understood the question. Maybe I did not explain it well enough. Let's assume I have:

users tracks "like" user-track interactions in a sparse matrix users' (age, gender) information in a matrix of dimension: [num_users x 2]

Let's say that I have already trained model. Now a new user comes in the system. He is a 25 year old male. He likes 5 songs. How to recommend n=50 songs to this new user?

DoronGi commented 6 years ago

I believe that with this library you would have to retrain, or at least continue training (fit_partial) from your previous model (provided that you pre-prepared additional self-features for the new users).

Without additional training all you can do is to generate recommendations based on the user features, or recommend items similar to the items the user has interacted with.

maciejkula commented 6 years ago

@DoronGi's answer is exactly right. Thanks!

SimonCW commented 3 years ago

I’m closing this issue because it has been inactive for a long time. If you still encounter the problem, please open a new issue.

Thank you!