Algorithm Search⌘K

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 γ\gamma, 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 d1,…,dnd_1, \ldots, d_n. Each document has an attractiveness ada_d and a satisfaction sds_d, and γ\gamma is shared by all sessions. At rank ii there are hidden events EiE_i (examined), AiA_i (attracted), SiS_i (satisfied) and the observed click CiC_i:

  • E1=1E_1 = 1, and Ci=1C_i = 1 exactly when Ei=1E_i = 1 and Ai=1A_i = 1, with P(Ai=1)=adiP(A_i = 1) = a_{d_i}.
  • After a click, P(Si=1∣Ci=1)=sdiP(S_i = 1 \mid C_i = 1) = s_{d_i}; without a click, Si=0S_i = 0.
  • A satisfied user stops: P(Ei+1=1∣Si=1)=0P(E_{i+1} = 1 \mid S_i = 1) = 0.
  • Otherwise the user goes on with probability γ\gamma: P(Ei+1=1∣Ei=1,Si=0)=γP(E_{i+1} = 1 \mid E_i = 1, S_i = 0) = \gamma, 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 γ\gamma applies after a skip and after an unsatisfying click.

What it counts

The model gives a probability to every click vector c1,…,cnc_1, \ldots, c_n, including vectors with several clicks. A forward pass computes it in O(n)O(n) time. Keep two numbers: ee, the probability of the clicks so far and that rank ii is examined, and ff, the probability of the clicks so far and that the user has stopped. Start with e=1e = 1, f=0f = 0. At rank ii, with a=adia = a_{d_i} and s=sdis = s_{d_i}:

  • if ci=1c_i = 1: e←e a(1−s)γe \leftarrow e\, a (1 - s) \gamma and f←e a(s+(1−s)(1−γ))f \leftarrow e\, a \big(s + (1 - s)(1 - \gamma)\big), with the old ee on the right, because only an examined user clicks;
  • if ci=0c_i = 0: e←e(1−a)γe \leftarrow e (1 - a) \gamma and f←f+e(1−a)(1−γ)f \leftarrow f + e (1 - a)(1 - \gamma).

The answer is e+fe + f after the last rank. The probability of a click at rank ii alone is adia_{d_i} times the probability that rank ii is examined, and that probability falls by the factor γ (1−adsd)\gamma\,(1 - a_d s_d) at each rank.

For example, take the ranking x, y, z with a=(0.5,0.4,0.3)a = (0.5, 0.4, 0.3), s=(0.6,0.5,0.5)s = (0.6, 0.5, 0.5) and γ=0.9\gamma = 0.9:

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 0.50.5, 0.2520.252 and 0.136080.13608. Each of the 8 values matches an enumeration over all 292^9 settings of the hidden attraction, satisfaction and perseverance coins in the tests.

Relation to other models

  • Cascade model. With γ=1\gamma = 1 and sd=1s_d = 1 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 γ=1\gamma = 1 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 adsda_d s_d. 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 γ=1\gamma = 1, that the user examines every result down to the last click and then stops. Then all events above the last click are observed and

a^d=clicks on dsessions with d at or above the last click,s^d=sessions where d is the last clickclicks on d.\hat a_d = \frac{\text{clicks on } d}{\text{sessions with } d \text{ at or above the last click}}, \qquad \hat s_d = \frac{\text{sessions where } d \text{ is the last click}}{\text{clicks on } d}.

These are maximum likelihood estimates under that assumption. Under the model itself with γ=1\gamma = 1, 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 ln⁡(2/δ)/(2n)\sqrt{\ln(2/\delta)/(2n)} for δ=10−6\delta = 10^{-6}.

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.

dbn_click_model.pyI0RawGitHub
# 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

  1. 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)
  2. 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)
  3. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/H0ZAVM/text.yaml