#112Clipped Inverse Propensity WeightingMediumCalculusML System DesignAsked atMeta · Google · Amazon
Clipped Inverse Propensity Weighting
Background
Click-through training data is biased by where each impression appeared: a slot-1 impression has a much higher prior probability of being clicked than a slot-10 impression. Inverse propensity weighting (IPW) corrects for this by weighting each example by where is the prior click probability at the example's slot. Clipped IPW caps the weight at so a single rare-slot example doesn't dominate the gradient.
Problem statement
Implement clipped_ipw_weights(slot_indices, slot_priors, w_max=5.0):
Input
slot_indices- sequence ofintslot positions for each example.slot_priors- sequence offloat > 0, slot prior click probability indexed by slot position.w_max-float > 0, clip ceiling (default ).
Output
np.ndarrayof weights, same length asslot_indices.
Examples
Input: slot_indices=[0, 1, 9], slot_priors=[1.0, 0.5, 0.05]
(where slot 0 always clicks, slot 9 rarely)
Output: [1.0, 2.0, 5.0] # 1/0.05 = 20 clipped to 5
Constraints
- required; ValueError otherwise.
- Slot index out of bounds raises IndexError.
Notes
- Why clip. Without clipping, variance grows like , so a slot-10 example with has 10x the variance of a slot-1 example. Clipping at is the canonical production default.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: rare slot clipped at w_max
- •Worked example: slot with prior 0.1 clips to default 5
- •Sample: mixed slots weighted independently, no clip