Save & Serve tfrs that does not recommend items previously interacted with using BruteForce layer
See original GitHub issueI am working with a relatively small data set and am noticing that users are being recommended a lot of items they have previously interacted with and I would like to pre-filter out these items before saving and serving the mode on ai platform. I realize this could also be done after the list has been generated, but the way our app works makes it rather difficult (and slow) to filter post hoc on the client side.
I have seen a few other issues addressing related questions (e.g., 307, 113). However, I have not seen a definitive solution, and these seem to deal with either excluding a set of items for all users (rather than a unique set for each user), or excluding items from test recommendations.
Currently, I generate an index with 80 recommended items: index = tfrs.layers.factorized_top_k.BruteForce(model.user_model, k = 80)
and then remove any duplicates that existed in the training df: index.index_from_dataset( tf.data.Dataset.zip((unique_recipe_id_pred.batch(80), unique_recipe_id_pred.batch(80).map(model.recipe_model))))
This works well, but how could I also exclude items in the index that users have interacted with? Could the query with exclusions function be a possible solution?
Apologies if I have missed something here and thanks in advance for any advice!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5

Top Related StackOverflow Question
@maciejkula & @patrickorlando thank you both for your thoughts on this. I am curious if you could point me to any code regarding the second option of wrapping the BruteForce index in a model with logic, I fear my technical skills are not sufficient to figure it out alone. In the meantime, using your suggestion we have added a middle (business) layer using React Native to filter out previously interacted with items, which whilst slowing us down ~.5 seconds per call, has solved the problem.
You need to track the state of what user’s have interacted with separately from the model. If for each user you maintain a list of item_ids that the user has interacted with, you can then filter them out in your caller API, or wrap the BruteForce Index in a model with some logic to remove them.