Algorithm Search⌘K

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 rr is examined with a probability γr\gamma_r that depends on the rank only, and document dd attracts with a probability αd\alpha_d 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 d1,…,dnd_1, \ldots, d_n. For each rank rr, independently of all other ranks:

  • the user examines rank rr, Er=1E_r = 1, with probability γr\gamma_r;
  • the document is attractive, Ar=1A_r = 1, with probability αdr\alpha_{d_r}, independently of ErE_r;
  • the click is Cr=ErArC_r = E_r A_r.

This is the examination hypothesis, C=1C = 1 exactly when E=1E = 1 and A=1A = 1. 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 γ1=1\gamma_1 = 1 by convention (footnote to Section 3.3 of Chuklin, Markov and de Rijke).

What it counts

The probability of a click vector c1,…,cnc_1, \ldots, c_n is the product over ranks of

P(Cr=1)=γrαdr,P(Cr=0)=1−γrαdr.P(C_r = 1) = \gamma_r \alpha_{d_r}, \qquad P(C_r = 0) = 1 - \gamma_r \alpha_{d_r}.

Any number of clicks is possible, and the click at one rank says nothing about the others. For example, with γ=(1,0.5)\gamma = (1, 0.5) and αa=0.6\alpha_a = 0.6, αb=0.4\alpha_b = 0.4, the ranking a, b has click probabilities 0.60.6 and 0.5⋅0.4=0.20.5 \cdot 0.4 = 0.2, and is clicked at both ranks with probability 0.6⋅0.2=0.120.6 \cdot 0.2 = 0.12. The ranking b, a has 0.40.4 and 0.30.3. 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 rr 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 γ\gamma, all ranks are examined and αd\alpha_d 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 γr>0\gamma_r > 0 is known, weighting each click at rank rr by 1/γr1 / \gamma_r 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 γrαd\gamma_r \alpha_d alone, so (tγ,α/t)(t \gamma, \alpha / t) fits the data exactly as well as (γ,α)(\gamma, \alpha) for every t>0t > 0 that keeps all values in [0,1][0, 1]. One fixes the scale with γ1=1\gamma_1 = 1, or compares the ratios γr/γ1\gamma_r / \gamma_1 and the products αdγ1\alpha_d \gamma_1. 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 Nd,rN_{d,r} be the number of impressions of dd at rank rr and Kd,rK_{d,r} the clicks among them. A click shows E=A=1E = A = 1. For a non-click, Bayes' rule gives

P(E=1∣C=0)=γr(1−αd)1−γrαd,P(A=1∣C=0)=αd(1−γr)1−γrαd.P(E = 1 \mid C = 0) = \frac{\gamma_r (1 - \alpha_d)}{1 - \gamma_r \alpha_d}, \qquad P(A = 1 \mid C = 0) = \frac{\alpha_d (1 - \gamma_r)}{1 - \gamma_r \alpha_d}.

The M-step sets γr\gamma_r to the expected examinations at rank rr divided by ∑dNd,r\sum_d N_{d,r}, and αd\alpha_d to the expected attractions of dd divided by ∑rNd,r\sum_r N_{d,r}:

γr←∑d(Kd,r+(Nd,r−Kd,r)P(E=1∣C=0))∑dNd,r,αd←∑r(Kd,r+(Nd,r−Kd,r)P(A=1∣C=0))∑rNd,r.\gamma_r \leftarrow \frac{\sum_d \big(K_{d,r} + (N_{d,r} - K_{d,r}) P(E = 1 \mid C = 0)\big)}{\sum_d N_{d,r}}, \qquad \alpha_d \leftarrow \frac{\sum_r \big(K_{d,r} + (N_{d,r} - K_{d,r}) P(A = 1 \mid C = 0)\big)}{\sum_r N_{d,r}}.

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 (d,r)(d, r), 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 γ=(1,0.7,0.5,0.35,0.25)\gamma = (1, 0.7, 0.5, 0.35, 0.25) and αd\alpha_d from 0.100.10 to 0.730.73. After 1000 EM iterations from α=γ=0.5\alpha = \gamma = 0.5, every ratio γ^r/γ^1\hat\gamma_r / \hat\gamma_1 and every product α^dγ^1\hat\alpha_d \hat\gamma_1 is within 0.0040.004 of the truth, the fitted scale is γ^1≈0.855\hat\gamma_1 \approx 0.855 rather than 1, and the log likelihood rises at every step. The test asserts a tolerance of 0.030.03. 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 αd\alpha_d, because the average examination over the five ranks is 0.560.56. 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.

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

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

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/56VCGX/text.yaml