Train a Two-Tower Retrieval Model With In-Batch Negatives
Last updated: November 29, 2026
Quick Overview
Explain how a two-tower model retrieves candidates for Reels or friend suggestions, how in-batch negatives work, and what bias they introduce and how to correct it.
Meta
November 29, 20260
0
0 solved
Explain how a two-tower model retrieves candidates for Reels or friend suggestions, how in-batch negatives work, and what bias they introduce and how to correct it.
Candidate retrieval at Meta uses embedding-based retrieval with approximate nearest neighbor search, so MLE screens often probe two-tower training details. The interviewer checks the softmax formulation, popularity bias from in-batch sampling, and the logQ correction.
What the Interviewer Expects
- Describe user and item towers producing embeddings scored by dot product
- Write the sampled softmax loss with in-batch negatives
- Explain why in-batch negatives over-penalize popular items
- Apply the logQ correction
- Mention hard negatives and ANN serving
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Why use a dot product instead of a cross network at retrieval time?
- How would you add mixed negatives from a uniform pool?
- How do you keep item embeddings fresh for new videos?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Retrieval must select a few thousand candidates from hundreds of millions of items in milliseconds, so the scoring function must be decomposable: , letting item em...
Approach
Train on positive pairs (user, item engaged). For a batch of pairs, treat other items in the batch as negatives for each user. This is cheap because item embeddings are already computed for the ba...