Debiasing Click Logs for Ranking: Propensities, IPS, Offline Eval
Machine LearningModel answerLast updated
Design a pipeline that models, estimates and corrects position bias in click-trained feed rankers, then evaluates a new ranker offline using only logged impressions.
Context
You own the ranking model for a personalized content feed. Every impression of a ranked list is logged along with user actions such as clicks, upvotes and dwell time. An audit shows that, after matching on post quality and user intent, a post shown in the first slot is clicked about four times as often as the same kind of post in the fifth slot.
If you train directly on raw clicks, a feedback loop appears. Relevant posts that sit low in the list collect few clicks, the model learns they are unattractive, and it pushes them even lower.
What to cover
Describe a complete approach for modeling, measuring and removing this position bias.
- Click model. Write the examination hypothesis that links the click indicator
C, the relevance indicatorRand the examination indicatorEfor an item at positionk. List the independence assumptions the factorization needs. - Propensity estimation. Give at least two ways to estimate
P(E = 1 | position = k), one based on interventions (randomization or swapping) and one based on observational logs (an EM click model or a dual-learning approach). Compare them on user-experience cost, sample efficiency and implementation effort. - Debiased training. Write an inverse-propensity-weighted objective for a generic loss
L(y_pred, y_true). Explain why it becomes unstable when propensities at deep positions are tiny, and describe how you would stabilize it (for example clipping or self-normalization). - Offline evaluation. Show how to estimate NDCG or average precision of a candidate ranker from logged feedback alone, without exposing it to users. State when that estimator stops being valid, such as when common support (positivity) fails.
Hints
Hint 1
Start from the product form: a click needs the item to be both looked at and relevant. Ask which variables each factor is allowed to depend on.
Hint 2
To isolate the effect of position, find situations where the same item appears at two different positions. Swaps and randomization create these deliberately; historical rankers create them for free.
Hint 3
The expected value of c / p_k equals relevance, which is where the IPS weight comes from. The cost is that small p_k blows up the variance, so think about trading a little bias for stability and monitor effective sample size.
Hint 4
For offline evaluation, re-rank the logged candidates with the new model, but weight each logged click by the inverse propensity of where it was shown, not where the new model would put it. Then ask what happens to items the logger never displayed.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Overview
A good answer has four parts: a precise probabilistic model, practical ways to measure propensities, a debiased objective with variance control, and an honest account of when the offline estimate can be trusted.
1. Examination hypothesis
For context q and post d shown at position k, a click occurs only if the post is examined and relevant:
C = E · R
P(C=1 | q, d, k) = P(E=1 | k) · P(R=1 | q, d) = p_k · r(q, d)
Assumptions needed:
- Position-only examination:
Edepends onkand not on the content (in richer models, also on coarse context such as device). - Position-independent relevance: where a post is placed does not change whether it is relevant.
- No noise clicks:
P(C=1 | E=0) = 0andP(C=1 | R=0) = 0. Trust bias and accidental clicks violate this. - No cross-item effects: examining one slot is independent of what is in other slots. Cascade behavior and diversity effects break this.
A 4x CTR gap between ranks 1 and 5 at fixed quality then implies p_1 / p_5 ≈ 4.
2. Estimating propensities
Interventional
- Randomize the top n on a small traffic slice. Relevance averages out, so
p_k ∝ CTR_k. - Swap pairs: exchange the items at rank 1 and rank k. For the same item,
p_k / p_1 = CTR(at k) / CTR(at 1). Relevance cancels, and the user-experience cost is much smaller than a full shuffle. - Harvesting: different historical rankers or A/B arms already put the same post at different ranks. Treat those as free quasi-swaps.
Observational
- EM click model: treat
EandRas latent and maximize the likelihood∏ (p_k r)^c (1 - p_k r)^(1-c). The E-step computes posteriors overEandRper impression. The M-step updates a per-position table forp_kand a feature-based model forr. - Dual learning (DLA): train a ranker
fand a propensity modelgtogether. The ranker uses weights1/g(k), and the propensity model uses weights1/f(q, d), exploiting the symmetry ofC = E·R.
| Randomize / swap | Harvesting | EM / DLA | |
|---|---|---|---|
| User cost | Real (worse items shown high) | None | None |
| Sample efficiency | Low | Medium | High (uses all logs) |
| Bias risk | Lowest, causal by design | Needs overlapping rankers | Identifiability depends on model capacity |
| Complexity | Simple analysis, needs experiment infra | Moderate | Highest, joint training can be unstable |
Practical recipe: run a small swap experiment as ground truth, use EM or DLA for contextual propensities at scale, and validate the latter against the former.
3. IPS training
Since E[c / p_k] = r, a click weighted by 1/p_k is an unbiased stand-in for relevance:
L_IPS(f) = (1/|Q|) Σ_q Σ_{d: c_qd = 1} L(f(q,d), 1) / p_{k(q,d)}
This is unbiased for losses that are additive over relevant items (pairwise hinge, listwise softmax, DCG surrogates). For pointwise cross-entropy, negatives need correction too:
(c/p) · log σ(f) + (1 - c/p) · log(1 - σ(f))
Variance. A click at a slot with p = 0.02 gets weight 50, so a handful of examples can dominate the gradient. Remedies:
- Clipping:
w = 1 / max(p_k, τ)withτaround 0.05 to 0.1. Introduces a small bias, cuts variance sharply. Tuneτon a randomized holdout. - Self-normalized IPS: divide by the sum of weights per batch or query. Consistent rather than unbiased, and scale-invariant.
- Power weights:
w = p^(-η),ηin (0, 1), interpolating between naive and fully corrected. - Doubly robust: impute relevance with a model and apply IPS to the residual; helps when the imputation is decent.
- Hygiene: truncate training depth, clip gradients, and track effective sample size
(Σw)² / Σw².
4. Counterfactual offline evaluation
For metrics additive over relevant items, such as DCG with λ(r) = 1 / log2(1 + r):
DCG_IPS(f) = (1/|Q|) Σ_q Σ_{d: c=1} λ(rank_f(q,d)) / p_{k_log(q,d)}
Re-rank the logged candidates with the new model to get rank_f, but weight each click by the propensity of the logged position. This is unbiased under the assumptions above.
- NDCG: the ideal DCG needs the unknown count of relevant items. Estimate it as
Σ c/p; the ratio is consistent, not unbiased. - AP: not linear in relevance, so it requires pairwise IPS products with high variance. Prefer DCG-style metrics where possible.
- Stochastic logging policies: slate-level importance ratios explode combinatorially; use item-position or pseudo-inverse estimators.
Failure modes
- Positivity violation: if the logger never showed an item, or never at the positions the new ranker would use, there are no clicks to reweight and the estimator is blind. This covers items below the cutoff or removed by candidate generation. Keep some exploration in production.
- Misspecified propensities: context-dependent examination or trust bias biases results silently.
- Interactions: cascades, duplicates and diversity effects break additivity.
- Non-stationarity: layout changes or population shifts make old
p_kstale. - Heavy-tailed weights: unbiased in theory, but a few huge weights make the estimate useless. Report confidence intervals and effective sample size.
Common mistakes
- Saying "divide by CTR at position" and treating raw CTR ratios as propensities without controlling for relevance.
- Applying IPS only to positives in a pointwise loss.
- Ignoring variance and never validating propensities on a randomized slice.
- Trusting offline estimates for rankers that differ greatly from the logger.
Closing recommendation
Collect a small swap or randomization slice, fit contextual propensities with EM or DLA and cross-check them, train with clipped or self-normalized IPS, evaluate offline with IPS-DCG plus effective sample size, and confirm the final candidate with an online A/B test.