Fine-tuning Llama3 to measure semantic relevance in search

Quentin Hsu, Wayne Zhang14 May 2024

Problem

Faire, a wholesale marketplace, needs to know how relevant its search results are. Clicks, carts and orders are sparse. A missing click says little, because purchases also depend on desirability and personalization. A vendor labeled a sample of query-product pairs once a month, which was costly and arrived a month late. A fine-tuned external GPT model made labels daily, but the API cost capped volume, and new personalized retrieval sources needed far more labels.

Example from the article: for the query "fairy lights for tent", a "Live Moss Terrarium Supply Kit" is labeled Irrelevant, even though its description contains the words "light" and "fairy".

Solution in brief

Define relevance with the four-tier ESCI scale, write labeling guidelines until humans agree, then fine-tune a small open LLM (Llama3-8b with LoRA) to reproduce the human labels as a text-completion task. The model runs self-hosted in batches and scores tens of millions of query-product pairs per day.

Questions this case answers
  • How to measure the quality of a ranked result list at scale when behavioral signals are sparse and manual labels arrive with a long delay
  • How to replace an expensive externally hosted fine-tuned LLM classifier with a self-hosted open model without losing agreement with human labels
  • How to measure the semantic relevance of search results daily when monthly human labeling is too slow and expensive?
  • How to define search relevance so that labelers and a model can agree on it?

Tools and methods

  • ESCI relevance scale — Exact, Substitute, Complement, Irrelevant labels for a query-product pair
  • Llama (Llama3-8b, Llama2-7b, Llama2-13b) — base models for the classifier
  • LoRA fine-tuning — trains about 4% of the base model's parameters on human labels
  • DeepSpeed — distributed training and faster batch inference
  • 8-bit quantization — fits the model on one A100 for inference
  • Krippendorff's alpha — agreement between model and human labels
Continue reading — it's free

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