Using Large Language Models as Recommendation Systems

Mohamad Aboufoul10 Apr 2023

Problem

Classic next-purchase recommenders need feature engineering and other manual processes. A text-to-text language model promises to skip them: the purchase history goes in as text and the next item comes out as text. The practical questions are how to format the input, whether a small custom dataset is enough, and what breaks outside English.

Example from the article: the author fine-tuned T5-large on about 100 sports-equipment purchase sequences, then repeated the experiment in Arabic.

Solution in brief

Treat sequential recommendation as text generation. Fine-tune a pretrained T5 model on pairs of "items bought so far plus the full candidate list" and "next item". The candidate list in the prompt keeps the answer inside the inventory. The English run gave plausible picks, while Arabic models collapsed to one or two items.

Questions this case answers
  • How to predict the next item for a user from a short interaction history when hand-built features are unavailable and the output must come from a closed catalog
  • How to build a next-item recommender from a text-to-text language model without hand-made features?
  • How to make a seq2seq model pick the next purchase only from items that are in stock?
  • How to know whether a fine-tuned language model recommends from the history or just repeats one popular item?

Tools and methods

  • T5 (T5-large) — encoder-decoder language model fine-tuned to output the next item.
  • Hugging Face Transformers (Seq2SeqTrainer) — fine-tuning loop, about 10 epochs.
  • P5 (Geng et al.) — paper that frames recommendation tasks as text-to-text prompts; the model for this replication.
  • AraT5, mT5 — multilingual models tried for Arabic.
  • Google Translate API — translate-in, translate-out workaround, which failed.
Continue reading — it's free

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