Correct Sampling Bias When Training Two-Tower Retrieval with In-Batch Negatives
Last updated: November 29, 2026
Quick Overview
You train a two-tower retrieval model for product recommendations using in-batch negatives. Explain the bias this introduces toward or against popular items and how to correct it.
Amazon
November 29, 20260
0
0 solved
You train a two-tower retrieval model for product recommendations using in-batch negatives. Explain the bias this introduces toward or against popular items and how to correct it.
Candidate generation for Amazon recommendations and search typically uses two-tower models with approximate nearest neighbor serving. This question probes whether you understand the softmax approximation behind in-batch negatives and the log-frequency correction, which separates people who have trained these models from people who have read about them.
What the Interviewer Expects
- Explain why in-batch negatives are a sampled softmax
- Identify that popular items are oversampled as negatives
- Derive the logQ correction
- Discuss hard negatives and mixed negative sampling
- Explain how to evaluate the retriever (recall@K)
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
- How would you estimate item sampling probabilities in a streaming setting?
- What happens if you add random negatives from the whole catalog as well?
- How do false negatives (items the user would have liked) hurt training?
- Why might you use a temperature, and how do you tune it?
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
Each training example is a (user context, purchased item) pair. Within a batch of size , every other example's item serves as a negative. Ask about catalog size, item popularity skew, and whether s...
Approach
The ideal objective is a full softmax over all items: . In-batch negatives approximate the denominator with items sampled in proportion to their freque...