AI Wiki中文/EN

Active learning: choose which label to buy

主动学习

Identify a hidden threshold with three queries, compare exact random-query cost and expose a noisy-label failure.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Spend the next label where it can resolve a question

A model has seven unlabeled items but a budget for only three annotations. Active learning chooses which item to ask about next, using labels already obtained. The aim is useful prediction at lower labeling cost, not simply making the model ask questions.

Pool-based methods choose from available inputs; stream-based methods decide whether to label an arriving input; query synthesis can request a constructed input. Settles’s survey, Sections 2–3, describes these settings and query strategies. Our example uses a fixed pool and a deterministic labeling oracle. No network or human service is called by the program.

Keep hypotheses that agree with the answers

Consider points x=1,…,n and possible thresholds θ=1,…,n+1. A threshold predicts h_θ(x)=1 when x≥θ and 0 otherwise. Start with every threshold possible. After querying x and receiving label y, update the version space:

Vt+1={θ∈Vt:hθ(xt)=yt},hθ(x)=1{x≥θ}.V_{t+1}=\{\theta\in V_t:h_\theta(x_t)=y_t\},\qquad h_\theta(x)=\mathbf1\{x\geq\theta\}.

This exact elimination requires realizability: a true threshold exists in the candidate set and every answer matches it. A noisy answer can eliminate the truth. The remaining candidates stay contiguous, so asking near their middle divides them as evenly as possible.

For n=7 there are eight possible thresholds. Ask x=4 first: label 0 leaves thresholds 5–8, while label 1 leaves 1–4. Each subsequent balanced query halves the surviving possibilities. Three labels identify every threshold. More generally:

Bbalanced≤⌈log⁡2(n+1)⌉,2B≥n+1 for any decision tree that identifies all thresholds.B_{\mathrm{balanced}}\leq\lceil\log_2(n+1)\rceil, \qquad 2^B\geq n+1\ \text{for any decision tree that identifies all thresholds}.

The lower bound counts the at most 2ᴮ possible binary answer transcripts at depth B. Balanced threshold queries attain that worst-case bound. This is exact identification in a finite, noiseless class; it is not a general bound for neural-network training or population prediction error. Hanneke’s 2014 survey, introduction, distinguishes labeling protocols, label complexity and guarantees under specified learning conditions.

What does a random-label baseline cost?

For comparison, choose each next point uniformly from the unqueried pool and stop once only one threshold remains. Assume a uniform prior over the eight thresholds. The program computes this policy’s exact mean cost, not a noisy Monte Carlo estimate.

For a state with candidate set V and remaining pool P, let Vₓ,ᵧ be candidates giving answer y at x. Its expected remaining query count satisfies:

E(V,P)=1+1∣P∣∑x∈P∑y:Vx,y≠∅∣Vx,y∣∣V∣E(Vx,y,P∖{x}),E(V,P)=0 if ∣V∣=1.E(V,P)=1+\frac1{|P|}\sum_{x\in P}\sum_{y:V_{x,y}\ne\varnothing} \frac{|V_{x,y}|}{|V|}E(V_{x,y},P\setminus\{x\}),\qquad E(V,P)=0\text{ if }|V|=1.

The leading one pays for the next label. The two averages account for a random query and its answer under the current uniform posterior. For n=7 the result is 5 labels on average, versus 3 for balanced querying. Different priors, costs or goals change this comparison.

Let the selector see answers, not the hidden threshold

This complete Python 3.12 program passes only the chosen input to the oracle. The demonstration supplies synthetic oracles for all eight possible truths and checks every final answer. The selector cannot read the threshold parameter from its own arguments; it uses only the oracle’s returned labels.

from fractions import Fraction as F
from functools import lru_cache


def pool_size(n):
    if type(n) is not int or not 1<=n<=9:
        raise ValueError('integer pool size from one to nine required')


def identify_threshold(n, oracle, budget=None):
    pool_size(n)
    if not callable(oracle):raise ValueError('a callable labeling oracle required')
    if budget is None:budget=n
    if type(budget) is not int or not 0<=budget<=n:
        raise ValueError('integer query budget from zero to pool size required')
    version=tuple(range(1,n+2));pool=list(range(1,n+1));trace=[]
    while len(version)>1 and len(trace)<budget:
        x=min(pool,key=lambda point:(abs(2*sum(point>=t for t in version)-len(version)),point))
        label=oracle(x)
        if type(label) is not int or label not in (0,1):raise ValueError('oracle must return integer zero or one')
        version=tuple(t for t in version if int(x>=t)==label)
        pool.remove(x);trace.append((x,label,len(version)))
    return version,trace,len(version)==1


def random_query_expectation(n):
    pool_size(n)
    @lru_cache(None)
    def expected(version,pool):
        if len(version)==1:return F(0)
        result=F(1)
        for x in pool:
            remaining=tuple(v for v in pool if v!=x)
            for label in (0,1):
                child=tuple(t for t in version if int(x>=t)==label)
                if child:result+=F(len(child),len(version)*len(pool))*expected(child,remaining)
        return result
    return expected(tuple(range(1,n+2)),tuple(range(1,n+1)))


if __name__=='__main__':
    n=7;costs=[]
    for truth in range(1,n+2):
        version,trace,done=identify_threshold(n,lambda x,t=truth:int(x>=t))
        costs.append(len(trace))
        if truth==5:print('threshold5 trace (query,label,candidates):',trace)
        if not done or version!=(truth,):raise AssertionError('incorrect noiseless identification')
    print('active costs for all eight thresholds:',costs)
    print('active uniform-prior mean:',F(sum(costs),len(costs)))
    print('random-without-replacement exact mean:',random_query_expectation(n))
    version,trace,done=identify_threshold(n,lambda x:int(x>=5),budget=1)
    print('one-query remaining thresholds:',version,'identified:',done)

Output:

threshold5 trace (query,label,candidates): [(4, 0, 4), (6, 1, 2), (5, 1, 1)]
active costs for all eight thresholds: [3, 3, 3, 3, 3, 3, 3, 3]
active uniform-prior mean: 3
random-without-replacement exact mean: 5
one-query remaining thresholds: (5, 6, 7, 8) identified: False

Each trace entry records the query, its observed label and the number of surviving candidates. With truth 5, the queries are 4,6,5. A one-query budget leaves four candidates and reports identified=False; it does not invent a finished answer.

Scoring every available query against every candidate takes O(n²) work per selection in this simple implementation, with O(n) state storage excluding traces. A threshold-specific binary search is more efficient. The exact random-policy evaluator memoizes subset states and can grow exponentially with pool size; the API caps n at 9. It is a small validation instrument, not a scalable active-learning library.

Model uncertainty can point to the wrong example

In this example, uniform committee votes yield a class probability equal to the fraction of surviving thresholds predicting 1. A balanced split is therefore also closest to probability 1/2. General uncertainty sampling often asks where a fitted classifier is least certain, but its scores may be miscalibrated, and ambiguous noise may be expensive without improving the decision boundary.

Query-by-committee, expected error reduction, diversity and cost-sensitive strategies address different concerns. Settles, Sections 3.1–3.2 and 6, discusses uncertainty, disagreement, noisy oracles and variable annotation costs. A heuristic’s failure should not be confused with a limit on every possible active protocol.

The returned identified flag means a single hypothesis remains under the noiseless model. A wrong label can still produce a confident but wrong singleton. This code has no noise model or repeated-label mechanism. Likewise, exact identification on this pool says nothing about inputs outside the specified threshold domain.

Actively selected labels are not an IID test set from the deployment population. Keep an independent evaluation set, compare at equal annotation cost, and record acquisition and retraining time. In batch querying, several individually uncertain items may be redundant. Annotation guidelines, abstentions and disagreements belong in the data pipeline.

Count information and count costs

  1. Which query is chosen first with seven points?

Answer 1: x=4, splitting eight thresholds into two groups of four.

  1. Why can two binary answers not identify all eight thresholds?

Answer 2: They produce at most four transcripts, fewer than eight possibilities.

  1. What is the random baseline’s exact mean query count under the stated prior?

Answer 3: Five; balanced selection uses three for each threshold.

  1. Does a singleton version space prove the labels were correct?

Answer 4: No. A noisy answer can remove the truth and leave an incorrect singleton.

Compare acquisition rules under the same budget

Project: flip the first oracle answer, then allow subsequent answers to be correct. Inspect whether the method can still return identified=True for a wrong threshold. Next, assign different costs to points and compare expected cost, not just query count. A balanced split need not be the cheapest question.

For larger models, compare an uncertainty selector, a diversity-aware selector and random acquisition across several initial label sets. Preserve a held-out evaluation set and report variance across runs. Semi-supervised learning uses unlabeled structure without necessarily requesting labels; Bayesian decision theory frames the value of additional information relative to losses and costs.

Make a prediction, then check

What does identified=True actually establish in this code?

Choose one answer

Learning objectives

  • Update a finite version space using queried labels.
  • Prove a noiseless threshold query bound and compare exact costs.
  • Explain noisy-label failure and independent evaluation.

Prerequisites & connections

Explore related knowledge →

References

  1. Active Learning Literature Survey — updated January26,2010
    Burr Settles · 2010
  2. Theory of Active Learning — Version1.1, September22,2014
    Steve Hanneke · 2014

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter. Graph scores use analytic references; KM and random-query expectations use exact fractions; ranking gradients use literal and finite-difference checks. No NumPy dependency in these examples.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

  • Active Learning Literature Survey — updated January26,2010 · UpdatedJanuary26,2010 PDF, Sections2,3.1–3.2,6.2–6.3,6.6–6.7,7.1: query settings, uncertainty/committee strategies, selected-data bias, stopping and semi-supervised distinction. Finite exact-cost calculation is original.
  • Theory of Active Learning — Version1.1, September22,2014 · Author-linked226-page Version1.1 datedSeptember22,2014; actually read cover, introduction pp1–4: pool-based labeling protocol, label complexity, distinction between empirical heuristic failures and theoretical capabilities. No full-book proof review claimed.

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.