Modelcore
Position-based click model
Also called examination hypothesis model, PBM, position-based model.
A click happens when the user examines a rank, with a probability that depends only on the rank, and the document attracts.
The position-based click model (PBM) is a click model in which a result is clicked when the user examines its rank and is attracted by the document, two independent events: rank is examined with a probability that depends on the rank only, and document attracts with a probability that depends on the document only. It is the simplest model that separates position bias from attractiveness, and it is the basis of most estimates of position bias for unbiased learning to rank. The examination events are hidden, so the parameters are fitted by EM. The cascade model instead makes examination depend on the clicks above, which allows only one click per session.
The machine
A session shows a ranking . For each rank , independently of all other ranks:
- the user examines rank , , with probability ;
- the document is attractive, , with probability , independently of ;
- the click is .
This is the examination hypothesis, exactly when and . Richardson, Dominowska and Ragno used the same factorization in 2007 to predict the click-through rate of ads, and Craswell, Zoeter, Taylor and Ramsey compared it with the cascade model in 2008. Usually by convention (footnote to Section 3.3 of Chuklin, Markov and de Rijke).
What it counts
The probability of a click vector is the product over ranks of
Any number of clicks is possible, and the click at one rank says nothing about the others. For example, with and , , the ranking a, b has click probabilities and , and is clicked at both ranks with probability . The ranking b, a has and . Document a gets twice as many clicks at the top as at the second rank, with the same attractiveness.
Relation to other models
- Cascade model. In the cascade model the examination of rank is the event that all results above were skipped, so it depends on the documents above. In the PBM it does not. The cascade model allows at most one click, the PBM any number.
- User browsing model. The UBM of Dupret and Piwowarski (2008) makes the examination depend on the rank and on the distance to the previous click; the PBM is the case where it depends on the rank only.
- DBN. The DBN model keeps a top-down scan, like the cascade model, and adds satisfaction after a click.
- Click-through rate models. Without , all ranks are examined and is the click-through rate of the document. Those raw rates mix the attraction of a document with the ranks where it was shown, which is the bias the PBM removes.
- Unbiased learning to rank. If the clicks follow the PBM and is known, weighting each click at rank by gives an unbiased estimate of attractiveness. This inverse propensity weighting is the core of unbiased learning to rank, and the PBM is its usual model of examination.
Known results in the model
Only the products are identified. The likelihood depends on the parameters through the products alone, so fits the data exactly as well as for every that keeps all values in . One fixes the scale with , or compares the ratios and the products . The ranks are also only separable from the documents if the same document appears at several ranks: if every document always stays at one rank, the data determine only one click rate per pair, and position bias cannot be told apart from attractiveness. Randomized or swapped rankings, as in the experiment of Craswell et al., give the variation that is needed.
EM updates. Let be the number of impressions of at rank and the clicks among them. A click shows . For a non-click, Bayes' rule gives
The M-step sets to the expected examinations at rank divided by , and to the expected attractions of divided by :
This is the update in the table of Section 4.3 of Chuklin, Markov and de Rijke. Each iteration costs time linear in the number of distinct pairs , not in the number of sessions. As for any EM, the log likelihood never decreases, but EM may stop at a local maximum or a saddle point, and the result depends on the starting values.
A simulation. The tests draw 200000 sessions with a fixed seed, each showing 5 of 10 documents in random order, with and from to . After 1000 EM iterations from , every ratio and every product is within of the truth, the fitted scale is rather than 1, and the log likelihood rises at every step. The test asserts a tolerance of . This is a measurement on simulated data from the model itself; it shows that the fit works, not that real users follow the PBM. In the comparison on a real log in Chapter 7 of Chuklin, Markov and de Rijke, the PBM beats the click-through rate models and the cascade model in log likelihood and perplexity, and comes close to UBM, the best model there, with parameters that are easier to interpret; these are measurements on one log.
Raw rates are biased. In the same simulation, the click-through rate of every document is well below its , because the average examination over the five ranks is . A document shown mostly at the top would look better than an equal document shown lower.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/position-based-click-model/. The authors are listed in prov/56VCGX.jsonl.
"""The position-based click model (PBM) and its EM fit.
A result d shown at rank r (0-based) is clicked with probability
gamma[r] * alpha[d]: the user examines rank r with probability gamma[r],
is attracted by d with probability alpha[d], and the two events are
independent. Clicks at different ranks are independent.
The EM fit works on aggregated counts: n[(d, r)] impressions of d at r
and c[(d, r)] clicks among them.
"""
import math
def simulate(rankings, alpha, gamma, rng):
"""Return one 0/1 click vector for each ranking."""
return [[1 if rng.random() < gamma[r] * alpha[d] else 0 for r, d in enumerate(ranking)] for ranking in rankings]
def aggregate(rankings, clicks):
"""Return (n, c), the impressions and clicks of each (document, rank) pair."""
n, c = {}, {}
for ranking, vec in zip(rankings, clicks):
for r, (d, k) in enumerate(zip(ranking, vec)):
n[(d, r)] = n.get((d, r), 0) + 1
c[(d, r)] = c.get((d, r), 0) + k
return n, c
def log_likelihood(n, c, alpha, gamma):
total = 0.0
for key, m in n.items():
d, r = key
p = gamma[r] * alpha[d]
k = c[key]
if k:
total += k * math.log(p)
if m - k:
total += (m - k) * math.log(1.0 - p)
return total
def em_step(n, c, alpha, gamma):
"""One EM iteration. The parameters must lie strictly inside (0, 1)."""
exam, attr = {}, {}
n_rank, n_doc = {}, {}
for key, m in n.items():
d, r = key
k = c[key]
g, a = gamma[r], alpha[d]
skip = 1.0 - g * a
# Expected numbers of examinations and attractions: a click has both,
# a non-click has E = 1 with g (1 - a) / skip and A = 1 with a (1 - g) / skip.
exam[r] = exam.get(r, 0.0) + k + (m - k) * g * (1.0 - a) / skip
attr[d] = attr.get(d, 0.0) + k + (m - k) * a * (1.0 - g) / skip
n_rank[r] = n_rank.get(r, 0) + m
n_doc[d] = n_doc.get(d, 0) + m
new_gamma = {r: exam[r] / n_rank[r] for r in exam}
new_alpha = {d: attr[d] / n_doc[d] for d in attr}
return new_alpha, new_gamma
def fit(n, c, iterations=500, start=0.5):
"""Run EM from alpha = gamma = start. Return (alpha, gamma, history),
where history holds the log likelihood before each step and at the end."""
alpha = {d: start for d, _ in n}
gamma = {r: start for _, r in n}
history = [log_likelihood(n, c, alpha, gamma)]
for _ in range(iterations):
alpha, gamma = em_step(n, c, alpha, gamma)
history.append(log_likelihood(n, c, alpha, gamma))
return alpha, gamma, history
test_position_based_click_model.py 73 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/position-based-click-model/. The authors are listed in prov/56VCGX.jsonl.
import math
import random
from position_based_click_model import aggregate, em_step, fit, log_likelihood, simulate
DOCS = list(range(10))
TRUE_ALPHA = {d: 0.1 + 0.07 * d for d in DOCS} # 0.10 ... 0.73
TRUE_GAMMA = {0: 1.0, 1: 0.7, 2: 0.5, 3: 0.35, 4: 0.25}
# Sampling error and EM convergence together. With about 20000 impressions
# per (document, rank) pair, the standard error of a click rate is below
# 0.004, so 0.03 leaves a wide margin; the fit is a measurement on one seed.
TOL = 0.03
SLACK = 1e-9 # allowed decrease of the log likelihood from rounding
def data(seed, sessions):
rng = random.Random(seed)
rankings = [rng.sample(DOCS, 5) for _ in range(sessions)]
clicks = simulate(rankings, TRUE_ALPHA, TRUE_GAMMA, rng)
return aggregate(rankings, clicks)
def test_aggregate_counts():
n, c = aggregate([["a", "b"], ["b", "a"], ["a", "b"]], [[1, 0], [1, 1], [0, 0]])
assert n == {("a", 0): 2, ("b", 1): 2, ("b", 0): 1, ("a", 1): 1}
assert c == {("a", 0): 1, ("b", 1): 0, ("b", 0): 1, ("a", 1): 1}
def test_one_em_step_by_hand():
# One pair, 10 impressions, 4 clicks, start at alpha = gamma = 0.5:
# a non-click is examined with probability 0.25 / 0.75 = 1/3.
n, c = {("d", 0): 10}, {("d", 0): 4}
alpha, gamma = em_step(n, c, {"d": 0.5}, {0: 0.5})
assert math.isclose(gamma[0], (4 + 6 / 3) / 10, rel_tol=1e-12)
assert math.isclose(alpha["d"], (4 + 6 / 3) / 10, rel_tol=1e-12)
def test_log_likelihood_never_decreases():
for seed in range(5):
n, c = data(100 + seed, 4000)
_, _, history = fit(n, c, iterations=200)
for before, after in zip(history, history[1:]):
assert after >= before - SLACK
def test_em_recovers_the_identifiable_parameters():
# The likelihood only depends on the products gamma[r] * alpha[d], so
# (gamma * t, alpha / t) fits equally well. With the true gamma[0] = 1,
# compare gamma[r] / gamma[0] and alpha[d] * gamma[0] with the truth.
n, c = data(7, 200000)
alpha, gamma, history = fit(n, c, iterations=1000)
for before, after in zip(history, history[1:]):
assert after >= before - SLACK
scale = gamma[0]
for r, g in TRUE_GAMMA.items():
assert abs(gamma[r] / scale - g) <= TOL
for d, a in TRUE_ALPHA.items():
assert abs(alpha[d] * scale - a) <= TOL
# The fitted model is at least as likely as the truth on these data.
assert history[-1] >= log_likelihood(n, c, TRUE_ALPHA, TRUE_GAMMA) - 1e-6
def test_raw_click_rates_are_biased():
# Without the model, the click rate of a document mixes its attraction
# with the examination of the ranks where it was shown.
n, c = data(8, 20000)
for d in DOCS:
shown = sum(m for (x, _), m in n.items() if x == d)
clicked = sum(k for (x, _), k in c.items() if x == d)
assert clicked / shown < TRUE_ALPHA[d] * 0.8
References
- Matthew Richardson, Ewa Dominowska and Robert Ragno, Predicting clicks, estimating the click-through rate for new ads, Proceedings of the 16th International Conference on World Wide Web (WWW 2007), 521-530, the assumption that the probability of a click is the probability that the ad is seen, which depends on its position, times the probability that it is clicked once seen
- Nick Craswell, Onno Zoeter, Michael Taylor and Bill Ramsey, An experimental comparison of click position-bias models, Proceedings of the 2008 International Conference on Web Search and Data Mining (WSDM 2008), 87-94, the examination hypothesis as one of the four position-bias models compared, with the cascade model
- Aleksandr Chuklin, Ilya Markov and Maarten de Rijke, Click Models for Web Search, Morgan and Claypool 2015, reissued by Springer, Section 3.3 (the position-based model, Equations 3.4 to 3.8, with the convention that the first rank is always examined), Section 4.2 (the EM algorithm for click models), Section 4.3 (the table of update formulas, including the PBM update) and Chapter 7 (an experimental comparison of click models)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 56VCGX Edit this page History Report an error Markdown