Algorithmresearch
xQuAD
Also called explicit query aspect diversification, eXplicit Query Aspect Diversification.
Greedily picks documents that are relevant to the query and to query aspects not yet covered by the documents already picked.
- Time
- O(n log n + n k m) worst
- Space
- O(n + m) extra
- Where
- k = the number of results; m = the number of aspects; n = the number of candidate documents
- Model
- Word RAM
- Properties
- deterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Rodrygo L. T. Santos, Craig Macdonald, Iadh Ounis, 2010
xQuAD (explicit query aspect diversification) is a greedy algorithm for search result diversification that reranks the top of a first ranking by mixing two scores: how relevant a document is to the query, and how well it covers the aspects (sub-queries) of the query that the documents already picked leave uncovered. Rodrygo Santos, Craig Macdonald and Iadh Ounis introduced it in 2010 and took the aspects from the query reformulations that web search engines suggest. Its diversity term is the coverage objective of IA-Select; xQuAD adds the plain relevance with a weight , so that keeps the first ranking and is IA-Select. Unlike maximal marginal relevance, it never compares two documents with each other.
In plain words
Suppose someone searches for "jaguar", and the search engine knows that people often rewrite that query as "jaguar car" or "jaguar animal". xQuAD treats each rewrite as one need behind the query. It builds the result list one page at a time. A page earns points for matching the original query, and more points for matching a need that the list does not cover yet. Once a car page is in the list, other car pages earn less from the car need, so a good animal page can move up. A slider sets how much the uncovered needs count against the plain match.
The problem
The input is a query , a first ranking of candidates (Santos et al. rerank the top ), the relevance of each candidate, a set of sub-queries with importances that sum to 1, the coverage of each candidate for each sub-query, and a length . The output is a list of documents. In the paper, both and come from a retrieval model, such as BM25 or a query likelihood model, run once for the query and once for each sub-query.
The algorithm
With the list chosen so far, the next document maximizes Equation 5 of the paper:
The product is the probability that no chosen document satisfies , under the assumption that the documents satisfy a sub-query independently. It changes by one factor per pick, so the procedure keeps it per sub-query:
XQUAD(R, rel, P_aspect, cover, λ, k)- 1
for each sub-query i: novel[i] ← 1 - 2
S ← empty list - 3
while some document of R is not in S and |S| < k: - 4
for each d not in S, in id order: - 5
score(d) ← (1 − λ) · rel(d) + λ · Σ over i of P_aspect(i) · cover(d, i) · novel[i] - 6
b ← the d with the largest score, ties to the smaller id; append b to S - 7
for each sub-query i that b covers: - 8
novel[i] ← (1 − cover(b, i)) · novel[i] - 9
return S
Example
The query "jaguar" has two aspects, car with importance 0.6 and animal with 0.4, and four candidates:
| doc | |||
|---|---|---|---|
| d1 | 0.9 | 0.9 | 0 |
| d2 | 0.8 | 0.8 | 0 |
| d3 | 0.6 | 0 | 0.7 |
| d4 | 0.5 | 0.3 | 0.3 |
With the list is the first ranking, d1, d2, d3, d4. With :
| step | novel(car) | novel(animal) | d1 | d2 | d3 | d4 | pick |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0.72 | 0.64 | 0.44 | 0.40 | d1 |
| 2 | 0.1 | 1 | 0.424 | 0.44 | 0.319 | d3 | |
| 3 | 0.1 | 0.3 | 0.424 | 0.277 | d2 | ||
| 4 | 0.02 | 0.3 | 0.2698 | d4 |
After d1, the car aspect is 90% covered, so d2 keeps almost only its relevance, , plus , and d3 moves up because the animal aspect is still open. With the order is d1, d3, d4, d2: d4 covers a little of both aspects and passes d2, whose only aspect is already served.
Correctness
The file proofs/correctness.md proves that the loop picks, at each step, the document of Equation 5 with the tie rule. The invariant is that before each pass, which line L8 keeps. The proof also shows that the score of is the marginal gain of the set function
the sum of a modular term and the IA-Select objective. With non-negative relevance scores, is monotone and submodular, so by the Nemhauser, Wolsey and Fisher theorem the greedy list has at least of the best value of . The paper does not state this bound; it is a consequence of the form of Equation 5. The bound is about under the model, not about measured quality.
Proof: The incremental xQuAD loop picks the document of Equation 5 at every step, and is greedy on a monotone submodular objectivefull
Let be a finite set of candidate ids with a total order, for , a finite set of aspects with weights , coverages , taken as when not given, and . For a chosen set and , Equation 5 of Santos, Macdonald and Ounis is
The xQuAD list with the tie rule of this page is with , where is the smallest id among the maximizers of over , and .
Lemma 1 (invariant). At the start of each pass of the loop of line L3, with the set of ids chosen so far, for every aspect .
Proof. Line L1 sets every value to , the empty product. When is chosen, lines L7 and L8 multiply by for each aspect that covers; for the other aspects and the factor is .
Theorem 2 (output). The procedure returns , each with its score .
Proof. By Lemma 1, line L5 computes , where the sum skips the aspects with , whose terms are . The ids are scanned in increasing order and the best is replaced only on a strictly larger score, so line L6 records the smallest id among the maximizers, which is . The loop runs while ids remain and fewer than are chosen, so it makes passes.
Corollary 3 (lambda = 0). For the output is the first ids in the order rel descending, then id ascending, the first ranking.
Proof. The score is and does not depend on .
Theorem 4 (the set objective). Define, for ,
Then for , so xQuAD is the greedy algorithm on . If for every , is monotone and submodular with , and the list satisfies .
Proof. The first sum grows by . In the second, the product of aspect gains the factor , so its term grows by . Together this is . The first sum is modular, so its marginal gain does not depend on , and it is non-negative when rel is. The second is the objective of IA-Select with and , whose marginal gain is a product of numbers in and can only shrink when grows. A non-negative combination of monotone submodular functions with value on the empty set has the same properties, and because the empty product is . The theorem of Nemhauser, Wolsey and Fisher gives the bound for the greedy algorithm, since by Theorem 2 each pick maximizes the marginal gain.
Santos et al. do not state Theorem 4; they present Algorithm 1 as an instance of the greedy approximation and note that the general problem is NP-hard by a reduction from maximum coverage. The bound concerns under the model, and says nothing about measured effectiveness.
Corollary 5 (lambda = 1). For , xQuAD and IA-Select with and pick the same list under the same tie rule.
Proof. Both scores are the marginal gain of the same function, the second term of .
Cost. Let , , and the number of pairs with . Each of the at most passes computes scores in total time and updates at most values, so the procedure runs in time with extra space. The direct form, which recomputes each product over , takes time.
The test file checks Theorem 2 step by step against the direct form on random instances, half of them on a grid of values so that ties are frequent, and checks for that each score is the largest marginal gain of the coverage term.
Complexity
Each of the at most passes computes scores, each a sum over the sub-queries that the document covers, and updates at most products. The time is , including the sort of the ids, and when only pairs have nonzero coverage. The extra space is . In practice, the main cost is retrieval: one ranking for the query and one for each sub-query. Santos et al. point out that, unlike implicit methods, xQuAD needs no comparisons between the term vectors of documents.
Properties
- Explicit. The aspects are part of the input. The paper takes them from the related and suggested queries of three web search engines.
- Probabilistic mixture. The score mixes relevance and novel coverage with one weight .
- Greedy on a submodular objective. Each pick has the largest marginal gain of , as shown in the proof.
- The ends of the range. gives the first ranking and gives IA-Select with the sub-queries as intents.
- Deterministic. The tie rule fixes the output.
Variants and improvements
- Sub-query importance. Section 4.2.3 of the paper compares a uniform importance (Equation 6) with estimators from the result sets of the sub-queries, including one inspired by the CRCS method of resource selection.
- Other aspect sources. Sub-queries can come from query logs, click graphs, query expansion, clusters of the first ranking, or a taxonomy. Santos et al. also ran xQuAD with the official sub-topics of TREC, as a best case.
- Implicit counterpart. MMR uses the largest similarity to the chosen documents in the place of the per-aspect novelty.
- Without relevance. Setting turns the method into IA-Select, and with coverages of or into weighted greedy max coverage.
When to use it
Use xQuAD when you can produce a few reformulations or sub-topics for an ambiguous query and can score the candidates against each of them, and when you want to keep most of a good first ranking while making room for missed aspects. In the paper, on the 50 queries of the TREC 2009 Web track diversity task, xQuAD with uniform importance improved alpha-nDCG over the BM25, DPH and language model baselines, by up to 30% (BM25, alpha-nDCG@5), and did better than MMR and simulated versions of IA-Select and of the method of Radlinski and Dumais in most settings. These are measurements on one collection, with trained by 5-fold cross validation; the learned value was small, with a peak near for BM25 and DPH in Figure 2.
Pitfalls
- The meaning of lambda. In xQuAD, weights diversity; in MMR, it weights relevance. A value tuned for one does not carry over.
- Probabilities from scores. Equation 5 treats and as probabilities. Raw BM25 scores are not in and are not comparable across sub-queries; normalize them first, or the products and the mix lose their meaning.
- Bad sub-queries. A sub-query that is only a paraphrase of the query adds no diversity, and a wrong one promotes off-topic documents. The quality of the aspects limits the method.
- Coverage of 1. A document with closes the aspect for good: every later document gets nothing from it.
- Evaluation leakage. Running xQuAD with the official sub-topics of a test collection, as the best case in the paper does, uses the judgments' own aspect structure. Report such runs apart from runs with real sub-queries.
Implementations
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/xquad/. The authors are listed in prov/ZHZBK5.jsonl.
"""xQuAD (Santos, Macdonald and Ounis, 2010).
Given the candidates R of a query q, their relevance P(d | q), the aspects
(sub-queries) q_i of q with importance P(q_i | q), and the coverage
P(d | q_i) of each candidate for each aspect, xQuAD builds the list S by
repeatedly taking the candidate with the largest
(1 - lam) * P(d | q) + lam * sum over i of P(q_i | q) P(d | q_i) * prod over d_j in S of (1 - P(d_j | q_i)).
The product, the probability that no chosen document covers aspect q_i,
is kept per aspect and updated after each pick. Ties go to the smaller id.
"""
def _check(docs, rel, p_aspect, cover, lam):
if not 0.0 <= lam <= 1.0:
raise ValueError("lam must lie in [0, 1]")
for d in docs:
if d not in rel:
raise ValueError("every candidate needs a relevance score")
for a, v in cover.get(d, {}).items():
if a not in p_aspect or not 0.0 <= v <= 1.0:
raise ValueError("P(d | q_i) must lie in [0, 1] for a known aspect")
def xquad_steps(docs, rel, p_aspect, cover, lam, k):
"""Return the list of (document, score at the time it was picked)."""
_check(docs, rel, p_aspect, cover, lam)
novel = {a: 1.0 for a in p_aspect} # @line L1
rest = sorted(set(docs))
chosen = [] # @line L2
while rest and len(chosen) < k: # @line L3
best, best_score = None, None
for d in rest: # @line L4
div = sum(p_aspect[a] * v * novel[a] for a, v in cover.get(d, {}).items())
score = (1.0 - lam) * rel[d] + lam * div # @line L5
if best_score is None or score > best_score: # ties keep the smaller id
best, best_score = d, score
chosen.append((best, best_score)) # @line L6
rest.remove(best)
for a, v in cover.get(best, {}).items(): # @line L7
novel[a] *= 1.0 - v # @line L8
return chosen # @line L9
def xquad(docs, rel, p_aspect, cover, lam, k):
"""Return the documents that xQuAD picks, in order."""
return [d for d, _ in xquad_steps(docs, rel, p_aspect, cover, lam, k)]
test_xquad.py 115 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/xquad/. The authors are listed in prov/ZHZBK5.jsonl.
import math
import random
import pytest
from xquad import xquad, xquad_steps
TOL = 1e-12
# The example of the page: "jaguar" with a car aspect and an animal aspect.
REL = {1: 0.9, 2: 0.8, 3: 0.6, 4: 0.5}
ASPECTS = {"car": 0.6, "animal": 0.4}
COVER = {1: {"car": 0.9}, 2: {"car": 0.8}, 3: {"animal": 0.7}, 4: {"car": 0.3, "animal": 0.3}}
def direct_steps(docs, rel, p_aspect, cover, lam, k):
"""Equation 5 of Santos et al., with the product over S recomputed from scratch."""
chosen = []
rest = sorted(docs)
while rest and len(chosen) < k:
scores = {}
for d in rest:
div = 0.0
for a, p in p_aspect.items():
miss = 1.0
for s, _ in chosen:
miss *= 1.0 - cover.get(s, {}).get(a, 0.0)
div += p * cover.get(d, {}).get(a, 0.0) * miss
scores[d] = (1.0 - lam) * rel[d] + lam * div
top = max(scores.values())
best = min(d for d in rest if scores[d] == top)
chosen.append((best, scores[best]))
rest.remove(best)
return chosen
def coverage(selected, p_aspect, cover):
total = 0.0
for a, p in p_aspect.items():
miss = 1.0
for d in selected:
miss *= 1.0 - cover.get(d, {}).get(a, 0.0)
total += p * (1.0 - miss)
return total
def random_instance(rng, grid):
n = rng.randint(1, 10)
m = rng.randint(1, 4)
pick = (lambda: rng.choice([0.0, 0.25, 0.5, 0.75, 1.0])) if grid else rng.random
weights = [rng.random() + 0.01 for _ in range(m)]
p_aspect = {f"a{i}": w / sum(weights) for i, w in enumerate(weights)}
rel = {d: pick() for d in range(1, n + 1)}
cover = {}
for d in rel:
cover[d] = {a: pick() for a in p_aspect if rng.random() < 0.6}
lam = rng.choice([0.0, 0.25, 0.5, 0.75, 1.0]) if grid else rng.random()
return list(rel), rel, p_aspect, cover, lam
def same_steps(a, b):
assert [d for d, _ in a] == [d for d, _ in b]
for (_, x), (_, y) in zip(a, b):
assert math.isclose(x, y, rel_tol=1e-9, abs_tol=TOL)
def test_example_lambda_zero_is_relevance_order():
assert xquad(list(REL), REL, ASPECTS, COVER, 0.0, 4) == [1, 2, 3, 4]
def test_example_lambda_half():
steps = xquad_steps(list(REL), REL, ASPECTS, COVER, 0.5, 4)
assert [d for d, _ in steps] == [1, 3, 2, 4]
for (_, got), want in zip(steps, [0.72, 0.44, 0.424, 0.2698]):
assert math.isclose(got, want, rel_tol=1e-9)
def test_example_lambda_one():
steps = xquad_steps(list(REL), REL, ASPECTS, COVER, 1.0, 4)
assert [d for d, _ in steps] == [1, 3, 4, 2]
for (_, got), want in zip(steps, [0.54, 0.28, 0.054, 0.0336]):
assert math.isclose(got, want, rel_tol=1e-9)
@pytest.mark.parametrize("seed", range(200))
def test_matches_direct_formula_step_by_step(seed):
rng = random.Random(seed)
docs, rel, p_aspect, cover, lam = random_instance(rng, grid=seed % 2 == 0)
k = rng.randint(0, len(docs) + 1)
same_steps(xquad_steps(docs, rel, p_aspect, cover, lam, k), direct_steps(docs, rel, p_aspect, cover, lam, k))
@pytest.mark.parametrize("seed", range(50))
def test_lambda_one_is_greedy_on_coverage(seed):
rng = random.Random(500 + seed)
docs, rel, p_aspect, cover, _ = random_instance(rng, grid=False)
prefix = []
for d, score in xquad_steps(docs, rel, p_aspect, cover, 1.0, len(docs)):
before = coverage(prefix, p_aspect, cover)
gains = {x: coverage(prefix + [x], p_aspect, cover) - before for x in docs if x not in prefix}
assert math.isclose(score, gains[d], rel_tol=1e-9, abs_tol=TOL)
assert all(g <= score + TOL for g in gains.values())
prefix.append(d)
def test_rejects_bad_input():
with pytest.raises(ValueError):
xquad([1], {1: 0.5}, {"a": 1.0}, {1: {"a": 0.5}}, 1.5, 1)
with pytest.raises(ValueError):
xquad([1], {1: 0.5}, {"a": 1.0}, {1: {"b": 0.5}}, 0.5, 1)
with pytest.raises(ValueError):
xquad([1], {}, {"a": 1.0}, {}, 0.5, 1)
History
Santos, Macdonald and Ounis presented xQuAD at WWW 2010 as part of their work at the University of Glasgow on the diversity task of the TREC 2009 Web track. They framed it as a probabilistic version of the greedy approximation used by most earlier methods, with explicit sub-queries in the place of comparisons between documents, and they built on the coverage idea of Agrawal et al. from 2009. xQuAD became one of the standard explicit diversification baselines, together with IA-Select.
References
- Rodrygo L. T. Santos, Craig Macdonald and Iadh Ounis, Exploiting query reformulations for web search result diversification, Proceedings of the 19th International Conference on World Wide Web (WWW 2010), 881-890, Section 2 (implicit and explicit diversification, and NP-hardness by reduction from maximum coverage), Section 4.1 (Algorithm 1 and Equations 1 to 5), Section 4.2 (estimation of relevance, coverage, novelty, sub-queries and their importance, with the uniform estimator of Equation 6), Section 5 (the TREC 2009 Web track setup, the baselines and the 5-fold training of lambda), Section 6 (Table 2 and Figure 2)
- Rakesh Agrawal, Sreenivas Gollapudi, Alan Halverson and Samuel Ieong, Diversifying search results, Proceedings of the Second ACM International Conference on Web Search and Data Mining (WSDM 2009), 5-14, Section 3 (Equation 1, the coverage objective that the diversity term of xQuAD shares, and Algorithm 1, IA-Select)
- Jaime Carbonell and Jade Goldstein, The use of MMR, diversity-based reranking for reordering documents and producing summaries, Proceedings of the 21st Annual International ACM SIGIR Conference (SIGIR 1998), 335-336, the MMR formula, the implicit method that xQuAD is compared with
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 | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag ZHZBK5 Edit this page History Report an error Markdown