AIFeed

How Pinterest Built LLM-Powered Search in 20 Languages With Minimal Training

Summary

Developer workshop: Low-latency AI with Rust (Sponsored) Build a high-performance Rust app where AI agents learn from shared, real-time memory Want to learn how to scale fast AI decision loops? Join us for this free interactive workshop. As you explore key principles of designing low-latency systems with Rust, you will learn how to: Build and compile a real-world Rust app that runs many concurrent decision loops Connect it to ScyllaDB (NoSQL data store) as a shared, persistent memory subsystem Negotiate data modeling and query tradeoffs for AI workloads, such as single-row partitions and counters as incremental updates Manage and monitor the database for consistently low latencies as concurrency grows All attendees will get a 3-chapter excerpt from the Latency book by Pekka Enberg (published by Manning). Register for Free When you search for something on Pinterest, you express an intention with just a few words. For example, a query like “small balcony garden ideas” tries to describe s…

Original text(via ByteByteGo)

Developer workshop: Low-latency AI with Rust (Sponsored)

Build a high-performance Rust app where AI agents learn from shared, real-time memory

Want to learn how to scale fast AI decision loops? Join us for this free interactive workshop.

As you explore key principles of designing low-latency systems with Rust, you will learn how to:

  • Build and compile a real-world Rust app that runs many concurrent decision loops
  • Connect it to ScyllaDB (NoSQL data store) as a shared, persistent memory subsystem
  • Negotiate data modeling and query tradeoffs for AI workloads, such as single-row partitions and counters as incremental updates
  • Manage and monitor the database for consistently low latencies as concurrency grows

All attendees will get a 3-chapter excerpt from the Latency book by Pekka Enberg (published by Manning).

Register for Free

When you search for something on Pinterest, you express an intention with just a few words. For example, a query like “small balcony garden ideas” tries to describe something that you want to find. Pinterest needs to find out all the useful Pins that might satisfy this search query and decide how to order them.

Here, a Pin is a piece of content on Pinterest that contains an image or video. It sometimes links to an external webpage. Search relevance tries to measure how well the content satisfies the intention behind the query.

Pinterest uses a powerful language model to help judge if a search result is relevant. But running that model again and again during live searches would be quite expensive. Therefore, they used that model to produce training data for a smaller model that can answer things quickly.

In this article, we’ll try to understand the design behind this approach. Here’s what we’ll cover:

  • How Pinterest defines relevance
  • How a language model gets enough information to judge a Pin
  • How Pinterest trained its model to make the right judgements
  • How it transfers those judgements into a live production search system
  • How the cost of training was reduced

Disclaimer: This post is based on publicly shared details from various sources. References at the end. Please comment if you notice any inaccuracies.

How Pinterest Defines Relevance

Search relevance starts with understanding the request. As we saw using the earlier example, it’s all about understanding the user’s intent.

For the “balcony” query, a Pin that shows a compact arrangement of plants on a balcony would be highly relevant. On the other hand, a photograph of an enormous landscaped garden might look attractive and popular. But it would be less useful with space constraints.

This is the reason why Pinterest wanted an explicit relevance objective alongside engagement predictions while predicting stuff. Engagement just gives an estimate of whether people are likely to interact with something. Relevance estimates whether it addresses what they searched for. These measurements can complement each other. But they answer different questions.

Relevance also comes in degrees. With some results, you are able to match the request closely. Others might provide partial help. Some have little connection to it. Pinterest handles these differences using different levels:

  • L5 stands for highly relevant. It directly matches the query or closely corresponds to it.
  • L4 stands for relevant, where you provide a close match or a useful substitute. But there might be minor differences.
  • L3 is for marginally relevant. It means that the result might relate to the query but satisfies only part of the intention.
  • L2 stands for irrelevant. It belongs to the broad category but doesn’t satisfy the query.
  • L1 is for highly irrelevant. It simply means that the result has no relationship to the search.

Human annotators use these guidelines to label examples consisting of a query and a Pin. These examples provide a baseline for what the model should learn. The resulting task is multiclass classification. When you provide a query and information about a Pin, you’ve to predict its relevance across different categories.

Build with Gemini in Google Antigravity. (Sponsored)

Google Antigravity is made for how you actually ship software now. Built with Google’s frontier Gemini models, it lets you direct autonomous agents to plan changes, write code, run terminal commands, and verify their work in a real browser. Review inspectable plans and diffs as you go, from weekend prototypes to production codebases. Get started at no charge with a weekly quota. Rate Limits and Terms apply.

Try Google Antigravity

How to Give Information to the Language Model About a Pin

Before a model can judge relevance, you need to provide it with a useful representation of the content.

This is quite challenging for Pinterest because a lot of the content over there is visual in nature. You can have an image that communicates information that is left out by the title. For example, let’s say you might have a pin called “my favorite room”. It might show a particular furniture style, colour scheme, and room layout without mentioning any of that stuff in the title.

Pinterest handles this by bringing in text from several sources. Each source gives you a different view of the Pin.

Pin titles and descriptions provide the information that is written by the user who created the Pin. Titles and descriptions from linked webpages add information about the content behind it. For example, if you have a recipe Pin, the linked page might make the dish and its ingredients much clearer than the short description that the user has written on Pinterest.

To get information from the image itself, Pinterest uses synthetic image captions. These descriptions are generated by an existing image-captioning model called BLIP. A caption might talk about a wooden dining table, hanging lights, and white walls. This gives the relevance model textual evidence about the visual content.

Pinterest also includes user-curated board titles. These boards are collections where users save Pins. If a user saves an image to boards about compact kitchens, those titles can provide additional context about how they might interpret and use the image.

Finally, Pinterest also includes high-engagement query tokens that are drawn from historical searches that have led to strong engagement with that Pin over the last few years. These help them understand further details about the kinds of searches for which people may have found the Pin useful.

All these sources complement one another. A caption talks about visible objects, a webpage describes the linked content behind the Pin, and board titles capture context written by users.

This way, the teacher model gets a richer textual understanding than a title alone could provide. The quality of how relevant something is depends partly on the quality of this description. A capable LLM still needs to find information about what the Pin contains.

How Pinterest Trained the Teacher Model

Once Pinterest has assembled the Pin’s text, it combines that text with the search query and passes them both through an LLM.

The architecture is known as a cross-encoder. Its main feature is that it processes the query and the candidate’s text together so that it is able to understand the relationship between the request and the content.

For example, let’s say you have a search for the term “egg-free birthday cake”. You might have a candidate that contains many matching words while talking about a cake that requires eggs. If we process the request together with the recipe information, we give an opportunity to the model to recognize that the ingredients matter.

This is different from turning a query and a Pin into compact representations separately and then comparing those representations. With joint processing, you allow for more detailed interaction between the two pieces of text. However, you need more computation for each pair.

In the architectural context, the LLM produces a representation of the combined input. This representation goes through an MLP (Multilayer Perceptron), which is a small network of computational layers. These layers convert the representation into scores for the five relevance levels.

Pinterest takes pretrained language models and adapts them using its human-annotated examples. This process is known as fine-tuning. The model starts with knowledge acquired during pretraining. It then learns how to apply that knowledge to Pinterest’s particular relevance guidelines.

Training uses cross-entropy loss. You can think of this as a way to measure how poorly the model’s predicted scores match the training labels. If you have a human judgment indicating that a Pin is highly relevant while the model gives that category very little probability, the training process adjusts the model to reduce the disagreement level.

Using a bunch of many examples, the model learns about Pinterest’s relevance task. It becomes the teacher because its predictions will eventually provide supervision for another model.

Why the Teacher Needs a Smaller Student

You can have a cross-encoder making useful judgments. But every Query-Pin pair also needs joint processing.

The same Pin can have very different relevance ratings for different searches. For example, you might have a photograph of a red sofa that is great for a search about “red living room furniture” and unhelpful for “blue bedroom furniture.” Therefore, the relevance depends on the combination of the query and the content.

At the scale of Pinterest Search, if you run an LLM over candidate pairs, you end up with a lot of computational cost and response-time pressure. Users want search results quickly, and relevance scoring is only one part of producing those results.

Pinterest handles this using the process of knowledge distillation. In this process, you have a capable teacher model generate predictions. A smaller student model learns to reproduce those judgments.

The teacher runs offline, outside the path that needs to respond immediately to a user’s search. Its predictions become training material. In contrast, the student runs online, where it must calculate relevance scores quickly enough for live search.

With distillation, you transfer useful behavior using training examples. The student model might have a different architecture and different inputs because its objective is to learn the teacher’s relevance judgments.

Other techniques also make the process of training larger teacher models more manageable. For example, QLoRA combines compressed model weights with small trainable adapters. Similarly, mixed precision reduces the numerical precision used in parts of the computation, while gradient checkpointing trades additional computation for lower memory use.

These techniques help bring down training costs. The teacher-and-student setup also helps handle the challenge of serving relevant predictions at the time of live searches.

Turning Search Logs Into Training Set

Human labels give you a valuable starting point, but collecting them is expensive. Trained people must examine Query-Pin pairs and make judgments according to the relevance guidelines.

Pinterest already has a much larger source of examples. Its search logs.

These logs contain impressions, recording content shown during searches, and engagements, recording interactions with that content. The source dataset has billions of rows. However, knowing that a Pin was displayed or clicked doesn’t automatically give us a 5-level relevance judgment.

Pinterest uses the teacher model to provide those missing judgments for examples that are found from the logs.

In the training flow, the teacher model generates soft labels. It scores across the 5 relevance levels. For example, you might have a pair that gets substantial probability in both L4 and L5. This gives the student model more context about the teacher model’s uncertainty as well as the category that it prefers.

This process takes two ideas and combines them. Knowledge distillation talks about the transfer of information from the teacher model to the student. Semi-supervised learning deals with the use of human-labeled examples together with a much larger collection that doesn’t initially have the relevance labels.

With search logs, you also broaden the coverage of the training data. They are made up of queries from different countries and languages. They also contain changing interests and seasonal concepts that may be missing from the human-labeled collection.

You can have a multilingual teacher model apply its language capabilities to those examples to generate additional training supervision. This way, the student can learn from an even more varied collection of Query-Pin pairs.

How the Student Model Scores Live Search Results

The student model uses a lightweight feed-forward neural network. The inputs to this network come from features available to Pinterest’s search system. It’s organized into 3 groups.

The first group helps describe the query. These features include information about its interests, shopping intent, and a SearchSAGE query embedding. You can think of an embedding as a collection of numbers that represents the characteristics of some data point, such as a query or an image. A trained model learns these representations so that other models can use them as inputs.

The second group talks about the Pin. Pinterest uses PinSAGE embeddings, visual embeddings for the image, and SearchSAGE Pin embeddings. These provide multiple numerical views of the candidate content.

The third group deals with the relationship between the query and the Pin. It includes text-matching scores, BM25 scores across text fields, and historical engagement rates for the pair.

For reference, BM25 is a traditional search scoring method that is based on matching the terms used in a query against the text within a document. It takes care of factors such as how informative a term is and the length of the text being searched. With such features, you give the student direct evidence about word matching along with its learned representations.

Pinterest transforms these inputs into numerical representations and passes them through the student model’s feed-forward network to predict the 5-level relevance scores.

During training, the student has already learnt to match the teacher model’s predictions. During live search, it computes its own predictions from its available features. The teacher model’s judgments are already ingrained into the parameters that it has learnt.

Finally, the student model’s relevance score contributes to the final ranking along with other engagement predictions. This connects the new model back to the original product goal. Showing content that handles the search while also making sure whether people will find it the content worth interacting with.

The Evaluation of the Approach

Pinterest evaluates several parts of their new approach to understand which decisions have contributed to the improvement.

One measurement is 5-level accuracy, which checks whether the predicted category matches the evaluation label. This is a strict measure. If the model predicts L4 when the evaluation label is L5, they still count it as an error, even though both categories try to depict content that’s useful.

The Pinterest engineering team also reports AUROC, which measures how well model scores separate groups of examples. They evaluate this by using relevance cutoffs at levels 3, 4, and 5. For example, you might have a cutoff at L4 that asks how effectively the model distinguishes L4 and L5 examples from lower-relevance examples. This is quite important because you want the search ranking to find the strongest candidates.

The first experiment compares language models while keeping the Pin text features and maximum input length fixed. The SearchSAGE-only baseline achieves 50.3% accuracy, while the strongest tested model, Llama-3-8B, achieves 60.2%. This shows that the tested language model can extract additional relevance information beyond the embedding-based baseline.

The second experiment talks about the text supplied to the teacher. With the model and maximum text length held fixed, accuracy rises from 45.7% using synthetic captions alone to 58% using the full set of text features. Adding titles, descriptions, linked-page information, board titles, and historical query information improves the result.

This shows that better representations of Pins contribute to better judgments even when the underlying model stays the same.

The third experiment checks the amount of student training data. A student trained on roughly 300K human labels achieves 48.4% accuracy. Training with 30 million teacher-generated labels raises this to 54.8%.

The result is a great indicator of the practical value of distillation. A large collection of useful teacher model judgments can train a stronger production model than the available human labels alone.

Conclusion

Offline experiments show that a model makes better predictions on an evaluation dataset.

Pinterest also needs to determine whether these predictions improve the search experience.

Therefore, the Pinterest engineering team takes an online A/B experiment and evaluates search feeds produced with and without the new relevance model.

One evaluation uses nDCG@20. It tries to measure relevance across the first 20 results, which gives greater weight to results that appear nearer the top. A highly relevant Pin in the first position contributes more than the same Pin much farther down the list.

This is a great indicator of how users experience search. The ordering is super important because users encounter the first few results before deciding whether to continue checking things further.

Pinterest reports a 2.18% improvement in nDCG@20. This checks the quality of the ranked feed. It extends the evidence beyond whether a model assigns individual labels correctly.

The team also performed human relevance evaluations across countries. These evaluations reported improvements for the United States, Germany, France, and the United Kingdom.

Finally, Pinterest measures search fulfillment, which tracks search sessions resulting in a high-significance user action. The reported improvements are 0.7% for US traffic and 2.0% for non-US traffic. This connects the relevance improvements to changes in user behaviour.

  • Improving Pinterest Search Relevance Using Language Models
  • Research Paper: Pinterest Search Relevance Using Large Language Models

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by ByteByteGo
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗