models icon indicating copy to clipboard operation
models copied to clipboard

[BUG] to_top_k_recommender model does not have batch_predict() method

Open rnyak opened this issue 3 years ago • 1 comments

Bug description

I'd like to apply batch_predict() to top_k_recommender model but it gives the following error:

topk_rec_model.batch_predict()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [17], in <cell line: 1>()
----> 1 topk_rec_model.batch_predict()

AttributeError: 'ModelBlock' object has no attribute 'batch_predict'

Please train Two-tower model in 05-Retrieval-Model.ipynb example and then add the following script after model training:

def get_items_topk_recommender_model(train_dataset, schema, model, k):
    item_features = schema.select_by_tag(Tags.ITEM).column_names
    item_dataset = train_dataset.to_ddf()[item_features].drop_duplicates(subset=['item_id'], keep='last').compute()
    item_dataset = Dataset(item_dataset)
    recommender = model.to_top_k_recommender(item_dataset, k=k)
    return recommender

topk_rec_model = get_items_topk_recommender_model(
    train, schema, model, k=20
)
topk_rec_model.batch_predict()

Environment details

  • Merlin version:
  • Platform:
  • Python version:
  • PyTorch version (GPU?):
  • Tensorflow version (GPU?): TF 2.8.0

using merlin-tensorflow-training:22.05 image with the latest main branches pulled.

rnyak avatar Jun 07 '22 17:06 rnyak

For the KDD tutorial, we would like to use the retrieval model (e.g. Two-Tower) to generate a top-k candidates dataset and use it to train a ranking model. For that, we were thinking to convert the Two-Tower model to a Top-k recommender and use the batch_predict method to directly get the candidate datasets from the input interaction data.

So after some local tests, we had two questions about how to use batch_predict functionality with the top-k recommender:

  • Can we apply the batch_predict to any ModelBlock? If not, can we convert the top-k recommender to a Model object?
  • We also noticed that the top-k recommender still require item features as inputs (even if under the hood the item-tower is not applied and is replaced by the brute force top-k index ). Is it possible to update the input module of the top-k recommender to only keep the input branch related to user features ?

sararb avatar Jun 07 '22 19:06 sararb