Using Transformers to Cut Waste and Put Smiles on Our Customers Faces!

Maarten Sukel25 Jul 2023

Problem

An online grocer must order fresh products before customers order them. Ordering too much creates waste, and ordering too little leaves customers without items such as fruit. Forecasts built on past sales, seasonality, events and broad product categories miss how individual products behave. They also fail for new products with no sales history.

Example from the article: a product with "BBQ" in its description sells more on holidays and warm days, but a history-only model cannot know that.

Solution in brief

Picnic adds product content to a Temporal Fusion Transformer (TFT). A fine-tuned DistilBERT turns name, ingredients and description into a 10-dimensional vector, and an image model (ResNet152 or BLIP) does the same for the product photo. Both vectors enter the TFT as static inputs next to the usual demand, weather and calendar features. On a Christmas-period test set this lowers the mean absolute error (MAE) for almost all categories, by amounts shown only on a chart.

Questions this case answers
  • How to add item content features (text and images) to a time-series demand model when sales history alone cannot describe new or sparse items
  • How to compress pretrained text and image embeddings into a few dimensions so a large-scale sequence forecaster stays trainable
  • How to make a demand forecasting model understand what a product is, so it works better for new or sparse items?
  • How to turn product names, descriptions, ingredients and images into compact features for a time-series forecaster?

Tools and methods

  • Temporal Fusion Transformer (TFT) — baseline forecaster; with embeddings added it becomes the Multimodal TFT (MTFT)
  • DistilBERT — multilingual text encoder fine-tuned to predict average demand; yields a 10-dimensional text embedding
  • ResNet152 — ImageNet-pretrained image encoder fine-tuned to predict average demand; yields a 10-dimensional image embedding
  • BLIP — Salesforce model for text, image or combined embeddings; better than the fine-tuned ResNet on images, with little fine-tuning
Continue reading — it's free

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