The interview problem
A search team trains a relevance regressor. Its squared error improves, but the first few results get worse. Compare pointwise, pairwise and listwise training. Work through a counterexample, choose a loss for graded judgments and explain what changes when labels come from clicks.
Original fundamentals practice, not a reported company interview. All numerical examples are invented. Technical references retrieved September 27, 2026.
1. Define the ranking contract
Assume each query has a candidate list, item features available at serving time and relevance judgments from 0 to 3. Higher scores sort first. Our hypothetical product shows two results, and we average NDCG@2 equally over queries with positive ideal gain. State a separate convention for all-zero queries rather than dividing by zero.
Use gain 2relevance − 1 and position discount 1/log₂(rank + 1). This gain choice values grade 3 more than three grade-1 results. It is a product assumption, not an inevitable property of relevance labels. Fix candidate generation during the loss comparison so a retrieval change does not masquerade as a better ranker.
The data flow is query grouping → feature and label validation → loss construction → score model → sorting → held-out ranking evaluation. Keep the query boundary intact through sampling and batching.
2. Show why smaller prediction error can hurt ordering
Consider three items A, B and C with grades [3, 2, 0]. Model X predicts [1.2, 1.1, 0]. Its mean squared error is (1.8² + 0.9² + 0²)/3 = 1.35. It nevertheless orders every item correctly.
Model Y predicts [2.4, 2.5, 0]. Its squared error is much smaller: (0.6² + 0.5²)/3 ≈ 0.2033. But it places B above A. Ideal DCG@2 is 7 + 3/log₂(3) ≈ 8.8928. Model Y gets 3 + 7/log₂(3) ≈ 7.4165, so its NDCG@2 is about 0.8340 instead of X's 1.0.
This does not make pointwise training useless. It can be a strong baseline, and calibrated outcome probabilities matter when decisions combine probability with value or cost. The example shows that numerical closeness to a grade and ordering near the top are different objectives. Graded relevance scores also need not be meaningful regression intervals.
3. Calculate a pairwise update
For a judged preference A over B, define d = score(A) − score(B) and logistic loss log(1 + exp(−d)). With d = 1, loss is approximately 0.3133; with d = −1, it is approximately 1.3133. At equal scores it is log(2), about 0.6931. Use a numerically stable softplus implementation.
The derivatives with respect to the preferred and other score are −1/(1 + exp(d)) and its negative, respectively. At d = 0 these are −0.5 and +0.5. If scores were independent optimization variables, a gradient descent step would raise the preferred score and lower the other. With shared model parameters, these derivatives define the desired score directions; a parameter update can affect other items and need not move every pair correctly. Pairwise differences are unchanged if the same constant is added to every score for a query, so this objective alone does not calibrate absolute probabilities.
Plain pair counting does not express which position or relevance gap matters most. Swapping A and B in the example changes NDCG@2 by about 0.1660. Swapping two items both outside the top two changes this metric by zero, although it can still create a pairwise error. LambdaRank uses metric-dependent swap weights in its update construction; it is not ordinary differentiation through the sorting operation.
4. Construct a listwise alternative
For an illustrative listwise objective, normalize positive gains into target probabilities. Grades [3, 2, 0] give gains [7, 3, 0], so target p is [0.7, 0.3, 0]. Let q be softmax over the three model scores and minimize −Σ pᵢ log(qᵢ). This is one explicitly chosen surrogate, not a definition of all listwise losses.
At equal scores q is [1/3, 1/3, 1/3], the loss is log(3) ≈ 1.0986, and score gradients q − p are approximately [−0.3667, 0.0333, 0.3333]. For direct score updates, A rises, C falls strongly, and B falls slightly relative to this initially uniform distribution. B is relevant, but its current probability exceeds the chosen target 0.3.
For q = [0.69, 0.30, 0.01], loss is about 0.6209. The infimum occurs at q = p and is the target entropy, about 0.6109, not zero. A finite softmax cannot give C exactly zero probability. This surrogate has no explicit position discount and does not guarantee optimum NDCG@2 under model constraints.
If every gain is zero, normalization is undefined: skip that list for this objective or specify another supervision rule. Mask padding before normalization. Adding sampled negatives changes the softmax denominator and the training problem; candidate-list construction belongs in the experiment specification.
5. Bound cost without silently changing weights
A list of 100 items has at most 4,950 unordered pairs; a list of 1,000 has 499,500. Only unequal-label pairs are preferences in this example. Sampling pairs reduces work, but sampling harder negatives preferentially changes the distribution unless the intended weighting accounts for it.
Decide whether each query or each pair has equal importance. Averaging all pairs across the dataset can give long lists much more influence than short lists. If the evaluation gives every query equal weight, begin with an average within each query followed by an average over queries, and handle queries without eligible pairs explicitly.
Listwise softmax over fixed item scores can be computed in linear time in list length. That does not make an arbitrary list-aware scoring network linear: cross-item attention, for example, has its own cost. Training objective and scoring architecture are separate choices.
6. Diagnose label and evaluation failures
An unclicked item is not necessarily irrelevant; it may never have been examined. A loss change cannot repair missing exposure information by itself. Record impressions, positions and the logging policy. Keep human-judged evaluation or carefully designed exploration data to distinguish relevance gains from imitation of the old ranker.
Split by time and prevent repeated query or user patterns from leaking in ways inconsistent with the intended generalization test. Report uncertainty using the appropriate independent unit, not individual document rows when outcomes are grouped. Compare head and tail queries, language slices and lists with sparse judgments.
Test ties, all-zero labels, padded lists, very long lists and incomplete judgments. Never treat unjudged documents as proven negatives without acknowledging the assumption. A ranker cannot recover a useful document absent from the candidate set, so retain retrieval diagnostics alongside ranking metrics.
7. Defend the choice
Start with the simplest credible baseline, then compare the alternative under the same features, candidate sets and evaluation protocol. For graded top-of-list quality, test a metric-weighted pairwise method alongside the stated listwise surrogate. Choose using held-out quality, operational cost and downstream product evidence, not the name of the loss.
Follow-ups: Why does adding a score constant leave the pairwise loss unchanged? What happens when a new negative joins a softmax list? How would query weights change for a traffic-weighted product metric? When do you need calibrated probabilities in addition to good ordering?
Score 0–2 each for the counterexample, gradient calculation, metric alignment, query/sampling weights and label-bias diagnosis. A strong answer identifies which assumptions the proposed loss cannot fix.
Expose an accidental query-weighting change
Additional original practice exercise · October 3, 2026. Numbers are illustrative assumptions.
Query A has 10 candidates with distinct grades and query B has 100. If every unordered pair is eligible, A contributes 45 pairs and B contributes 4,950. Averaging all pair losses makes B's weight 110 times A's, even if the product metric gives both queries equal weight. With tied grades there are fewer eligible pairs, so compute the actual counts rather than substituting list length.
For equal-query weighting, first average eligible pair losses within each query, then average query losses. Define what happens when a query has no eligible pairs. Sampling the same number of pairs per query is another design, but nonuniform hard-pair sampling still changes the within-query objective unless its weighting is accounted for.
Practice: duplicate B's candidate list in a test fixture. Explain which metrics and loss weights should remain invariant, and which legitimately change because the candidate universe changed. A loss improvement without a fixed evaluation protocol is not a ranking win.
Related practice: Design a search ranking system · Design a fraud detection system
Sources and next steps
- Burges: From RankNet to LambdaRank to LambdaMART — pairwise logistic updates and metric-dependent weighting.
- TensorFlow Ranking overview — ranking losses and evaluation tooling.
All prediction vectors, gradients, gain-normalized targets and sizing examples above are original calculations. For metric interpretation, continue with evaluating recommendations.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.