Large Language Models for Search Relevance via Knowledge Distillation

pinterest · Tech · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Search relevance ranking for a visual discovery platform

Pinterest needed higher-quality query-to-Pin relevance predictions for search, but direct cross-encoder LLM serving was too expensive for real-time Pinterest Search. The system also had to represent multimodal Pins as text, use limited human-labeled relevance data efficiently, and generalize beyond US-labeled examples.

Constraints:

Architecture

Pinterest fine-tuned cross-encoder language models as relevance teachers over query and Pin text, then distilled those teachers into a lightweight online student relevance model. Pin text representations combine titles, descriptions, BLIP-generated synthetic image captions, high-engagement query tokens, board titles, and linked-page metadata. The teacher labels a daily logged search engagement and impression dataset with billions of rows, and the student trains on those teacher labels using query, Pin, and query-Pin interaction features. Online, the student produces relevance scores that are combined with engagement predictions for final search ranking.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  human["Human relevance labels"] --> teacher["Cross-encoder relevance teacher"]
  pintext["Pin text representations"] --> teacher
  teacher --> daily["Daily search log labels"]
  daily --> student["Student relevance model"]
  pintext --> student
  qfeat["Query-level features"] --> student
  pfeat["Pin-level features"] --> student
  pairfeat["Query-Pin interaction features"] --> student
  student --> ranking["Final ranking"]
  teacher --> eval["Offline and online evaluation"]
  student --> eval
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Human relevance labels Annotated query-Pin examples used to fine-tune and evaluate teacher relevance models. Cross-encoder relevance teacher
Pin text representations Textual representation of Pins built from user metadata, captions, board titles, linked-page metadata, and engaged queries. Cross-encoder relevance teacher, Student relevance model
Cross-encoder relevance teacher Fine-tuned LLM-style relevance classifier that jointly reads a search query and Pin text to predict five-scale relevance. Human relevance labels, Pin text representations, Daily search log labels
Daily search log labels Teacher-generated five-scale labels over large daily search engagement and impression data. Cross-encoder relevance teacher, Student relevance model
Student relevance model Lightweight feed-forward online model trained by distillation to predict five-scale relevance scores from efficient search features. Pin text representations, Daily search log labels, Query-level features, Pin-level features, Query-Pin interaction features, Final ranking
Query-level features Query interest, shopping interest, and SearchSAGE query embeddings used by the student model. Student relevance model
Pin-level features PinSAGE, visual, and SearchSAGE Pin embeddings used by the student model. Student relevance model
Query-Pin interaction features BM25, text-match scores, and historical engagement features describing the query-Pin pair. Student relevance model
Final ranking Search ranking stage that blends student relevance scores with engagement predictions. Student relevance model
Offline and online evaluation Accuracy, AUROC, human relevance evaluation, cross-language precision, and A/B experiment measurement. Cross-encoder relevance teacher, Student relevance model

Data flow

Pinterest starts with human-annotated relevance data to fine-tune cross-encoder teacher models that read the query and enriched Pin text together. The teacher then labels large daily search logs with five-scale relevance labels. Those generated labels train a smaller student model that embeds query-level features, Pin-level embeddings, and query-Pin interaction features. In production, the student predicts relevance scores for ranking, and those scores are used with engagement predictions to form the final search results.

3 supporting quotes
“We use a cross-encoder language model to predict a Pin’s relevance to a query, along with Pin text, as shown in Figure 1.”article, stated
“To train our student relevance model, we employ the LLM-based teacher model to generate 5-scale relevance labels on a daily logged large search engagement and impression dataset with billions of rows.”article, stated
“The relevance scores generated by the student model are then utilized alongside engagement predictions to determine the final ranking of search results.”article, stated

Why this architecture

Pinterest separated model quality from serving cost: a cross-encoder teacher can capture query-Pin interactions and create high-quality labels offline, while a smaller student can be served online with efficient query, Pin, and interaction features. The enriched Pin text representation lets language models reason over visual and user-curated context, and teacher-generated labels expand training coverage beyond human annotation.

3 supporting quotes
“Our cross-encoder LLM-based classifier is hard to scale for Pinterest Search due to real-time latency and cost considerations.”article, stated
“Therefore, we use knowledge distillation to distill the LLM-based teacher model into a lightweight student relevance model.”article, stated
“This blend of knowledge distillation and semi-supervised learning not only makes effective use of vast amounts of initially unlabeled data”article, stated

Models used: Llama-3-8B · multilingual BERT-base · T5-base · mDeBERTa-V3-base · XLM-RoBERTa-large · SearchSAGE · PinSAGE · BLIP · feed-forward student relevance model

Scale

Alternatives considered (roads not taken)

Serve the cross-encoder LLM relevance classifier directly in Pinterest Search

Rejected because: The article says direct cross-encoder serving is hard to scale because of real-time latency and cost.

“Our cross-encoder LLM-based classifier is hard to scale for Pinterest Search due to real-time latency and cost considerations.”article, stated

Train only on human-annotated relevance data

Rejected because: Teacher-generated labels let Pinterest use initially unlabeled data and expand coverage across languages and new concepts.

“not only makes effective use of vast amounts of initially unlabeled data, but also expands the data to a wide range of languages from around the world and new concepts”article, stated

Use only internal SearchSAGE embeddings as the language baseline

Rejected because: Language models provided additional five-scale accuracy improvements over the SearchSAGE-only baseline.

“Specifically, the Llama-3–8B outperforms the multilingual BERT-base model by 12.5% and the baseline model by 19.7% in terms of 5-scale accuracy.”article, stated

Represent Pins only with titles and descriptions

Rejected because: Ablation results showed each added text feature improved relevance prediction.

“The results, summarized in Table 4, demonstrate that the model’s performance consistently improves with the sequential addition of these text features.”article, stated

Patterns

model-distillation (model-serving)

Pinterest uses the LLM cross-encoder as an offline teacher and trains a lightweight online student relevance model from the teacher's five-scale labels.

“we use knowledge distillation to distill the LLM-based teacher model into a lightweight student relevance model.”article, stated

batch-offline-processing (data-pipeline)

The expensive LLM teacher runs over daily logged search engagement and impression data offline, rather than in the real-time ranking path.

“generate 5-scale relevance labels on a daily logged large search engagement and impression dataset with billions of rows.”article, stated

fine-tuning-adaptation (model-training)

Pinterest fine-tunes multiple pretrained language models on internal search relevance training data, including qLoRA-based fine-tuning for larger Llama models.

“These models are initialized from Hugging Face checkpoints and fine-tuned using our in-house search relevance training data.”article, stated

synthetic-data-generation (data-generation)

The system uses a teacher model to generate relevance labels at large scale and uses BLIP to generate synthetic image captions for visual Pins.

“Synthetic image captions: synthetic image descriptions generated by [Bootstrapping Language-Image Pre-training (BLIP)]”article, stated
“This labeled dataset is subsequently used to train the much smaller student model.”article, stated

eval-driven-development (evaluation)

Pinterest compares teacher models, text-feature ablations, label-scale increases, human relevance judgements, and online A/B experiments before claiming production impact.

“We now present offline experiments to demonstrate the effectiveness of each modeling decision.”article, stated
“Besides offline experiments, we also conducted an online A/B experiment to assess the effectiveness of our new relevance model.”article, stated

Tradeoffs

How to use LLM-quality relevance predictions in production search

Chose Offline LLM teacher plus online lightweight student over Directly serving the cross-encoder LLM classifier.

Rationale: The teacher captures richer query-Pin relevance, but the student avoids real-time LLM latency and cost.

“Our cross-encoder LLM-based classifier is hard to scale for Pinterest Search due to real-time latency and cost considerations.”article, stated
“These features are embedded and passed through a feed-forward network to predict 5-scale relevance scores”article, stated

How to expand relevance training data

Chose Teacher-generated labels over daily search logs over Relying only on limited human-annotated labels.

Rationale: Teacher labeling scales training examples to unlabeled logs and covers languages, countries, seasonality, and new concepts.

“This blend of knowledge distillation and semi-supervised learning not only makes effective use of vast amounts of initially unlabeled data”article, stated
“we are able to successfully generalize from human-labeled data focused on US queries to unseen languages and countries.”article, stated

How to represent multimedia Pins to language models

Chose A broad set of text features including generated captions and user-curated signals over Pin titles and descriptions alone.

Rationale: The ablation results show relevance performance improving as each additional text feature is added.

“The results, summarized in Table 4, demonstrate that the model’s performance consistently improves with the sequential addition of these text features.”article, stated

How to validate production relevance changes

Chose Offline metrics, human feed evaluation, cross-language judgements, and online A/B experiments over A single offline accuracy metric.

Rationale: Pinterest evaluates modeling decisions offline, measures human-perceived relevance with nDCG@20, checks country/language generalization, and confirms business impact through search fulfillment.

“In all offline experiments, we report the accuracy of 5-scale relevance predictions and the AUROC metrics for binarized labels with thresholds at 3, 4, and 5”article, stated
“The improvements in relevance also result in increased fulfillment in non-US countries, despite not having annotated data available for those countries during model training”article, stated

Gotchas (what bit them)

The most accurate cross-encoder architecture was not directly servable in the search path.

Root cause: A cross-encoder jointly evaluates every query-Pin pair, creating real-time latency and cost pressure.

Resolution: Distill the LLM teacher into a lightweight student relevance model with efficient online features.

“Our cross-encoder LLM-based classifier is hard to scale for Pinterest Search due to real-time latency and cost considerations.”article, stated
“Therefore, we use knowledge distillation to distill the LLM-based teacher model into a lightweight student relevance model.”article, stated

Human-labeled data did not cover the full language, country, seasonal, and concept space of Pinterest Search.

Root cause: Human relevance annotations were limited, while search contains global languages and newly emerging concepts.

Resolution: Use multilingual LLM teacher labels over daily logged data to expand training coverage.

“expands the data to a wide range of languages from around the world and new concepts not encountered in our human-labeled data owing to the seasonality in Pinterest Search.”article, stated

Visual Pins need reliable text representations before language models can judge relevance.

Root cause: Pins are multimedia objects, not plain text documents.

Resolution: Build a feature set from Pin metadata, generated captions, board titles, engaged queries, and linked-page metadata.

“Pins on Pinterest are rich multimedia entities that feature images, videos, and other contents, often linked to external webpages or blogs.”article, stated
“we use the following varied set of text features derived from metadata, the image itself, as well as user-curated data.”article, stated

Large model fine-tuning introduced practical memory and efficiency constraints.

Root cause: Fine-tuning larger models such as Llama requires more memory and compute than smaller encoders.

Resolution: Use quantized model weights, qLoRA, gradient checkpointing, and mixed precision to make training feasible.

“For larger language models such as Llama, we first load quantized model weights and then apply qLoRA for fine-tuning.”article, stated
“Additionally, we incorporate gradient checkpointing and mixed precision techniques to further improve training efficiency and memory usage.”article, stated

Evaluation

Pinterest evaluated the teacher models offline with five-scale accuracy and AUROC thresholds, ran feature ablations, tested the effect of increasing teacher-generated label volume, used human relevance judgements for search-feed nDCG@20 and cross-language precision@8, and ran online A/B experiments using search fulfillment rate.

Metrics: five-scale relevance prediction accuracy · AUROC at relevance thresholds 3, 4, and 5 · feature-ablation accuracy · training-label scale comparisons · human relevance nDCG@20 · cross-country precision@8 · search fulfillment rate

4 supporting quotes
“In all offline experiments, we report the accuracy of 5-scale relevance predictions and the AUROC metrics for binarized labels with thresholds at 3, 4, and 5”article, stated
“We conduct an analysis to assess the impact of each text feature on relevance prediction”article, stated
“By using knowledge distillation and semi-supervised learning, we can effectively scale the training data beyond the limited human-annotated data.”article, stated
“We set up evaluations with human annotators to assess the relevance of the search feeds with and without the new relevance model serving traffic.”article, stated

Outcomes

The system operates over daily logged search engagement and impression data with billions of rows, trains labels at scale through teacher-generated supervision, and serves lightweight relevance predictions for Pinterest Search.

4 supporting quotes
“Specifically, the Llama-3–8B outperforms the multilingual BERT-base model by 12.5% and the baseline model by 19.7% in terms of 5-scale accuracy.”article, stated
“Our proposed relevance modeling pipeline leads to a +2.18% improvement in search feed relevance, as measured by nDCG@20.”article, stated
“online A/B experiment, which showed an improvement of >1% in search feed relevance and >1.5% in search fulfillment rates.”article, stated
“we are able to successfully generalize from human-labeled data focused on US queries to unseen languages and countries.”article, stated