Gousto R-series Vol 3: Visualising Transformer Self-Attention to Explain Customer Recommendations

Steven George9 Jan 2023

Problem

A recipe-box retailer needs to recommend recipes to every customer, including new ones with little history. Learning one embedding per customer does not work for newcomers, and a deep model on top of it gives no answer to the question "why was this shown to this person?". Without that answer, product teams cannot trust the output or find out why a recommendation failed. Menus change weekly, so a favourite recipe can vanish for months.

Example from the article: a customer's top recommendation was a pasta dish ordered once before and absent from the menu in between. The team wanted to know whether the model replayed the old order or used more of the history.

Solution in brief

Gousto represents each customer as the sequence of recipes they ordered and scores a target recipe with an encoder-only Transformer, framed as binary classification on implicit feedback (orders). The self-attention weights over the 51 input positions are drawn as a heatmap per recommendation, which shows which past orders drove the score. The same heatmaps are used to debug false positives.

Questions this case answers
  • How to produce per-customer recommendations from a purchase history alone, without learning a separate embedding for each customer, so that new customers can be served
  • How to explain an individual neural recommendation to non-ML colleagues and find out which past behavior drove it
  • How to recommend items to customers when there are no learned per-user embeddings and each customer is only a sequence of past orders?
  • How to explain why a recommender picked a given item for a given customer?

Tools and methods

  • Behaviour Sequence Transformer (Alibaba), adapted — encoder-only Transformer over the order history plus the target recipe, with an MLP on top.
  • Multi-head self-attention — 8 heads, each able to link recipes by a different property.
  • Attention heatmap (viridis scale) — per-customer explanation of one recommendation, averaged over heads.
Continue reading — it's free

Google or a one-time email code. No password.