lyst / lightfm

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

What does the weight matrix do for implicit rating? #441

Open tianpunchh opened 5 years ago

tianpunchh commented 5 years ago

As far as I know, lightfm is dealing with implicit interaction matrix, i.e., 0s and 1s. However it can also creates a weight matrix separately and get into the training. I think if you call "Dataset().build_interaction()" function, what it does is extracting the original interaction data to interaction matrix and weight matrix. Say a rating of 3.5, then there will be a "1" field in interaction matrix and "3.5" will go to weight matrix.

My question is what does the weight matrix really do for the training? We know for an explicit interaction, the goal is trying to fit those explicit scores directly. For lightfm, however, the target is 0/1 indicators. Therefore the role of weight is not quite clear to me. Does it change the learning rate or convergency criteria for each individual interaction entity? Be more specific, if we have two records [1, 5], then interaction_matrix = [1, 1] and weight_matrix = [1, 5], what would be different for lightfm to deal with them considering interactions are both 1 but weights are different, would it be slightly tending towards weight of 5 record?

maciejkula commented 5 years ago

It multiplies the loss by the weight for that particular example.

This means that the model takes larger gradient steps, trying to fit these examples more closely than others. This is almost (if not quite) analogous to repeating that example weight times.

emudria commented 4 years ago

Building on the same discussion, I am building a recsys using Light FM, on our estore. I have got interactions, where a user has purchased an item - and then there are users who has bought same item multiple times. To feed these explici weights, I have done following 1 - The number of times a user has purchased an item - hence if someone has purchased an items10 times, the weight I have given is 10. 2- Since, we also got a timestamp against each item purchased, and I thought it would make more sense to prioritise purchases that users have done in recent past as opposed to 2 years ago, I have calculated number of days elapsed for each interaction.

For the weights, I have fed weights = (Number of times an item has been purchased by a user/ number of days elapsed since this user purchased this item last time)

would be great if you could kindly comment on following: does this technique makes any sense to you second, this would bring most numbers below 1, how would model behave in such case.

P.S. If it were working fine, I wouldnt come here, but when I input these weights, mostly the model outputs same items for all users, but if I dont, I get decent output. Thanks.