Modeladvanced
Dynamic Bayesian network click model
Also called Chapelle-Zhang click model, DBN click model, DBN.
Extends the cascade model so that a clicked document may or may not satisfy the user, who continues with a fixed perseverance.
The dynamic Bayesian network (DBN) click model is a click model in which the user scans the results from the top, clicks attractive ones, and after each click is either satisfied and stops, or not satisfied and goes on with a fixed probability , the perseverance. Olivier Chapelle and Ya Zhang introduced it in 2009 to estimate the relevance of documents from search logs. It extends the cascade model, which stops at the first click, and it separates two things that a single click rate mixes: how attractive a result looks in the list, and how satisfying the document is once opened. The model is a dynamic Bayesian network over the ranks, its hidden states make the fit an EM problem, and the position-based model is the alternative without a top-down scan.
The machine
A session shows a ranking . Each document has an attractiveness and a satisfaction , and is shared by all sessions. At rank there are hidden events (examined), (attracted), (satisfied) and the observed click :
- , and exactly when and , with .
- After a click, ; without a click, .
- A satisfied user stops: .
- Otherwise the user goes on with probability : , and a user who stopped never resumes.
These are Equations 3.34 to 3.40 in Section 3.8 of Chuklin, Markov and de Rijke. The same applies after a skip and after an unsatisfying click.
What it counts
The model gives a probability to every click vector , including vectors with several clicks. A forward pass computes it in time. Keep two numbers: , the probability of the clicks so far and that rank is examined, and , the probability of the clicks so far and that the user has stopped. Start with , . At rank , with and :
- if : and , with the old on the right, because only an examined user clicks;
- if : and .
The answer is after the last rank. The probability of a click at rank alone is times the probability that rank is examined, and that probability falls by the factor at each rank.
For example, take the ranking x, y, z with , and :
| clicks | probability | clicks | probability |
|---|---|---|---|
| 0 0 0 | 0.2471 | 1 0 0 | 0.39884 |
| 0 0 1 | 0.0729 | 1 0 1 | 0.02916 |
| 0 1 0 | 0.1557 | 1 1 0 | 0.06228 |
| 0 1 1 | 0.0243 | 1 1 1 | 0.00972 |
The click rates of the three ranks are , and . Each of the 8 values matches an enumeration over all settings of the hidden attraction, satisfaction and perseverance coins in the tests.
Relation to other models
- Cascade model. With and for every document, a user clicks the first attractive result and stops: this is the cascade model. The tests check this reduction on every click vector.
- Simplified DBN. With alone, the user never leaves without a reason. Chapelle and Zhang (Section 5) and Section 3.8.1 of Chuklin, Markov and de Rijke call this the simplified DBN (SDBN).
- Click chain model and dependent click model. These also extend the cascade model with a chance to go on after a click. The click chain model ties the satisfaction to the attractiveness, while DBN gives each document its own satisfaction parameter.
- Position-based model. The PBM has no scan: the examination of each rank is a fixed probability. DBN explains why ranks below a satisfying result get fewer clicks, which the PBM cannot.
- Hidden Markov models. The examination state moves down the ranks as a Markov chain driven by the clicks, so the forward pass above is the forward algorithm of a hidden Markov model with two states.
- Expected reciprocal rank. Expected reciprocal rank is a metric built on a cascade user who stops at each result with a probability that depends on its relevance, the same idea of satisfaction.
Known results in the model
Relevance from clicks. The probability that an examined document both attracts and satisfies the user is . Chapelle and Zhang use this product as the relevance of the document estimated from the logs, which removes the position bias of raw click rates.
EM fit. The examination and satisfaction events are hidden after the last click, so the full model is fitted by EM, which needs the posterior of these events in each session (Section 4.2.4 of Chuklin, Markov and de Rijke). Above the last click nothing is hidden: every rank was examined, and every earlier click was unsatisfying. The fit can stop at a local maximum.
Counting estimates for the simplified model. Section 4.1.3 of Chuklin, Markov and de Rijke assumes, for , that the user examines every result down to the last click and then stops. Then all events above the last click are observed and
These are maximum likelihood estimates under that assumption. Under the model itself with , a user who is not satisfied by the last click still examines the results below it without clicking, so the assumption is an approximation that drops this hidden examination.
Fit on real logs. In the comparison of Chapter 7 of Chuklin, Markov and de Rijke on a public log of a commercial search engine, DBN and SDBN are among the best models by perplexity, and DBN is close to UBM, the best model by log likelihood. Chapelle and Zhang report that DBN predicts click-through rates and relevance better than the earlier models on their data. Both are measurements on particular logs.
A simulation. The tests also draw 40000 sessions with a fixed seed from a 4-result ranking and check the frequency of each of the 16 click vectors against the forward pass, within the Hoeffding half width for .
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/dbn-click-model/. The authors are listed in prov/H0ZAVM.jsonl.
"""The dynamic Bayesian network click model (Chapelle and Zhang, 2009).
The user examines the first result. At an examined result d the user
clicks with probability a[d]. After a click the user is satisfied with
probability s[d] and then stops. A user who did not click, or clicked and
was not satisfied, examines the next result with probability gamma and
otherwise stops.
click_probability computes P(click vector) with a forward pass over two
numbers: the probability of the clicks so far together with "the current
rank is examined", and together with "the user has stopped".
"""
def click_probability(ranking, clicks, a, s, gamma):
"""P(C_1..C_n = clicks) for the ranking under the DBN model."""
if len(ranking) != len(clicks):
raise ValueError("one click value per rank")
examined, stopped = 1.0, 0.0
for d, c in zip(ranking, clicks):
if c:
# Only an examined user clicks; afterwards the user goes on if
# not satisfied and persevering, and stops otherwise.
stay = examined * a[d] * (1.0 - s[d]) * gamma
stopped = examined * a[d] * (s[d] + (1.0 - s[d]) * (1.0 - gamma))
examined = stay
else:
# A skip by an examined user, or any rank after stopping.
skip = examined * (1.0 - a[d])
examined, stopped = skip * gamma, stopped + skip * (1.0 - gamma)
return examined + stopped
def simulate(ranking, a, s, gamma, rng):
"""Draw one session; return its click vector as a tuple of 0/1."""
clicks = [0] * len(ranking)
for i, d in enumerate(ranking):
if rng.random() < a[d]:
clicks[i] = 1
if rng.random() < s[d]:
break
if rng.random() >= gamma:
break
return tuple(clicks)
def click_rates(ranking, a, s, gamma):
"""P(C_i = 1) for each rank i."""
rates = []
examined = 1.0
for d in ranking:
rates.append(examined * a[d])
examined *= (a[d] * (1.0 - s[d]) + (1.0 - a[d])) * gamma
return rates
test_dbn_click_model.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dbn-click-model/. The authors are listed in prov/H0ZAVM.jsonl.
import math
import random
from itertools import product
from dbn_click_model import click_probability, click_rates, simulate
TOL = 1e-12
def brute_force(ranking, a, s, gamma):
"""Enumerate the attraction, satisfaction and perseverance coins of every
rank, run the user on each outcome, and add up the click vectors."""
n = len(ranking)
dist = {}
for coins in product((0, 1), repeat=3 * n):
p = 1.0
for i, d in enumerate(ranking):
att, sat, per = coins[3 * i : 3 * i + 3]
p *= (a[d] if att else 1.0 - a[d]) * (s[d] if sat else 1.0 - s[d]) * (gamma if per else 1.0 - gamma)
clicks = [0] * n
for i, d in enumerate(ranking):
att, sat, per = coins[3 * i : 3 * i + 3]
if att:
clicks[i] = 1
if sat:
break
if not per:
break
key = tuple(clicks)
dist[key] = dist.get(key, 0.0) + p
return dist
def random_params(rng, docs):
a = {d: rng.random() for d in docs}
s = {d: rng.random() for d in docs}
return a, s, rng.random()
def test_matches_enumeration_of_hidden_states():
rng = random.Random(1)
for _ in range(30):
docs = list(range(rng.randint(1, 5)))
a, s, gamma = random_params(rng, docs)
ranking = docs[:]
rng.shuffle(ranking)
dist = brute_force(ranking, a, s, gamma)
for clicks in product((0, 1), repeat=len(ranking)):
want = dist.get(clicks, 0.0)
assert math.isclose(click_probability(ranking, clicks, a, s, gamma), want, rel_tol=1e-9, abs_tol=TOL)
def test_probabilities_sum_to_one_and_match_click_rates():
rng = random.Random(2)
for _ in range(50):
docs = list(range(rng.randint(1, 8)))
a, s, gamma = random_params(rng, docs)
probs = {c: click_probability(docs, c, a, s, gamma) for c in product((0, 1), repeat=len(docs))}
assert math.isclose(sum(probs.values()), 1.0, rel_tol=0, abs_tol=1e-12)
rates = click_rates(docs, a, s, gamma)
for i, r in enumerate(rates):
marginal = sum(p for c, p in probs.items() if c[i])
assert math.isclose(marginal, r, rel_tol=1e-9, abs_tol=TOL)
def test_reduces_to_the_cascade_model():
# With gamma = 1 and s = 1 the user clicks the first attractive result and stops.
rng = random.Random(3)
for _ in range(30):
docs = list(range(rng.randint(1, 7)))
a = {d: rng.random() for d in docs}
s = {d: 1.0 for d in docs}
for clicks in product((0, 1), repeat=len(docs)):
p = click_probability(docs, clicks, a, s, 1.0)
if sum(clicks) > 1:
assert p == 0.0
continue
want = 1.0
for i, d in enumerate(docs):
if clicks[i]:
want *= a[d]
break
want *= 1.0 - a[d]
assert math.isclose(p, want, rel_tol=1e-12, abs_tol=TOL)
def test_example_of_the_page():
ranking = ["x", "y", "z"]
a = {"x": 0.5, "y": 0.4, "z": 0.3}
s = {"x": 0.6, "y": 0.5, "z": 0.5}
gamma = 0.9
assert math.isclose(click_probability(ranking, (1, 0, 0), a, s, gamma), 0.39884, rel_tol=1e-9)
assert math.isclose(click_probability(ranking, (1, 1, 0), a, s, gamma), 0.06228, rel_tol=1e-9)
assert math.isclose(click_probability(ranking, (0, 0, 0), a, s, gamma), 0.2471, rel_tol=1e-9)
rates = click_rates(ranking, a, s, gamma)
for got, want in zip(rates, [0.5, 0.252, 0.13608]):
assert math.isclose(got, want, rel_tol=1e-9)
def test_monte_carlo_frequencies():
# Each frequency is a mean of n independent indicators, so by Hoeffding's
# bound it is within sqrt(ln(2 / delta) / (2 n)) of its probability with
# probability 1 - delta; delta = 1e-6 for each of the 16 click vectors.
rng = random.Random(4)
ranking = list(range(4))
a, s, gamma = {0: 0.6, 1: 0.5, 2: 0.4, 3: 0.3}, {0: 0.3, 1: 0.5, 2: 0.2, 3: 0.7}, 0.8
n = 40000
counts = {}
for _ in range(n):
c = simulate(ranking, a, s, gamma, rng)
counts[c] = counts.get(c, 0) + 1
tol = math.sqrt(math.log(2.0 / 1e-6) / (2.0 * n))
for clicks in product((0, 1), repeat=4):
p = click_probability(ranking, clicks, a, s, gamma)
assert abs(counts.get(clicks, 0) / n - p) <= tol
References
- Olivier Chapelle and Ya Zhang, A dynamic Bayesian network click model for web search ranking, Proceedings of the 18th International Conference on World Wide Web (WWW 2009), 1-10, the model with attractiveness, satisfaction and the perseverance gamma, its reduction to the cascade model when gamma and the satisfactions are 1, the EM fit, and Section 5 (the simplified model with gamma = 1)
- Aleksandr Chuklin, Ilya Markov and Maarten de Rijke, Click Models for Web Search, Morgan and Claypool 2015, reissued by Springer, Section 3.8 (the DBN model, Equations 3.34 to 3.40), Section 3.8.1 (the simplified DBN and its reduction to the cascade model), Section 4.1.3 (the counting estimates of the simplified DBN, Equation 4.10), Section 4.2.4 (EM estimation for DBN) and Chapter 7 (an experimental comparison of click models)
- 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 cascade model that the DBN model extends
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 H0ZAVM Edit this page History Report an error Markdown