Problem
A food-delivery team wants to show each user an ordered list of restaurants. Scoring restaurants one by one, or in pairs, ignores the list as a whole and can produce near-duplicates of what the user already ordered. The data is large: in some countries user and restaurant combinations exceed billions of rows, and each user has a different set of open, nearby restaurants.
Example from the article: a user liked restaurant A (sushi) and restaurant B (Mexican). A pairwise recommender suggests C (sushi) and D (Mexican). A listwise one may suggest E (Asian) and F (Latin American), a list that covers more of the user's tastes.
Solution in brief
Train a TensorFlow Recommenders ranking model with a listwise loss (ListMLE) on short lists of rated restaurants sampled per user. Build the lists in BigQuery rather than in Python. At prediction time, group users by the number of available restaurants, score each group in one pass, and write the scores back to BigQuery in file-sized chunks.
Questions this case answers
- How to train a ranker that optimizes the order of a whole list of items per user instead of scoring each item on its own
- How to batch-score a very large user-by-item candidate set when candidate counts differ per user and memory is limited
- How to train a listwise ranking model that orders restaurants for each user with TensorFlow Recommenders?
- How to build training lists of rated items per user directly in the data warehouse?
Tools and methods
- Listwise ranking (ListMLE loss) — trains on whole lists, so the model learns the order of items for a user
- TensorFlow Recommenders (TFRS) — the
tfrs.ModelandRankingtask that wrap the loss and metrics - TensorFlow Ranking — provides
ListMLELossandNDCGMetric - BigQuery — stores ratings, samples training lists and receives the final scores
- TensorFlow — Keras layers for the embeddings and the scoring network
Google or a one-time email code. No password.