AI & Machine Learning Master Course — 157. Exposure bias and recommendation experiments
Smartyfy AI & Machine Learning Master Course
Course ID: smartyfy-ai-ml-master-200
Lesson 157: Exposure bias and recommendation experiments
Prerequisites: Lesson 156. Learning outcome: Identify feedback loops and evaluate product impact with appropriate experiments.
The system helps create the data it observes
Recommendation logs are produced by a policy that selects items, positions, and presentation. More exposure creates more opportunities for interaction. Training on those interactions and then giving popular items still more exposure can create a feedback loop, even if the model never sees an explicit popularity feature.
Distinguish exposure bias from a model simply making inaccurate predictions. Exposure changes which outcomes are observed. Two items can have different click rates because they reached different audiences or occupied different positions. A logged click is evidence about an observed opportunity, not a randomized comparison against every unshown item.
Write the product question as a policy comparison: what would change if eligible users received the proposed recommendation procedure instead of the existing one? This question involves outcomes under different decisions. An offline accuracy score on historical exposures only partially addresses it.
Understand the importance-weighting identity
Let p(a|x) be the logging policy’s probability of selecting action a in context x, and let pi(a|x) be a target policy. An inverse-propensity-scoring, or IPS, contribution weights an observed reward by pi(a|x)/p(a|x). Averaging over logged decisions can estimate target-policy value under appropriate identification and logging assumptions.
The probability must describe the actual action selection mechanism. A predicted click probability is not a propensity. The context must capture the variables needed for the relevant conditional comparison, and the reward and action definitions must be consistent between logging and evaluation.
Support is essential: whenever the target policy might choose an action, the logging policy must give it positive probability in that context. A zero-probability action supplies no observed outcome to reweight. Tiny probabilities create large weights and potentially high variance. Weight clipping or self-normalization changes the estimator and can introduce bias; it is not free certainty.
For recommendation slates, the action may be the complete ordered list rather than one item. Item-level propensities need assumptions that justify their use for the chosen slate-level outcome. This lesson uses one binary action choice per context to make the identity visible.
CPU lab: exact expectations in a two-context world
The invented population has two equally common contexts. The logging policy chooses item A with probabilities 0.9 and 0.2. A’s expected rewards are 0.2 and 0.8 respectively. The target policy always selects A.
The target’s true value in this fully specified world is (0.2 + 0.8)/2 = 0.5. Among logged A selections, the low-reward context is overrepresented. Its conditional mean reward is approximately 0.309091. The difference comes from context selection, not from changing A’s supplied reward function.
IPS weights logged A choices by approximately 1.111111 and 5. Taking the exact expectation cancels the logging probabilities and recovers 0.5. The code enumerates this expectation; it does not sample a real log or demonstrate finite-sample estimator accuracy. The final check identifies a zero-support alternative policy but does not attempt division by zero.
import numpy as np
# Exact expectations in an invented world, not sampled logged outcomes.
context_mass=np.array([.5,.5])
logging_A=np.array([.9,.2])
reward_A=np.array([.2,.8])
assert np.all(logging_A>0)
true_target_value=np.sum(context_mass*reward_A)
selected_mean=np.sum(context_mass*logging_A*reward_A)/np.sum(context_mass*logging_A)
ips_expectation=np.sum(context_mass*logging_A*(1/logging_A)*reward_A)
print('Target always-A value:',round(float(true_target_value),6))
print('Mean reward conditional on logged A:',round(float(selected_mean),6))
print('IPS expectation:',round(float(ips_expectation),6))
print('Importance weights for logged A:',(1/logging_A).round(6).tolist())
assert np.isclose(true_target_value,.5)
assert np.isclose(selected_mean,17/55)
assert np.isclose(ips_expectation,true_target_value)
unsupported=np.array([.9,0.])
print('Zero-support policy fails positivity:',bool(np.any(unsupported==0)))
Design an experiment around the actual decision
A randomized comparison can directly assign eligible units to recommendation policies. Choose the assignment unit to match the experience and dependencies. User-level assignment can prevent a person switching variants between visits; request-level assignment answers a different question and can create carryover effects.
Specify a primary outcome, exposure window, analysis population, minimum effect of practical interest, duration or valid sequential rule, and guardrail metrics before launch. A click increase accompanied by more abandonment may not be a product improvement. Track latency, failures, and important experience measures alongside engagement.
Check assignment and instrumentation before interpreting outcomes. A sample-ratio mismatch means observed variant counts deviate suspiciously from the allocation design; it can indicate eligibility, logging, or delivery problems. It is a diagnostic warning, not a treatment-effect estimate. An A/A test can help uncover measurement or assignment defects.
Analyze according to the defined assignment policy rather than retaining only users whose post-assignment behavior looks convenient. Restricting to people who clicked can compare selected groups caused by the treatment itself. Where exposure-based analyses are needed, define their assumptions and logging carefully.
Account for interference and delayed effects
Recommendation can affect inventory, creators, shared social content, or what friends see. One user’s assignment may therefore influence another user’s outcome. Ordinary independent-user analysis can become misleading when this interference is material. Cluster or switchback designs may help in appropriate settings, but introduce their own assumptions and timing requirements.
Short-term novelty can also differ from sustained usefulness. A surprising layout may attract clicks briefly, while repeated exposure changes behavior. Outcomes can arrive late or be censored by a short observation window. Define when rewards are mature enough to analyze.
Offline experiments remain valuable for catching broken rankings, unavailable items, latency problems, and obvious regressions before any user-facing test. They do not automatically establish product impact. This lesson teaches the measurement logic with fictional data and runs no live experiment.
Four practice questions with worked answers
Practice 1
A target always chooses A, while the logging propensity for A is 0.25. What weight applies to an observed A reward?
Answer: The target probability is one, so the ratio is 1/0.25 = 4. This is an action-selection weight, not a claim that the reward itself is four times larger.
Practice 2
Why does the lab’s unweighted logged-A mean differ from 0.5?
Answer: A is selected much more often in the context where its expected reward is 0.2. Conditioning on logged A changes the context mixture. The target policy instead chooses A in both equally common contexts.
Practice 3
Can IPS evaluate a target action with zero logging probability?
Answer: No. The required support condition fails and there is no observed outcome for that action-context combination to reweight. Additional experimental coverage or substantive modeling assumptions would be needed.
Practice 4
Why is analyzing only people who clicked after assignment risky?
Answer: Clicking may itself be affected by the policy. Conditioning on it selects different subsets in the two variants and can destroy the randomized comparability of the originally assigned groups.
Five multiple-choice questions
Question 1
What is the denominator in an IPS importance weight?
- A. The predicted probability that the user clicks the selected item.
- B. The logging probability of the observed action given its context.
- C. The target policy’s probability of selecting any catalog item.
Correct: B. Propensities describe assignment or selection, whereas click probabilities describe outcomes.
Question 2
What does the reported target-policy value of 0.5 represent?
- A. The conditional reward mean among only logged A selections.
- B. An exact target-policy expectation in a fully specified fictional world.
- C. The fraction of all logging-policy decisions that select A.
Correct: B. The code enumerates known probabilities and expected rewards. It does not sample users or measure a live intervention.
Question 3
What can very small logging propensities cause?
- A. Lower importance weights because rare actions are downweighted.
- B. Guaranteed lower estimator variance than the unweighted selected mean.
- C. Large importance weights and unstable finite-sample estimates.
Correct: C. Rare actions can contribute large weighted rewards. Support and confounding assumptions remain separate requirements.
Question 4
What does a sample-ratio mismatch check assess?
- A. Whether the treatment has a positive causal effect on the primary outcome.
- B. Whether both variants necessarily have identical click rates.
- C. Whether observed assignment counts are compatible with the planned allocation.
Correct: C. It is an experiment-integrity diagnostic. It does not directly estimate outcome differences or require equal outcomes.
Question 5
Why might user-level assignment be preferable to request-level assignment?
- A. To maintain a consistent experience when repeated visits have carryover effects.
- B. To guarantee that one user can never influence another user.
- C. To remove every need to account for delayed outcomes.
Correct: A. Persistent assignment can reduce within-user switching. Interference and delayed measurement still require attention.
Common pitfalls
Do not confuse response probabilities with propensities, ignore support, present exact synthetic expectations as sampled evidence, or condition casually on post-assignment behavior. Check experiment health before interpreting apparent lift.
Summary
Exposure determines which recommendation outcomes become observable. IPS requires trustworthy selection probabilities and support; randomized experiments require valid assignment, measurement, and analysis. Neither a weighting formula nor an offline ranking score alone establishes product impact.