Factorized_top_k using tensorflow recommenders

I followed the tensorflow recommenders movie ranking tutorial and built the model. Now I would like to get top_k recommendations using the model. This is what I tried:

layer = tfrs.layers.factorized_top_k.Streaming(model.ranking_model)
layer.index(movies.map(model.ranking_model.movie_embeddings), movies)
tracks = layer.query_with_exclusions(
    queries=np.array([["42", "52"]]),
    exclusions= np.array([[]])

But it throws the error “iterating over tf.Tensor is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.”

How to invoke the query_with_exclusions() function correctly?

1 Like

Also interested in the answer to this, and how one could use this function to remove all previously interacted with items for each user.