Excluding previously seen samples from test recommendations, on TFRS

Hello everyone,

I was following TensorFlow’s Recommending movies: retrieval tutorial, aiming to adapt it to my problem: It is a similar recommender system, with the difference that previously seens samples must be excluded at all times. The only section where I read something slightly related on that issue (and in general, on TFRS documentation), was the following:

Test set performance is much worse than training performance. This is due to two factors:

  1. Our model is likely to perform better on the data that it has seen, simply because it can memorize it. This overfitting phenomenon is especially strong when models have many parameters. It can be mediated by model regularization and use of user and movie features that help the model generalize better to unseen data.
  2. The model is re-recommending some of users’ already watched movies. These known-positive watches can crowd out test movies out of top K recommendations.

The second phenomenon can be tackled by excluding previously seen movies from test recommendations. This approach is relatively common in the recommender systems literature, but we don’t follow it in these tutorials. If not recommending past watches is important, we should expect appropriately specified models to learn this behaviour automatically from past user history and contextual information. Additionally, it is often appropriate to recommend the same item multiple times (say, an evergreen TV series or a regularly purchased item).

This is OK as a theoretical explanation, but now I have the following questions:

  • Excluding previously seen samples is something currently feasible with TFRS, and if so, how to do it?
  • What the article refers as Test set is actually that set, or a CV Set?

Would be nice if the explanation uses the code of the linked tutorial, as foundation for any explanation.

Thank you very much!

PS.: Tried to include a link to TensorFlow’s Recommending movies: retrieval tutorial, but the automated system mentioned that address could not be used. I appreciate if you can make a quick search, it will be one of the top results. Thanks

1 Like

Hi David,

the functionality is currently not offered by default (see open issue on github)
There might be a few options and solutions that fit you case, feel free to have a look:


I can’t believe this only has one heart! Thanks for asking this in such a clear and concise manner. I need to exclude already owned products by users for a retrieval model using TFRS and just followed the Recommending movies: retrieval tutorial. I got to the very cell you pasted above and was hoping for more pointed advice. I lucked on this page. Heading to the Github pages listed below now. Thanks again

1 Like