AI Engineer World's Fair 2025
What We Learned from Using LLMs in Pinterest
Read the talk
How Pinterest Distills LLM Relevance into Production Search
Pinterest combines joint query–Pin scoring, image captions and behavioral annotations with a distilled student that serves search and supplies reusable semantic embeddings.
From a talk by Mukuntha Narayanan and Han Wang
Before you start: Familiarity with embeddings, classification and the distinction between model training and inference will help with the architecture and serving details.
Which Pins answer a search query?
When someone types a query into Pinterest, which images will satisfy their information need? Search sits alongside home feed and related Pins as one of Pinterest’s three discovery surfaces. Han Wang and Mukuntha Narayanan, machine learning engineers on the Search Relevance team, focus on improving that query-driven experience.
Han reports more than six billion searches per month across billions of Pins, supporting over 45 languages and reaching users in more than 100 countries. Those searches span recipes, home decor, travel, fashion and other domains, so relevance modeling must work across both subjects and languages.
The search pipeline proceeds through query understanding → retrieval → reranking → blending, then produces a search feed. Semantic relevance is modeled during reranking: given a query and a candidate Pin, a classifier predicts one of five relevance levels, ranging from most relevant to most irrelevant. This is the specific task the LLM must improve.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Score the query and Pin together
The relevance model concatenates the query and the Pin’s text, then passes them through an LLM. This cross-encoder lets the model capture interactions between the query and candidate content inside the encoder. An MLP consumes the resulting embedding and produces a five-dimensional vector corresponding to the relevance levels. Pinterest fine-tunes open-source language models on internal data to adapt this classifier to its content.
The baseline uses SearchSage, Pinterest’s in-house query and content embeddings. Across the tested models, Han reports stronger relevance prediction with more advanced and larger LLMs. Han reports that Llama 3 8B improves relevance prediction by approximately 12% over multilingual BERT base and 20% over SearchSage. The companion paper identifies the matching comparison as relative improvement in five-class accuracy, rather than percentage-point gains, with Pin text features and maximum input length held fixed across models.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Turn images and user actions into text
A text-based relevance model needs a useful textual representation of an image-centered Pin. Pinterest builds that representation from five sources:
| Text source | Information supplied |
|---|---|
| Pin title | The Pin’s title text |
| Pin description | Its accompanying description |
| VLM-generated caption | Content extracted from the image |
| Saved-to board titles | How users organize the Pin |
| High-engagement search queries | Queries that lead users to engage with it |
The last two sources turn user actions into content annotations. Saving a Pin to a named board gives it context beyond its own description; queries associated with strong engagement provide another view of what people find it useful for. Together, the five sources give the language model a more comprehensive representation.
The ablation starts with the VLM caption alone, which Han describes as a strong baseline. Adding the other text features sequentially improves relevance prediction, including gains from the board titles and engaged queries. The useful result is not simply that more text helps: image-derived descriptions and behavior-derived annotations each contribute information that the original Pin text may lack.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Use the teacher to expand supervision
An accurate cross-encoder still leaves a production problem: how can Pinterest afford to apply its knowledge at search scale? Mukuntha introduces knowledge distillation into a smaller student. The student predicts the same five relevance levels, but learns from the teacher’s five-dimensional soft scores rather than only a single winning class.
A soft target preserves how the teacher distributes probability across relevance levels. The following Python loss illustrates training a student against such a distribution; teacher_probs contains one five-level distribution per query–Pin pair, while student_logits contains the student’s unnormalized predictions:
python
import torch
import torch.nn.functional as F
def soft_relevance_loss(
student_logits: torch.Tensor,
teacher_probs: torch.Tensor,
) -> torch.Tensor:
if student_logits.shape != teacher_probs.shape:
raise ValueError("Student and teacher shapes must match")
if student_logits.ndim != 2 or student_logits.shape[1] != 5:
raise ValueError("Expected tensors with shape [batch, 5]")
log_probs = F.log_softmax(student_logits, dim=-1)
targets = teacher_probs.detach()
return -(targets * log_probs).sum(dim=-1).mean()
This expresses the soft-supervision mechanism; the talk does not specify its exact training loss.
The semi-supervised data pipeline expands the reach of a relatively small human-labeled dataset:
- Train the teacher. Annotators trained for specific segments supply human labels. Pinterest fine-tunes a multilingual teacher using features that can apply across domains.
- Sample daily search logs. Sampling captures trending queries and fresh Pins, along with traffic from many languages and countries. Most human labels originate in the US, while only a small subset of this global traffic does.
- Label the sampled pairs. The teacher supplies relevance scores across the domains and markets where it produces useful labels.
- Train and serve the student. The expanded dataset transfers the teacher’s relevance judgments into the model that runs online.
Mukuntha reports approximately 100× expansion of the training data through teacher labeling. Daily sampling matters because the student’s supervision can cover current search behavior and content, not just the narrower population represented by the original human labels.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Separate encoding from online scoring
The student still contains language models, but it uses a bi-encoder: the Pin and query are encoded separately, without cross interactions inside their encoders. It also consumes SearchSage features, GraphSAGE embeddings, OmniSage and other embedding features. Query–Pin text-match statistics such as BM25 add signals that have historically worked well for Pinterest relevance prediction. Separate language encoding therefore does not mean that the final score is merely an embedding similarity.
The serving advantage follows from separating the two inputs:
| Component | Computation strategy |
|---|---|
| Pin embedding | Infer offline across billions of Pins |
| Pin refresh | Recompute when input features meaningfully change |
| Query embedding | Infer online from a short query |
| Repeated query | Reuse its cached embedding |
The Pin encoder uses predominantly the same text features as the teacher, helping transfer its knowledge. Once computed, a Pin’s representation can be reused across searches; its encoding is not part of the work triggered by an individual search request.
Mukuntha reports query-embedding latency of a few milliseconds for short search queries. Repeated queries provide another saving: Mukuntha reports an approximately 85% query-embedding cache hit rate. These figures describe the query-encoding path and its cache, not end-to-end search latency.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Measure relevance and fulfillment across markets
The online evaluation examines relevance through nDCG and precision at eight in selected US, Germany and France segments. These are relevance measurements rather than engagement measures; the companion paper uses graded labels for precision at eight and an all-highest-relevance ideal for nDCG. Mukuntha reports international relevance gains despite starting this experiment with limited, predominantly US human-labeled data.
Pinterest also measures search fulfillment, which tracks fulfilling engagement actions on search. Mukuntha reports that search fulfillment also improves outside the US. The multilingual teacher makes the limited initial supervision useful across a broader set of countries and domains, while the student makes those learned judgments practical to serve.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Reuse the representations beyond search
The production student produces more than relevance scores. Its Pin and query embeddings are already available as semantic representations, so other systems can reuse them without building a separate representation model for each application. Pinterest also uses the model to represent boards from their titles and related text. Mukuntha attributes the representations’ richness to relevance tuning, distillation from the teacher and the language models within the student.
Mukuntha reports improvements from adding these representations to related Pins, home feed and other surfaces. The applications slide extends that reuse across retrieval, ranking and content moderation. Each displayed result belongs to its associated application and metric; they are separate downstream uses of the embeddings, rather than one aggregate search result.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Choose the model and locate its serving role
Asked how Pinterest chose which open-source LLM to fine-tune, Han describes an empirical selection process: experiment with multiple language models, compare their measured performance and select the strongest performer. The answer supplies no additional selection rule beyond those experiments.
A second question separates two roles that are easy to conflate: the LLM that produces training labels and the model that scores a live search. Mukuntha clarifies that the teacher distills its judgments into a five-level relevance student. Candidate generators and early ranking run first; the student scores relevance later, during reranking immediately before blending the results into a feed. The teacher’s influence reaches serving through the trained student.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Broader coverage with captions and one multilingual model
The next question asks what drove adoption: did LLMs enable new search features, or improve capabilities that the existing system already had? Mukuntha emphasizes the ability to expand relevance measurement and labeling beyond a limited set of markets. VLM captions improve the content representation, while multilingual models supply synthetic relevance data for additional markets. The benefit described is broader relevance coverage, rather than a new user-facing search interaction.
Asked whether the embedding model inherently combines text and images, Mukuntha says direct multimodality is under exploration. In the approach described here, visual captions capture image content effectively for many applications, supported by Pinterest’s in-house captioning models. The distinction matters: images contribute through their textual descriptions, without requiring the relevance encoder itself to ingest pixels.
The final question asks whether international improvements require separate models for individual languages or a common model. Han confirms that all languages use the same model, attributing cross-language transfer to the multilingual language model. That answer establishes shared modeling across languages, without claiming that every feature is identical in every market.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Pinterest's original account of SearchSage query embeddings for search retrieval and ranking.
Pinterest's framework combining graph, content and user-sequence signals into reusable representations.
Original research on learning representations that generalize to previously unseen graph nodes.
Further reading
Original research detailing relevance classification, distillation and offline and online evaluations.
The speakers' companion explanation of text features, teacher training and production relevance scoring.
- OmniSearchSagePaper
Joint query, Pin and product embeddings trained through multiple tasks for Pinterest Search.
Official research implementation with source code, tests and dependency requirements.
Read the complete timestamped transcript
- 0:00
[on-hold electronic music] Yeah, hi, everyone.
- 0:15
Um, thanks for joining the talk today. Um, we are super excited to be here and to share some of the learnings we, um, we have from integrating the LLM into Pinterest Search.
- 0:27
My name's Han, and today I'll be presenting with Mukuntha, and we are both machine learning engineers from Search Relevance team at Pinterest.
- 0:36
So start with a brief introduction to Pinterest. Um, Pinterest is a visual discovery platform where Pinners can come to find inspiration to create a life they love. And there are three main discovery surfaces on Pinterest, the home feed, the related pins, and search.
- 0:54
In today's talk, we'll be focusing on search and, um, where the user can type in their queries and, um, find useful, inspiring content based on their information need. And we'll share, um, how we leverage LLM to improve the search relevance.
- 1:13
Um, here are some key statistics for Pinterest Search. Every month, we handle over six billion searches with billions of pins to search from, covering topics from recipe, home decor, travel, fashion, and beyond.
- 1:29
And at Pinterest, search is remarkably global and multilingual. We support over forty-five languages and are reaching Pinners in more than one hundred countries. These numbers highlight the importance of search at Pinterest and why we are investing, um, in search relevance to improving the search experience.
- 1:52
So, um, this is an overview of how Pinterest Search work at the back end. So it's similar to, um, many recommendation system at industry. It has query understanding, retrieval, reranking, and the blending stage, and finally produce, um, relevant and engagement search feeds.
- 2:12
And, um, in today's go- talk, we'll be focusing on the semantic relevance modeling that happen at the reranking stage and share about how we use LLM to improve, um, the search relevance on the search.
- 2:29
Okay, so, um, here's our search relevance model, which, um, is essentially a classification model. Given a search query and a pin, the model will predict how much the pin is relevant to the search query.
- 2:44
And to measure this, we use a five-point scale, um, ranging from the most relevant to most irrelevant.
- 2:53
All right. Um, now we are gonna share some key learnings we have from using the LLM to improve search, Pinterest search relevance. And here are four main takeaways that we would like to, um, go into more details.
- 3:11
Lesson one, LLMs are good at relevance prediction.
- 3:17
Um, so before I present, um, the result, let me first give a quick overview of the model architecture that we are using. Um, we concatenate the query and the pin text together and pass them into a LLM to get a, um, embedding.
- 3:35
So this is called, um, Cross-encoder structure, we- we-- where we can better capture the interaction between the query and the pin. And then we feed the, um, embedding from LLM into NLP layer to produce a five-dimensional vector which correspond to the, um, five relevance levels.
- 3:55
And during training, we fine-tune some open source LLM using Pinterest internal data and to better adapt the model to our Pinterest content.
- 4:07
And here, um, I'd like to share some results, um, to demonstrate that the usefulness of LLM. And as a baseline, we use SearchSage, which is a Pinterest in-house content and the query embedding.
- 4:24
And, um, so if you look at the table, you can see that the LLM has substantially, um, improved the performance of the relevance prediction. And as we use more advanced LLMs and increase the model size, the performance keeps improving.
- 4:42
And for example, um, the eight billion Llama three model gives, um, twelve percent of improvement over the multilingual BERT base model and twenty percent of improvement over the SearchSage embedding model.
- 4:55
So, um, the lesson here is that, um, LLMs, they are quite good at relevance prediction.
- 5:04
Um, lesson two, the vision language model generated captions and the user actions can be quite useful for content annotations.
- 5:16
So to use LLM for search, uh, for relevance prediction, we need to build a text representation of each pin. And here I listed several features that we used in our model.
- 5:30
Besides the, um, the title of description of the pin, we also include, um, the VLM-generated synthetic image caption to directly extract information from the image itself. And besides that, we add some, um, user engagement-based feature like the board titles, um, for the user-curated board that the pin has been saved to,
- 5:55
or, um, the queries that led to the highest engagement with this pin on search surface So these two user action-based features, um, serves as additional annotation for the content.
- 6:09
And, um, here the five source of feature together helps to build a more, um, robust and comprehensive text representation for each pin.
- 6:22
Uh, we... To understand the, um, importance of t-each vortex feature, we also did some ablation studies. We used the, um, VLM generated image caption as a baseline. And, um, as you can see, itself already pro-um, provide a very solid baseline.
- 6:42
And as we sequentially add more vortex feature, we keep seeing performance improvement. And this indicate that enriching the vortex feature is quite useful for relevance prediction. And notably, um, the last two rows of the table shows the performance gain we have by adding these user action-based features.
- 7:04
So these features turned out to be quite useful content annotation that help model better understand the content.
- 7:14
All right. Um, next, I will hand over to Mukuntha to talk about how we used knowledge distillation to productionize this model.
- 7:22
Right. Yeah. Uh, so now we have a good relevance model, which is good at predicting search relevance. Uh, but how do we actually scale this up without bankrupting Pinterest?
- 7:33
Uh, usually the answer is knowledge distillation into smaller models. Um, and this is the production served relevance student model that we distilled from the teacher model using semi-supervised learning.
- 7:45
Uh, the student model is trained to predict five-scale relevance scores too. Uh, it trains using the five, uh, scale soft scores pro-produced by the teacher model. Um, and we produce data for this using a semi-supervised learning setup that, uh, I'll show in the next slide.
- 8:03
So the LLM teacher model is trained on a small set of human labeled data that we get from human annotators who are trained in very specific segments. Uh, we fine-tune, and this is a multilingual language model which uses pretty generic features which scale across a lot of different domains, et cetera.
- 8:22
Um, and the way we get training data for the student, uh, is through, uh, sampling from daily search logs, which is, um, all the searches, uh, people make on Pinterest.
- 8:34
Uh, and since we sample daily, uh, this includes any trending queries, all the latest, freshest pins on Pinterest. And this is also remarkably go-global, like we mentioned, and only a small subset of this comes from the US, where most of our human labeled data comes from.
- 8:52
Um, we sample from this, and we label using the teacher, and we scale it up pretty much 100X, uh, across different domains, languages, countries where, uh, the LLM teacher model produces pretty good labels.
- 9:05
We train the student model, and this is the model that actually gets served online. Um,
- 9:12
and, uh, zooming into the student model, uh, also-- this also has language models in it. Uh, but unlike the teacher model, it's not a cross-encoder. It, uh, is a bi-encoder, uh, which essentially means we don't have cross interactions between the pin and the query, uh, representations.
- 9:30
Um, the pin gets embedded separately, query gets embedded separately, and it also uses a lot of other features like, um, SearchSage that we previously mentioned for both embedding the query and the pin.
- 9:41
Uh, we have GraphSAGE embeddings, which Pinterest has published papers on, um, and OmniSage and a lot of other embedding features for query and pin. But we also use, uh, a lot of pin query text match statistics like BM25, which we've seen historically perform really well for predicting search relevance.
- 9:59
Um, and the reason this scales well is the bi-encoder. Uh, bi-encoder large language models can scale really well, uh, when we, uh, use offline inference and caching. Uh, the pin embedding here is entirely offline inferred on billions of pins.
- 10:17
Uh, it uses predominantly the same text features that we mentioned on the teacher, uh, which helps distill efficiently. Um, and, uh, we only, uh, re-infer, uh, these embeddings every time that these inputs meaningfully change, uh, meaning that, uh, every time that we, uh, need new embeddings, um, it's only going to run on a few set of new
- 10:40
pins. Um, and, uh, this is offline inferred, so none of this is happening online when a user issues a search query. Uh, and the query embedding is pretty much, uh, real-time inferred online.
- 10:52
Uh, and search queries are pretty short. Um, they don't occupy too many tokens, which means, uh, we can keep the latencies for the query embedding up to like a few milliseconds.
- 11:02
Um, and we also cache this, uh, because search queries get repeated a lot, and we get around an eighty-five percent cache hit rate. Um, and yeah, this scales really well, uh, to actually serve Pinterest traffic.
- 11:17
Um, the online results here, uh, the first four numbers are relevance, uh, measurements, nDCG, uh, precision at eight, uh, measured on the US, Germany, France, uh, specific segments that we zoomed into.
- 11:31
Uh, we can actually see that we get relevance gains international, uh, internationally even though we started with a very limited set of US data for this particular experiment. Um, and, uh, we also see that search fulfillment, which measures engagement on search, um, fulfilling actions, um, also goes up, um, also on non-US even though our, uh, starting data
- 11:56
was predominantly US. And, uh, yeah, uh, large language models are very good at, uh, expanding across many different domains, countries, uh, even though, uh, they have-- weren't explicitly trained for this.
- 12:10
Um, and, uh, this is a bonus. Uh, we also found that relevance-tuned large language models produce really good rich, uh, semantic representations, which are very good general purpose. Uh, this is the same production relevance student model that I shared on the previous slide.
- 12:27
Uh, and, uh, the Pin embedding and the query embedding, uh, are basically free representations that we get from these models, uh, which can be used across Pinterest for representing Pins and search queries.
- 12:41
Um, we, we also use this to represent boards using the titles, et cetera. Um, and we found that using these embeddings, especially since they've been distilled from a large language model teacher and also have large, uh, language models in them, uh, they are very good at semantic content representations.
- 13:01
Uh, and yeah, they perform pretty well across, uh, related Pins, home feed, and a lot of other surfaces where we've seen, uh, representations improve by adding these things. Um, so let me go over the key takeaways again.
- 13:18
Um, I think lesson one, we found that LLMs are really good at relevance prediction. Uh, lesson two, we found that visual language model captions are good, uh, ex- good ways to imbue them with, uh, image representations, and, uh, user actions are very good content annotations.
- 13:36
Um, three, uh, we found that knowledge distillation is a very good way to scale, uh, and efficiently serve models, uh, online. And, uh, lesson four, uh, relevance tuning produces pretty rich representations, uh, that embed semantic representations for content fairly well.
- 13:56
Thank you. Um, I wonder if there are any questions from the audience. Please come up to the mics.
- 14:03
How did you decide which open source LLMs to fine-tune?
- 14:09
Yeah, that's a... Yeah, that's a very good question. So we did a lot of experiment trying different language models. And, um, in the previous slide, we also share some, um, performance for different language model.
- 14:22
Yeah. So we did a lot of experiment and find the one that gives us the best performance. Yeah.
- 14:29
Uh, if you could just walk us through somebody typing a search prompt. The confusion that I have is you have, like, LLMs, uh, building some sort of matching. Is it just being used for the label to be distilled, or how did you shim that into the bi-encoder?
- 14:46
It wasn't really clear on the two-tower, uh, flying airline and how the LLM search kind of influenced that.
- 14:55
We use LLMs to distill into a student model which predicts search relevance specifically and produces five scale relevance scores. Um, and it's served at the end of the search pipeline.
- 15:06
It's, uh, the re-ranking stage. Um, like every recommendation system, we have a lot of, uh, CGs, which are candidate generators. We have early stage ranking, and this is one of the things that sits further down the pipeline, which actually predicts search relevance scores and, uh, is used
- 15:24
right before blending to actually produce a feed. So I think it's very similar to most recommender systems.
- 15:34
So, uh, I have a... Excuse me. Uh, I have a question on how you evolved into this architecture. Like, I'm sure Pinterest has pre-LLM era search as well. Like, what limitations did you see in those systems that this new architecture solved for?
- 15:56
So, um, if I'm understanding correctly your question is about what's the difference between the new system with the-
- 16:02
Yeah
- 16:02
... from the-
- 16:03
What, what was the, what was the driver to adapt, adapting LLMs, uh, for, for in, in your search pipeline? Did the type... Did it support new features, or is it...
- 16:13
Does it improve on the existing features where you had limitations?
- 16:19
I think they definitely improve, uh, especially with visual language model captions. I think we were es- very effectively able to expand beyond limited markets for actually measuring relevance data and getting relevance data.
- 16:34
And yeah, these multilingual models are very good at, uh, getting s- synthetic data for different markets for, uh, relevancy.
- 16:47
Hey. Um, g-great, great talk. Um, I was wondering why, uh, or if, if the embedding model is inherently multimodal, um, because you have text, which is, uh, the, the query, and then you're matching against, um, either text links or images.
- 17:03
And so how do you think about mo- multimodality?
- 17:07
It's definitely something we're exploring, but then, uh, on a lot of applications, I think we found, uh, visual captions are very good at ca- uh, capturing what the image has.
- 17:17
Um, and we have some very good captioning models in-house, which, uh, yeah, help us.
- 17:24
Great. Thanks.
- 17:27
What was the improvement-
- 17:28
Great talk. Uh, yeah, just a quick question. You mentioned that you saw improvements in other language as well. Did you start with the common baseline model for all languages, or did you have to sort of...
- 17:40
And just change the features for each language, or did you actually also start with separate l- models for individual languages?
- 17:49
Yeah, that's a-
- 17:49
Just curious how you actually saw the improvements manifest everywhere.
- 17:54
Yeah. Um, so we s- we used the, um, same model for all languages, and we... Because we u- we are using the multilingual mo- um, LM, so we believe it can have transfer to other languages. [outro music]