Algorithmresearch
IA-Select
Also called intent-aware select, intent-aware diversification.
Greedily picks documents that maximize the probability that each query intent is satisfied by at least one result; a (1 - 1/e) approximation.
- Time
- O(n log n + n k m) worst
- Space
- O(n + m) extra
- Where
- k = the number of results; m = the number of intents; n = the number of candidate documents
- Model
- Word RAM
- Properties
- deterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Rakesh Agrawal, Sreenivas Gollapudi, Alan Halverson, Samuel Ieong, 2009
IA-Select is a greedy algorithm for search result diversification that builds a result list one document at a time, each time adding the document that most increases the probability that the user finds at least one satisfying result. Rakesh Agrawal, Sreenivas Gollapudi, Alan Halverson and Samuel Ieong introduced it in 2009 with a distribution over the intents (categories) of the query. The objective is submodular, so the Nemhauser, Wolsey and Fisher theorem makes the greedy list at least of the optimum. Unlike maximal marginal relevance, which only compares documents with each other, IA-Select models the intents explicitly; xQuAD uses the same coverage term but mixes it with plain relevance.
In plain words
A short query such as "jaguar" can mean a car, an animal or a football team. A list of ten car pages is perfect for some users and useless for the rest. IA-Select knows roughly how many users mean each thing, and how well each page serves each meaning. It picks the page that helps the most users first. After that, the users who are already served count for less, so the next page is the one that helps most of the users who are still waiting. Repeating this gives a list where popular meanings come first, and a rare meaning gets a page once a page for it would help more of the waiting users than one more page for a popular meaning. The list is never far from the best possible list, and the method can prove how far.
The problem
The input is a query , a set of candidate documents, a set of categories with probabilities that sum to 1, a value for each document and category, and a length . The value is the probability that satisfies a user whose intent is ; it is when does not belong to . The users are assumed to have one intent each, and given the intent, the documents satisfy them independently. The probability that a set satisfies the user is
and the task is to find with that maximizes it. Agrawal et al. prove that this is NP-hard by a reduction from maximum coverage: with uniform and values or , is the fraction of the categories that covers.
The algorithm
IA-Select keeps , the probability that the intent is and no chosen document satisfies it. The gain of a document is the expected number of these still unsatisfied users that it satisfies:
IA-SELECT(D, P, V, k)- 1
for each category c: U(c) ← P(c | q) - 2
S ← empty list - 3
while some document is not in S and |S| < k: - 4
for each d not in S, in id order: - 5
g(d) ← Σ over c of U(c) · V(d | q, c) - 6
b ← the d with the largest g(d), ties to the smaller id; append b to S - 7
for each category c of b: - 8
U(c) ← (1 − V(b | q, c)) · U(c) - 9
return S
The paper calls "the conditional probability" that the intent is given that the documents so far failed, but line L8 does not renormalize it, and the analysis needs the unnormalized form: is a joint probability, and the gain of line L5 is then the exact increase of .
Example
Table 1 of the paper has two equally likely intents and three documents:
| doc | ||
|---|---|---|
| d1 | 0.8 | 0.8 |
| d2 | 1 | 0 |
| d3 | 0 | 1 |
| step | g(d1) | g(d2) | g(d3) | pick | |||
|---|---|---|---|---|---|---|---|
| 1 | 0.5 | 0.5 | 0.8 | 0.5 | 0.5 | d1 | 0.8 |
| 2 | 0.1 | 0.1 | 0.1 | 0.1 | d2 | 0.9 | |
| 3 | 0 | 0.1 | 0.1 | d3 | 1.0 |
For the greedy choice d1 is optimal. For the greedy list d1, d2 has value , while d2 and d3 together reach . So no single ordering is optimal for every , and the greedy result can be below the optimum. The loss here, against , is well inside the bound . Section 3.7 of the paper works a larger example with intents of probability and over ten documents.
Correctness
The file proofs/correctness.md proves the guarantees. Line L8 keeps the invariant , so the gain of line L5 equals . The marginal gain is a sum of products of numbers in , and adding documents only adds factors, so the objective is monotone and submodular, with value on the empty set. The theorem of Nemhauser, Wolsey and Fisher then gives
The paper's Theorem 2 states this for "a submodular set function"; the bound also needs monotonicity and , which this objective has. When each document belongs to only one category, IA-Select is optimal for every (Theorem 1 of the paper). The reduction from maximum coverage and the max coverage inapproximability result mean that no polynomial-time algorithm can guarantee a better constant unless P = NP.
Proof: IA-Select is greedy on a monotone submodular objective, so it is a (1 - 1/e) approximationfull
Let be a finite set of categories (intents) with and , and let be a finite set of documents with values , taken as when is not a category of . Write and for short. For define
the objective of Agrawal et al. (Equation 1 of their paper). The task is to find with that maximizes .
Lemma 1 (invariant). Before each pass of the loop of line L3, with the set of documents chosen so far, for every .
Proof. Line L1 sets , the empty product. Lines L7 and L8 multiply by for the new document and each category of ; for the other categories the factor would be .
So is the probability that the intent is and no chosen document satisfies it. It is not a conditional probability: in the example of the paper, becomes and is not renormalized.
Lemma 2 (the gain is the marginal gain). Line L5 computes .
Proof. For each , adding multiplies the product of by , so the term of grows by by Lemma 1. Summing over the categories of gives line L5.
Lemma 3 (the objective). , is monotone, and is submodular: for and , .
Proof. The empty product is , so . By Lemma 2 the marginal gain at is . Every factor lies in , so the gain is at least , and each product over is the product over times more factors in , so it is no larger.
Agrawal et al. state the theorem of Nemhauser, Wolsey and Fisher (their Theorem 2) for "a submodular set function". The guarantee needs more: the function must also be monotone with . Lemma 3 shows that has both properties, so the conclusion holds here.
Theorem 4 (approximation). If , the set that IA-Select returns satisfies for every with . If , it returns , which is optimal.
Proof. The scan of lines L4 to L6 keeps a document with the largest value of line L5, so by Lemma 2 each pick maximizes the marginal gain over the remaining documents, whatever the tie rule. Let be the first picks and . By monotonicity and submodularity (Lemma 3),
where the middle step adds the elements of one at a time and bounds each gain by its gain at , and the last step uses that has the largest gain (a document of already in has gain ). So . From , . If , every set of at most documents is a subset of , and is the largest value by monotonicity.
The test file checks Theorem 4 against the optimum over all -subsets on random instances.
Theorem 5 (one category per document). If every document has at most one category with a positive value, IA-Select is optimal for every .
Proof. Group the documents by category, and inside category sort them by value, . Taking the -th document of after the first adds , and because and . A set that takes documents from has the value over its documents, which is at most , because the term of grows with each value and is symmetric, so the largest values of maximize it. So is at most the sum of entries of the sequences , taken as prefixes, and since each sequence is non-increasing, at most the sum of the largest entries of all sequences together. IA-Select takes, inside each category, the documents in the order of their values, because the gain has the same for all documents of . So at each step its gain is the largest head among the sequences, and steps of taking the largest head of non-increasing sequences give the largest entries. So reaches the bound.
Agrawal et al. state this result as their Theorem 1 and Corollary 1.
Lemma 6 (hardness). Maximizing under is NP-hard.
Proof. Given an instance of maximum coverage, with ground set and sets , let and if and otherwise. Then is the fraction of covered by , so an optimal for solves the coverage instance.
This is the reduction of Lemma 1 of Agrawal et al. With max coverage inapproximability, no polynomial-time algorithm has a better constant than unless P = NP.
Greedy is not always optimal. Table 1 of the paper: , , , . The first pick is with gain , against for the others. Then , both remaining documents gain , and the tie rule gives , so , while . Here , as Theorem 4 requires.
Cost. Let , and . Each of the passes computes gains in total time and updates at most values, so IA-Select runs in time with extra space.
Complexity
Each of the at most passes computes gains, each a sum over the categories of a document, and updates at most values of . With at most categories per document the time is , including the sort of the ids, and with sparse values it is , where is the number of nonzero values. The extra space is . Lazy evaluation with a priority queue of stale gains, which is valid for any submodular objective, usually cuts the number of gain computations a lot.
Properties
- Explicit. It needs a set of intents, their probabilities and per-intent values, for example from a query classifier and per-intent relevance scores.
- Monotone submodular objective. Every pick has a non-negative gain, and the gain of a document never grows as the list grows.
- Approximation. At least of the optimum for every , and optimal when each document has one category.
- Not a ranking by relevance. Once an intent is well served, its documents drop in gain, so a highly relevant document can fall below a weaker document of another intent. This breaks the assumptions of the probability ranking principle on purpose.
- Deterministic. The tie rule fixes the output.
Variants and improvements
- Intent-aware measures. The same paper defines NDCG-IA, MAP-IA and MRR-IA: a measure is computed for each intent with the judgments of that intent and averaged with the weights . See nDCG and mean reciprocal rank for the base measures, and alpha-nDCG for a related measure of novelty and coverage.
- xQuAD. xQuAD adds the relevance to the same coverage term, with a weight , and takes its aspects from query reformulations.
- Max coverage. With values and , IA-Select is greedy max coverage with weights on the elements.
- Ranked lists. The objective ignores the order inside . For a ranking, one runs the loop with equal to the length of the list and uses the order of the picks, which is what the test collections evaluate.
When to use it
Use IA-Select when you have a taxonomy of intents and a classifier that gives each query a distribution over them, and when you want to maximize the chance that every likely intent finds a good result near the top. If the intents come from query reformulations, or if you want to keep more of the first ranking, xQuAD is the closer fit; if you have no intents at all, MMR needs only a similarity function. The gains reported for IA-Select in the paper and in later comparisons are measurements on particular data sets and intent models.
Pitfalls
- The values must be probabilities. The guarantee and the meaning of need . Raw retrieval scores such as BM25 must be calibrated or normalized first. The implementation rejects values outside the range.
- A bad intent distribution. If is wrong, the algorithm faithfully optimizes the wrong objective. A rare but missing intent gets no document at all.
- Value 1 stops an intent. A document with for an intent sets to 0, and no further document of that intent can gain anything. Clipping values below 1 keeps some redundancy.
- Do not renormalize U. Dividing by its sum after each step looks natural, since the paper calls it a conditional probability, but it changes the gains and loses the link to the objective.
- The bound is on the objective. The guarantee is about under the model, not about measured user satisfaction.
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/ia-select/. The authors are listed in prov/PXB2Y2.jsonl.
"""IA-Select (Agrawal, Gollapudi, Halverson and Ieong, 2009).
The objective of a set S of documents is
P(S | q) = sum over c of P(c | q) * (1 - prod over d in S of (1 - V(d | q, c))),
the probability that at least one document of S satisfies the user, when
the user's intent c is drawn from P(c | q) and the documents satisfy
independently given c. IA-Select adds documents one by one. It keeps
U(c), the probability that intent c is the intent and is not yet
satisfied, starting from P(c | q), and picks the document with the largest
gain sum over c of U(c) V(d | q, c), which is the exact increase of
P(S | q). Ties go to the smaller id.
"""
from itertools import combinations
def objective(selected, p_cat, value):
"""P(S | q) for the documents in selected."""
total = 0.0
for c, p in p_cat.items():
miss = 1.0
for d in selected:
miss *= 1.0 - value[d].get(c, 0.0)
total += p * (1.0 - miss)
return total
def ia_select_steps(docs, p_cat, value, k):
"""Return the list of (document, gain at the time it was picked)."""
for d in docs:
for c, v in value[d].items():
if c not in p_cat or not 0.0 <= v <= 1.0:
raise ValueError("V(d | q, c) must lie in [0, 1] for a known category")
u = dict(p_cat) # @line L1
rest = sorted(set(docs))
chosen = [] # @line L2
while rest and len(chosen) < k: # @line L3
best, best_gain = None, None
for d in rest: # @line L4
gain = sum(u[c] * v for c, v in value[d].items()) # @line L5
if best_gain is None or gain > best_gain: # ties keep the smaller id
best, best_gain = d, gain
chosen.append((best, best_gain)) # @line L6
rest.remove(best)
for c, v in value[best].items(): # @line L7
u[c] *= 1.0 - v # @line L8
return chosen # @line L9
def ia_select(docs, p_cat, value, k):
"""Return the documents that IA-Select picks, in order."""
return [d for d, _ in ia_select_steps(docs, p_cat, value, k)]
def best_subset(docs, p_cat, value, k):
"""The exact optimum over all subsets of size min(k, |docs|), by enumeration."""
size = min(k, len(docs))
best, best_val = (), -1.0
for s in combinations(sorted(docs), size):
v = objective(s, p_cat, value)
if v > best_val:
best, best_val = s, v
return list(best), best_val
test_ia_select.py 109 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ia-select/. The authors are listed in prov/PXB2Y2.jsonl.
import math
import random
import pytest
from ia_select import best_subset, ia_select, ia_select_steps, objective
TOL = 1e-12
RATIO = 1.0 - 1.0 / math.e
# Table 1 of Agrawal et al. (2009): no single ordering is optimal for every k.
P_TABLE1 = {"c1": 0.5, "c2": 0.5}
V_TABLE1 = {1: {"c1": 0.8, "c2": 0.8}, 2: {"c1": 1.0}, 3: {"c2": 1.0}}
def random_instance(rng, n, m, single=False):
weights = [rng.random() + 0.01 for _ in range(m)]
total = sum(weights)
p_cat = {f"c{i}": w / total for i, w in enumerate(weights)}
value = {}
for d in range(1, n + 1):
cats = list(p_cat)
if single:
chosen = [rng.choice(cats)]
else:
chosen = [c for c in cats if rng.random() < 0.6] or [rng.choice(cats)]
value[d] = {c: rng.choice([rng.random(), 1.0, 0.5]) for c in chosen}
return p_cat, value
def test_greedy_is_not_optimal_on_table_1():
docs = [1, 2, 3]
assert ia_select(docs, P_TABLE1, V_TABLE1, 1) == [1]
greedy = ia_select(docs, P_TABLE1, V_TABLE1, 2)
assert greedy == [1, 2]
g = objective(greedy, P_TABLE1, V_TABLE1)
opt, best = best_subset(docs, P_TABLE1, V_TABLE1, 2)
assert opt == [2, 3]
assert math.isclose(g, 0.9, rel_tol=TOL) and math.isclose(best, 1.0, rel_tol=TOL)
assert g >= RATIO * best
def test_gain_is_the_exact_marginal_gain():
rng = random.Random(5)
for _ in range(50):
p_cat, value = random_instance(rng, rng.randint(1, 9), rng.randint(1, 5))
docs = list(value)
prefix = []
for d, gain in ia_select_steps(docs, p_cat, value, len(docs)):
before = objective(prefix, p_cat, value)
prefix.append(d)
assert math.isclose(gain, objective(prefix, p_cat, value) - before, rel_tol=1e-9, abs_tol=1e-12)
# The pick maximizes the marginal gain over the remaining documents.
others = [x for x in docs if x not in prefix]
for x in others:
alt = objective(prefix[:-1] + [x], p_cat, value) - before
assert alt <= gain + 1e-12
@pytest.mark.parametrize("seed", range(150))
def test_at_least_one_minus_one_over_e_of_brute_force(seed):
rng = random.Random(seed)
n = rng.randint(1, 9)
p_cat, value = random_instance(rng, n, rng.randint(1, 5))
docs = list(value)
for k in range(0, n + 1):
greedy = ia_select(docs, p_cat, value, k)
assert len(greedy) == min(k, n) and len(set(greedy)) == len(greedy)
g = objective(greedy, p_cat, value)
_, best = best_subset(docs, p_cat, value, k)
assert g <= best + TOL
assert g >= RATIO * best - TOL
@pytest.mark.parametrize("seed", range(60))
def test_optimal_when_each_document_has_one_category(seed):
rng = random.Random(1000 + seed)
n = rng.randint(1, 9)
p_cat, value = random_instance(rng, n, rng.randint(1, 4), single=True)
docs = list(value)
for k in range(0, n + 1):
g = objective(ia_select(docs, p_cat, value, k), p_cat, value)
_, best = best_subset(docs, p_cat, value, k)
assert math.isclose(g, best, rel_tol=1e-9, abs_tol=TOL)
def test_random_search_finds_non_optimal_instances():
rng = random.Random(42)
gaps = 0
worst = 1.0
for _ in range(300):
p_cat, value = random_instance(rng, 6, 3)
docs = list(value)
g = objective(ia_select(docs, p_cat, value, 2), p_cat, value)
_, best = best_subset(docs, p_cat, value, 2)
if g < best - 1e-9:
gaps += 1
worst = min(worst, g / best)
assert gaps > 0 and worst >= RATIO
def test_rejects_bad_values():
with pytest.raises(ValueError):
ia_select([1], {"c": 1.0}, {1: {"c": 1.5}}, 1)
with pytest.raises(ValueError):
ia_select([1], {"c": 1.0}, {1: {"x": 0.5}}, 1)
History
Agrawal, Gollapudi, Halverson and Ieong presented the problem and IA-Select at WSDM 2009 under the title "Diversifying search results". They framed diversification as maximizing the probability that the average user finds at least one useful result, proved the problem NP-hard, showed that the objective is submodular, and applied the 1978 greedy bound of Nemhauser, Wolsey and Fisher. They also defined intent-aware versions of the standard measures. The paper became a reference point for explicit diversification, and xQuAD in 2010 built on the same coverage term.
References
- 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 objective P(S | q)), Section 3.3 (Lemma 1, NP-hardness from Max Coverage, and the instance of Table 1), Section 3.4 (Lemma 2, submodularity), Section 3.5 (Algorithm 1, IA-Select), Section 3.6 (Theorem 1 and Corollary 1, optimality with one category per document; Theorem 2 and Corollary 2, the (1 - 1/e) bound), Section 3.7 (a worked example), Section 4 (NDCG-IA, MAP-IA and MRR-IA)
- George L. Nemhauser, Laurence A. Wolsey and Marshall L. Fisher, An analysis of approximations for maximizing submodular set functions, I, Mathematical Programming 14, 265-294, 1978, the bound 1 - (1 - 1/k)^k for the greedy algorithm on a monotone submodular function with f of the empty set equal to 0, under the constraint of at most k elements
- 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 (the approach of Agrawal et al. as explicit diversification with a taxonomy), Section 5 (a simulated best case of IA-Select with the official TREC 2009 Web track sub-topics as classes) and Section 6 (Table 2, IA-Select as a baseline)
Where this leads
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 PXB2Y2 Edit this page History Report an error Markdown