tensorflow / tensorflow/recommenders
How to pass multiple inputs into the BruteForce index?
Open
@maciejkula is already working on this.
Since Nov 21, 2020.
question
- Dominant language
- Python
- Stars
- 2k
- Forks
- 300
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to use the index on my model which requires a dict as inputs (similar to [https://www.tensorflow.org/recommenders/examples/deep_recommenders#combined_model](this tutorial)). How do I input a query correctly when I call the index? I'm getting multiple errors.
This is my last attempt:
index = tfrs.layers.factorized_top_k.BruteForce(model.query_model)
# recommends products out of the entire products dataset.
index.index(train.batch(100).map(model.candidate_model),
train.batch(100).map(lambda x: model.candidate_model({'product_id': x['product_id']})))
test_query = {
"last_100_product_views": train_df["last_100_product_views"][0],
"last_100_purchases": train_df["last_100_purchases"][0],
"last_100_searches": train_df["last_100_searches"][0],
"user_gender": train_df["user_gender"][0],
"user_country": train_df["user_country"][0],
}
# Get recommendations.
_, titles = index(dict(train_df[['last_100_product_views',
'last_100_purchases',
'last_100_searches',
'user_gender',
'user_country',]].iloc[0]))
print(f"Recommendations for user 42: {titles[0, :3]}")```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.