Correct Sampling Bias From In-Batch Negatives in Two-Tower Retrieval

Last updated: November 29, 2026

Quick Overview

A two-tower retrieval model for YouTube is trained with in-batch softmax, using other items in the batch as negatives. Explain the bias this introduces toward popular items and how logQ correction fixes it.

Google
Machine Learning
Machine Learning Engineer
Google
November 29, 2026
Machine Learning Engineer
Onsite
Machine Learning
Hard

0

0

0 solved


A two-tower retrieval model for YouTube is trained with in-batch softmax, using other items in the batch as negatives. Explain the bias this introduces toward popular items and how logQ correction fixes it.

Candidate generation at YouTube and Play uses two-tower models trained with sampled softmax, and Google's recommender research popularized the sampling-bias correction. Interviewers check that you can derive why the bias appears and apply the fix correctly.

What the Interviewer Expects
  • Explain in-batch negatives and why they are sampled proportional to popularity
  • Show the effect: popular items are over-penalized as negatives
  • Derive the logQ correction to the logits
  • Describe estimating item frequency in a streaming setting
  • Mention mixing in uniform random negatives
Key Topics to Cover
Two-tower models
Sampled softmax
logQ correction
Negative sampling
Popularity bias
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
  • How would you estimate sampling probability for items in a streaming pipeline?
  • What happens to rare items if you skip the correction?
  • How does the temperature in the softmax interact with the correction?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Explore ML Interview Prep
Sample Answer
Clarify

Model: user tower u(x)u(x) and item tower v(y)v(y), score s(x,y)=u(x)Tv(y)s(x,y) = u(x)^T v(y). Training pairs are (user, watched item). A batch of BB pairs uses each other row's item as a negative....

Approach

Full softmax over the corpus P(y∣x)=es(x,y)∑y′es(x,y′)P(y|x) = \frac{e^{s(x,y)}}{\sum_{y'} e^{s(x,y')}} is too expensive. Sampled softmax approximates the denominator with a sample, which is unbiased only if logits are corr...


Submit Your Answer
Markdown supported