AI Wiki中文/EN

Semi-supervised learning: when unlabeled data helps

半监督学习

Solve a labeled chain, add a misleading edge and separate graph convergence from classification quality.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Unlabeled examples supply structure, not answers

You know the category of two documents, but have many more documents without labels. Their similarities might show where a category continues. They do not tell you, by themselves, which similarities matter for that category.

Semi-supervised learning uses labeled and unlabeled training examples together. Graph propagation is one approach; pseudo-labeling, consistency regularization and generative models make other assumptions. In contrast, active learning requests additional labels. Settles’s survey, Section 7.1, discusses the distinction and possible combinations.

Our laboratory is a five-node chain 0–1–2–3–4. Only node 0’s label 0 and node 4’s label 1 are revealed. Hidden labels at nodes 1,2,3 will be used only for evaluation, never for propagation. Read supervised learning and linear systems first.

Smooth labels along a specified graph

Let W be a symmetric nonnegative similarity matrix with zero diagonal, and fᵢ a soft class 1 score. Keep labeled scores fixed. On unlabeled nodes, minimize the graph energy:

E(f)=12∑i,jWij(fi−fj)2,fi=yi(i∈L).E(f)=\frac12\sum_{i,j}W_{ij}(f_i-f_j)^2, \qquad f_i=y_i\quad(i\in L).

Differentiating with respect to an unconstrained fᵢ gives a weighted-average equation. Writing Dᵢᵢ=ΣⱼWᵢⱼ, G=D−W, and partitioning indices into unlabeled U and labeled L:

fi=∑jWijfjDii,GUUfU=WULyL.f_i=\frac{\sum_j W_{ij}f_j}{D_{ii}},\qquad G_{UU}f_U=W_{UL}y_L.

Every connected component must touch a labeled node to identify all unlabeled scores uniquely. To see why, a zero-energy difference between two solutions must be constant along every positive-weight edge and zero at labeled nodes. Connectivity then forces that difference to vanish. An entirely unlabeled component has an arbitrary constant solution instead.

A synchronous iterative method repeatedly averages old neighboring scores and restores known labels:

fU(t+1)=PUUfU(t)+PULyL,P=D−1W.f_U^{(t+1)}=P_{UU}f_U^{(t)}+P_{UL}y_L, \qquad P=D^{-1}W.

Here P is used only on positive-degree unlabeled rows. With the component condition, a random walk can reach a labeled node from every unlabeled node. In a finite graph, repeated blocks of steps retain at most a fixed fraction of unlabeled mass; consequently the powers of P_UU tend to zero and the iteration converges. A small one-step change is a stopping criterion, not a classification guarantee.

Zhu and Ghahramani’s June 2002 report, Sections 2.1–2.3, describes propagation with label clamping and a fixed-point system. Its original fully connected positive-weight construction differs from our sparse graph; the component argument above supplies the condition needed here. The report’s matrix orientation and normalization should not be copied without checking their convention.

A chain and a misleading shortcut

Unit chain weights give scores(0,1/4,1/2,3/4,1). Each interior value is the mean of its neighbors. Classify a score strictly above 1/2 as class 1, breaking a tie toward class 0. For hidden labels(0,0,1), all three predictions are correct.

Now add an edge of weight 10 between nodes 0 and 3. Solving the same equations gives interior scores(1/34,1/17,3/34), all below 1/2. Node 3 is misclassified. More connectivity made the assumed geometry worse for the task. A baseline that uses positions 0 through 4 and the nearest labeled endpoint, with midpoint ties toward 0, makes no errors here.

Clamp labels and check graph reachability

The complete Python 3.12 program performs actual synchronous averaging. It validates the component condition before iteration. No hidden labels enter the solver; the small list in the demonstration only scores its predictions afterward.

from math import isfinite


def propagate(weights, labels, tol=1e-12, max_steps=5000):
    w=[list(row) for row in weights];n=len(w)
    if not 1<=n<=32 or any(len(row)!=n for row in w):
        raise ValueError('a square matrix with one to32 nodes required')
    if any(type(v) not in (int,float) or not isfinite(v) or not 0<=v<=10000 for row in w for v in row):
        raise ValueError('finite nonnegative weights at most10000 required')
    if any(w[i][i]!=0 or any(w[i][j]!=w[j][i] for j in range(n)) for i in range(n)):
        raise ValueError('symmetric weights and zero diagonal required')
    if type(labels) is not dict or not labels or any(type(i) is not int or not 0<=i<n or type(v) is not int or v not in (0,1) for i,v in labels.items()):
        raise ValueError('known binary labels keyed by node index required')
    if type(tol) not in (int,float) or not isfinite(tol) or not 1e-14<=tol<=1e-3 or type(max_steps) is not int or not 1<=max_steps<=5000:
        raise ValueError('bounded tolerance and sweep budget required')
    reached=set(labels);stack=list(labels)
    while stack:
        i=stack.pop()
        for j in range(n):
            if w[i][j]>0 and j not in reached:reached.add(j);stack.append(j)
    if len(reached)!=n:raise ValueError('every component must contain a labeled node')
    f=[float(labels.get(i,.5)) for i in range(n)];degree=list(map(sum,w))
    for step in range(max_steps):
        new=[float(labels[i]) if i in labels else sum(w[i][j]*f[j] for j in range(n))/degree[i] for i in range(n)]
        residual=max(abs(a-b) for a,b in zip(new,f));f=new
        if residual<=tol:return f,True,step+1,residual
    return f,False,max_steps,residual


def chain(shortcut=0):
    w=[[0]*5 for _ in range(5)]
    for i in range(4):w[i][i+1]=w[i+1][i]=1
    w[0][3]=w[3][0]=shortcut
    return w


if __name__=='__main__':
    for name,w in [('chain',chain()),('misleading shortcut',chain(10))]:
        f,done,steps,residual=propagate(w,{0:0,4:1})
        predicted=[int(v>.5) for v in f[1:4]]
        print(name,'scores:',*[f'{v:.12f}' for v in f])
        print('unlabeled predictions:',predicted,'errors:',sum(a!=b for a,b in zip(predicted,[0,0,1])))
        print('converged:',done,'sweeps:',steps,'residual:',f'{residual:.3g}')
    known={0:0,4:1}
    baseline=[known[min(known,key=lambda j:(abs(i-j),j))] for i in (1,2,3)]
    print('nearest labeled endpoint baseline errors:',sum(a!=b for a,b in zip(baseline,[0,0,1])))

Output:

chain scores: 0.000000000000 0.250000000000 0.500000000000 0.750000000000 1.000000000000
unlabeled predictions: [0, 0, 1] errors: 0
converged: True sweeps: 2 residual: 0
misleading shortcut scores: 0.000000000000 0.029411764706 0.058823529413 0.088235294118 1.000000000000
unlabeled predictions: [0, 0, 0] errors: 1
converged: True sweeps: 45 residual: 9.05e-13
nearest labeled endpoint baseline errors: 0

The algorithm reports whether it met its tolerance within 5000 sweeps. The dense representation uses O(n²) memory; validation and each sweep use O(n²) work. Sparse adjacency lists can reduce a sweep to O(number of edges). A direct solve of the unlabeled system is another option. Constructing a useful graph is a separate cost and modeling task.

The printed baseline is the stated nearest-endpoint rule evaluated on the three fixed positions; it is not an independently trained document model. Tests also verify the analytic score vectors and preserve the labeled endpoints.

The graph is a substantive assumption

Unlabeled inputs describe a marginal input distribution. Without a relationship between that distribution and the label mechanism, they need not improve a supervised prediction. A cluster can reflect document length, source or formatting instead of the intended topic. A wrongly clamped label can spread its error.

These graph scores are harmonic interpolation values, not automatically calibrated posterior probabilities. The 1/2 decision rule assumes the chosen binary interpretation; different loss functions may require another decision policy. The code solves a transductive problem on the supplied graph. Predicting a genuinely new node requires a stated extension rule or another fit.

Do not select graph parameters using hidden test labels. A transductive protocol may allow the unlabeled test inputs to be in the graph, but that must be declared and compared with the same protocol for baselines. In an inductive evaluation, leave test inputs out of training construction. Label scarcity, label errors and distribution shift should be varied independently.

What did the unlabeled data add?

  1. Why must known labels be restored after averaging?

Answer 1: They are the fixed boundary conditions. Letting them drift changes the problem.

  1. What is node 3’s score after adding the weight 10 shortcut?

Answer 2: 3/34, below the class 1 threshold despite its hidden label being 1.

  1. What fails in a component with no labeled node?

Answer 3: Its constant score is not identified by the energy; the code rejects that input.

  1. Does a converged graph solution prove that unlabeled data helped?

Answer 4: No. The misleading graph converges but performs worse than the stated supervised baseline.

Compare assumptions at a fixed label budget

Project: vary the shortcut weight, the number of revealed labels and which endpoint label is corrupted. Compare the graph method with the same nearest-label baseline. Report label budget, graph construction, evaluation protocol and error, keeping numerical convergence separate from prediction quality.

Self-training replaces some missing labels with model predictions; consistency methods ask related input views to produce compatible outputs. Both need assumptions about reliable predictions or label-preserving transformations. Graph methods make the corresponding smoothness assumption particularly visible. Continue with spectral clustering for another use of graph geometry and active learning for choosing which missing label to purchase.

Make a prediction, then check

Does propagation convergence certify useful unlabeled data?

Choose one answer

Learning objectives

  • Derive the clamped graph fixed-point equations.
  • Explain the component condition and transductive scope.
  • Demonstrate failure when graph similarity is misleading.

Prerequisites & connections

Explore related knowledge →

References

  1. Learning from Labeled and Unlabeled Data with Label Propagation
    Xiaojin Zhu; Zoubin Ghahramani · 2002
  2. Active Learning Literature Survey — updated January26,2010
    Burr Settles · 2010

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:

Related topics

No matches. Try a synonym or acronym.

0 results shown

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