Simple Algorithm
Machine Learning · Convergence · 26 min

Semi-Supervised Learning

Cluster, smoothness and manifold assumptions that make unlabeled data useful.

Unlabeled data are cheap, but they carry information about the inputs only, never directly about the labels. Semi-supervised learning works exactly when the shape of P(x)P(\mathbf x) constrains P(y∣x)P(y\mid\mathbf x). This lesson makes that link precise: the assumptions that create it, the algorithms that exploit it, and the theorems that say how much it can and cannot buy.

What you’ll learn

  • State the smoothness, cluster, low-density and manifold assumptions, and prove that with independent priors on P(x)P(\mathbf x) and P(y∣x)P(y\mid\mathbf x) unlabeled data leave the posterior over the classifier unchanged.
  • Derive the harmonic solution of label propagation, fU=−LUU−1LULyL\mathbf f_U=-L_{UU}^{-1}L_{UL}\mathbf y_L, and its random-walk interpretation.
  • Explain transductive SVMs, entropy minimization, pseudo-labeling and consistency regularization (FixMatch) as implementations of low-density separation.
  • State what Castelli & Cover, Blum & Mitchell, Balcan & Blum and Ben-David, Lu & Pál proved about the value of unlabeled data, and where the theory is still open.

When can unlabeled data help at all?

The learner receives ll labeled examples L={(xi,yi)}i=1lL=\{(\mathbf x_i,y_i)\}_{i=1}^{l} and uu unlabeled inputs U={xj}j=l+1l+uU=\{\mathbf x_j\}_{j=l+1}^{l+u}, usually with u≫lu\gg l, all drawn from the same distribution PP. An inductive learner outputs a classifier for any future input; a transductive one only labels the points of UU. Either way, the unlabeled points are samples from the marginal PxP_{\mathbf x} and say nothing about labels by themselves. They can help only if PxP_{\mathbf x} carries information about P(y∣x)P(y\mid\mathbf x), and a two-line Bayesian computation shows exactly what goes wrong when it does not.

DerivationIndependent priors make unlabeled data useless
  1. p(L,U∣θ,ψ)=[∏i∈Lp(yi∣xi,θ)][∏i∈L∪Up(xi∣ψ)]p(L,U\mid\boldsymbol\theta,\boldsymbol\psi)=\Big[\prod_{i\in L}p(y_i\mid\mathbf x_i,\boldsymbol\theta)\Big]\Big[\prod_{i\in L\cup U}p(\mathbf x_i\mid\boldsymbol\psi)\Big]

    Model the inputs with parameters ψ\boldsymbol\psi and the labels given inputs with θ\boldsymbol\theta, so p(x,y)=p(x∣ψ) p(y∣x,θ)p(\mathbf x,y)=p(\mathbf x\mid\boldsymbol\psi)\,p(y\mid\mathbf x,\boldsymbol\theta). The likelihood of all the data factorizes:

  2. p(θ,ψ∣L,U) ∝ [p(θ)∏i∈Lp(yi∣xi,θ)]⋅[p(ψ)∏i∈L∪Up(xi∣ψ)]p(\boldsymbol\theta,\boldsymbol\psi\mid L,U)\ \propto\ \Big[p(\boldsymbol\theta)\prod_{i\in L}p(y_i\mid\mathbf x_i,\boldsymbol\theta)\Big]\cdot\Big[p(\boldsymbol\psi)\prod_{i\in L\cup U}p(\mathbf x_i\mid\boldsymbol\psi)\Big]

    If the prior is independent, p(θ,ψ)=p(θ) p(ψ)p(\boldsymbol\theta,\boldsymbol\psi)=p(\boldsymbol\theta)\,p(\boldsymbol\psi), the posterior splits into a factor in θ\boldsymbol\theta and a factor in ψ\boldsymbol\psi:

  3. p(θ∣L,U)=p(θ∣L)p(\boldsymbol\theta\mid L,U)=p(\boldsymbol\theta\mid L)

    Integrating out ψ\boldsymbol\psi leaves a posterior over the classifier that does not involve UU at all. Every semi-supervised method therefore assumes, explicitly or not, a dependence between PxP_{\mathbf x} and P(y∣x)P(y\mid\mathbf x):

AssumptionWhat it saysMethods that use it
Smoothnesstwo points close together in a high-density region have similar labelsgraph methods, consistency regularization
Clusterpoints in the same cluster tend to share a labelcluster-then-label, mixture models with EM
Low-density separationthe decision boundary passes through regions where p(x)p(\mathbf x) is small (the cluster assumption restated)transductive SVMs, entropy minimization, pseudo-labels
Manifoldthe inputs lie near a low-dimensional manifold, and labels vary smoothly along itLaplacian regularization, manifold regularization
The four assumptions as organized by Chapelle, Schölkopf & Zien (2006). A causal reading by Schölkopf, Janzing, Peters, Sgouritsa, Zhang & Mooij (2012): if x\mathbf x causes yy, the mechanisms PxP_{\mathbf x} and P(y∣x)P(y\mid\mathbf x) are plausibly independent and semi-supervised learning should not help; if yy causes x\mathbf x (a digit's class generates its image), Px=∑yP(y)P(x∣y)P_{\mathbf x}=\sum_yP(y)P(\mathbf x\mid y) does carry information about P(y∣x)P(y\mid\mathbf x). Their meta-analysis of published results was consistent with this hypothesis.
Check your understanding

A model uses a Gaussian mixture with parameters ψ\boldsymbol\psi for p(x)p(\mathbf x) and a separate logistic regression with weights θ\boldsymbol\theta for p(y∣x)p(y\mid\mathbf x), with independent priors on θ\boldsymbol\theta and ψ\boldsymbol\psi. You add 100,000 unlabeled points. What happens to the posterior over θ\boldsymbol\theta?

  1. It concentrates faster, as with more labeled data
  2. It shifts the boundary toward low-density regions of the mixture
  3. Nothing: it equals the posterior given the labeled data alone
  4. It becomes improper, because the unlabeled points have no likelihood under θ\boldsymbol\theta
Show the answer

C. Nothing: it equals the posterior given the labeled data alone

The likelihood and the prior both factorize into a θ\boldsymbol\theta part and a ψ\boldsymbol\psi part, so the unlabeled points only sharpen the posterior over ψ\boldsymbol\psi, which the classifier does not use. To benefit, the model must tie θ\boldsymbol\theta to ψ\boldsymbol\psi, for instance a generative classifier where each mixture component is a class, or a penalty on boundaries through dense regions.

Graphs: label propagation is a harmonic function

Build a weighted graph on all n=l+un=l+u points, for instance with wij=exp⁡(−∥xi−xj∥2/2σ2)w_{ij}=\exp(-\norm{\mathbf x_i-\mathbf x_j}^2/2\sigma^2) for the kk nearest neighbors and 00 otherwise, and let D=diag⁡(d1,…,dn)D=\diag(d_1,\dots,d_n) with di=∑jwijd_i=\sum_jw_{ij}. The graph Laplacian L=D−WL=D-W measures how much a labeling f∈Rn\mathbf f\in\R^n varies across edges. Zhu, Ghahramani & Lafferty (2003) clamp the labeled values, fi=yi∈{0,1}f_i=y_i\in\{0,1\} for i∈Li\in L, and choose the smoothest completion.

DerivationThe harmonic solution
  1. E(f)=12∑i,jwij(fi−fj)2=∑idifi2−∑i,jwijfifj=f⊤(D−W)f=f⊤LfE(\mathbf f)=\tfrac12\sum_{i,j}w_{ij}(f_i-f_j)^2=\sum_id_if_i^2-\sum_{i,j}w_{ij}f_if_j=\mathbf f^\top(D-W)\mathbf f=\mathbf f^\top L\mathbf f

    Expand the sum over ordered pairs; the two squared terms each give ∑idifi2\sum_id_if_i^2:

  2. E=fL⊤LLLfL+2 fU⊤LULfL+fU⊤LUUfU⟹∇fUE=2LULfL+2LUUfUE=\mathbf f_L^\top L_{LL}\mathbf f_L+2\,\mathbf f_U^\top L_{UL}\mathbf f_L+\mathbf f_U^\top L_{UU}\mathbf f_U\quad\Longrightarrow\quad\nabla_{\mathbf f_U}E=2L_{UL}\mathbf f_L+2L_{UU}\mathbf f_U

    Order the points labeled first and split LL into blocks. Only fU\mathbf f_U is free, and the energy is a convex quadratic in it:

  3. fU=−LUU−1LUL yL=(DUU−WUU)−1WUL yL\mathbf f_U=-L_{UU}^{-1}L_{UL}\,\mathbf y_L=(D_{UU}-W_{UU})^{-1}W_{UL}\,\mathbf y_L

    Set the gradient to zero. LUUL_{UU} is positive definite, hence invertible, whenever every connected component of the graph contains a labeled point; and LUL=−WULL_{UL}=-W_{UL} because DD is diagonal:

  4. fi=1di∑jwijfj(i∈U),fi=Pr⁡[the walk from i reaches a label-1 point before a label-0 point]f_i=\frac1{d_i}\sum_jw_{ij}f_j\quad(i\in U),\qquad f_i=\Pr\big[\text{the walk from }i\text{ reaches a label-1 point before a label-0 point}\big]

    Row ii of the optimality condition says each unlabeled value is the weighted average of its neighbors: f\mathbf f is harmonic on UU, so by the maximum principle 0≤fi≤10\le f_i\le1. The hitting probability of a random walk that moves from ii to jj with probability wij/diw_{ij}/d_i satisfies the same equations with the same boundary values, so the two coincide:

Predict before you look

Four points on a path, 1−2−3−41-2-3-4, with unit edge weights. Point 1 is labeled 1 and point 4 is labeled 0. What is the harmonic value f2f_2?

Show the answer

0.67

The harmonic equations are f2=(1+f3)/2f_2=(1+f_3)/2 and f3=(f2+0)/2f_3=(f_2+0)/2, so f2=2/3f_2=2/3 and f3=1/3f_3=1/3: on a path, the harmonic function interpolates linearly. As a random walk, this is gambler's ruin: starting one step from the label-1 end of a path with three steps, the walk reaches that end first with probability 2/32/3.

The graph is where the assumptions live. If no edge crosses the gap between the two moons, each moon is a connected component, and one labeled point per moon labels all of it perfectly, exactly where k-means failed. A few edges across the gap leak label mass between the moons, so the choice of kk or σ\sigma matters as much as the algorithm.

The harmonic solution is transductive. Manifold regularization (Belkin, Niyogi & Sindhwani, 2006) makes it inductive: minimize ∑i∈Lℓ(f(xi),yi)+γA∥f∥K2+γI f⊤Lf\sum_{i\in L}\ell(f(\mathbf x_i),y_i)+\gamma_A\norm{f}_K^2+\gamma_I\,\mathbf f^\top L\mathbf f over a reproducing kernel Hilbert space, where f\mathbf f collects ff at all nn points; a representer theorem reduces it to nn kernel coefficients. One known weakness: with a fixed number of labels and ever more unlabeled points in dimension two or more, the Laplacian penalty on a neighborhood graph can degenerate toward a nearly constant function with sharp spikes at the labeled points, which has motivated higher-order and pp-Laplacian variants.

Low-density separation: TSVMs, entropy and pseudo-labels

Another family puts the decision boundary where the unlabeled points are not. The transductive SVM (Joachims, 1999, building on Vapnik) treats the unknown labels y^j∈{−1,+1}\hat y_j\in\{-1,+1\} of the unlabeled points as variables and maximizes the margin over all points:

min⁡w,b, y^l+1,…,y^l+u 12∥w∥2+C∑i∈L(1−yif(xi))++C∗∑j∈U(1−y^jf(xj))+,f(x)=w⊤x+b\min_{\mathbf w,b,\ \hat y_{l+1},\dots,\hat y_{l+u}}\ \tfrac12\norm{\mathbf w}^2+C\sum_{i\in L}\big(1-y_if(\mathbf x_i)\big)_++C^*\sum_{j\in U}\big(1-\hat y_jf(\mathbf x_j)\big)_+,\qquad f(\mathbf x)=\mathbf w^\top\mathbf x+b
Labels in {−1,+1}\{-1,+1\}, as for every SVM. Minimizing over each y^j\hat y_j gives y^j=sign⁡f(xj)\hat y_j=\sign f(\mathbf x_j), so an unlabeled point costs the non-convex "hat" loss (1−∣f(xj)∣)+(1-\abs{f(\mathbf x_j)})_+: it is penalized for sitting inside the margin whichever side it is on. The problem is combinatorial; Joachims's local search also fixes the fraction of unlabeled points assigned to each class, typically from the labeled class ratio, which rules out the trivial solution of pushing every unlabeled point to one side.

Entropy minimization (Grandvalet & Bengio, 2005) does the same for probabilistic classifiers: add λ∑j∈UH(pθ(⋅∣xj))\lambda\sum_{j\in U}H\big(p_{\boldsymbol\theta}(\cdot\mid\mathbf x_j)\big), the entropy of the predicted class distribution, to the training loss. A boundary through a dense cloud of unlabeled points leaves many of them uncertain and is penalized; a boundary through a gap lets every prediction be confident.

Self-training (pseudo-labeling) is the hard-label version: fit on LL, predict UU, add the confident predictions as labels, refit. Training on its own hard predictions pushes a model toward confident outputs, which is why pseudo-labeling behaves like entropy minimization. Its failure mode is confirmation bias: an early mistake becomes a training label and reinforces itself.

Consistency regularization adds domain knowledge: the prediction should not change under perturbations that preserve the label, such as crops, flips and color changes of an image. FixMatch (Sohn et al., 2020) combines the two ideas. For each unlabeled image ubu_b in a batch, a weakly augmented copy α(ub)\alpha(u_b) gives a prediction qbq_b; if its top probability clears a threshold τ\tau, the hard label q^b=arg max⁡qb\hat q_b=\argmax q_b becomes the target for a strongly augmented copy A(ub)\mathcal A(u_b):

ℓu=1μB∑b=1μB1{max⁡qb≥τ}  H(q^b, pθ(y∣A(ub))),total loss  ℓs+λuℓu\ell_u=\frac1{\mu B}\sum_{b=1}^{\mu B}\mathbf 1\big\{\max q_b\ge\tau\big\}\;H\big(\hat q_b,\ p_{\boldsymbol\theta}(y\mid\mathcal A(u_b))\big),\qquad\text{total loss }\ \ell_s+\lambda_u\ell_u
HH is the cross-entropy, ℓs\ell_s the supervised loss on a labeled batch of size BB, and μB\mu B the number of unlabeled images per batch. The paper used τ=0.95\tau=0.95, λu=1\lambda_u=1 and μ=7\mu=7, and reported 94.93% accuracy on CIFAR-10 with 250 labels and 88.61% with 40 labels, four per class.
Think first Why does adding the entropy of the predictions on unlabeled points to the loss push a classifier's decision boundary into low-density regions, and what stops it from simply predicting one class everywhere?

Predicted probabilities pass through 12\tfrac12 at the boundary, so unlabeled points near it have high entropy. With the scale of the weights held in check, by weight decay as in practice, the penalty is smallest when few unlabeled points lie near the boundary, that is, when the boundary runs through a gap. The check matters: without it, scaling up the weights would make every prediction confident wherever the boundary lies, so the norm penalty is what turns "confident" into "far from the boundary," as the margin does for the transductive SVM. Predicting one class everywhere would also be confident, but the labeled loss forbids it, which is why entropy minimization needs labeled data and, in practice, a class-balance term. The cluster assumption is what makes the gap the right place for the boundary.

What theory says unlabeled data are worth

That is the optimistic case: the model is right. When it is wrong, unlabeled data can hurt. Cozman, Cohen & Cirelo (2003) showed that semi-supervised maximum likelihood for mixture models can end up with higher classification error than the labeled data alone, even in settings where more labeled data would lower it: thousands of unlabeled points dominate the likelihood, and a misspecified model fits them at the expense of the boundary.

A PAC model for assumptions. Balcan & Blum (2010) formalize an assumption as a compatibility function χ(h,x)∈[0,1]\chi(h,\mathbf x)\in[0,1]: the margin of hh at x\mathbf x for low-density separation, agreement of the two views for co-training. The unlabeled error 1−Ex[χ(h,x)]1-\E_{\mathbf x}[\chi(h,\mathbf x)] can be estimated from unlabeled data alone, so unlabeled data shrink the search to the hypotheses that are nearly compatible. If the target is compatible, the number of labeled examples then scales with the complexity of that compatible subclass instead of the whole class H\mathcal H, while the number of unlabeled examples scales with H\mathcal H and χ\chi.

Without an assumption. Ben-David, Lu & Pál (2008) gave the learner more than any unlabeled sample can: exact knowledge of PxP_{\mathbf x}. For thresholds on the real line in the realizable case, with any absolutely continuous PxP_{\mathbf x}, supervised ERM needs at most ln⁡(1/δ)/ε\ln(1/\delta)/\varepsilon labels, and no semi-supervised algorithm can get by with fewer than about half as many: knowing PxP_{\mathbf x} is worth at most a factor of about 2. In the agnostic case, for thresholds and for unions of dd intervals, the semi-supervised sample complexity is of the same order as the supervised one, Θ((2d+ln⁡(1/δ))/ε2)\Theta\big((2d+\ln(1/\delta))/\varepsilon^2\big) for the intervals. They conjectured a constant-factor gap for every class. Darnstädt, Simon & Szörényi (2013) showed the conjecture fails in general: the gap can be arbitrarily large for classes of infinite VC dimension, while for finite classes containing both constant functions it is at most of order ln⁡∣H∣\ln\abs{\mathcal H}.

Key takeaways

  • Unlabeled data reveal only PxP_{\mathbf x}. With independent priors on PxP_{\mathbf x} and P(y∣x)P(y\mid\mathbf x), the posterior over the classifier ignores them; every method relies on a link such as smoothness, clusters, low-density separation or a manifold, plausibly present when yy causes x\mathbf x.
  • Label propagation minimizes f⊤Lf\mathbf f^\top L\mathbf f with the labels clamped. The harmonic solution fU=−LUU−1LULyL\mathbf f_U=-L_{UU}^{-1}L_{UL}\mathbf y_L averages neighbors and equals a random walk's probability of reaching a label-1 point first.
  • Transductive SVMs, entropy minimization, pseudo-labels and consistency regularization (FixMatch: confident weak-augmentation labels as targets for strong augmentations) all push the boundary into low-density regions.
  • With a correct, identifiable mixture, labels are exponentially valuable once unlabeled data have found the regions (Castelli–Cover); with a wrong one, unlabeled data can hurt. Without assumptions, knowing PxP_{\mathbf x} buys at most a constant factor for thresholds (Ben-David–Lu–Pál), though not for every class.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

In label propagation with the harmonic solution, what is the value fif_i of an unlabeled point?

  1. The label of the nearest labeled point
  2. The weighted average of its neighbors' values, equal to the probability that a random walk from ii hits a label-1 point before a label-0 point
  3. The majority label among its kk nearest neighbors in the input space
  4. 12\tfrac12 until enough labeled points are nearby
Show the answer

B. The weighted average of its neighbors' values, equal to the probability that a random walk from ii hits a label-1 point before a label-0 point

Minimizing f⊤Lf\mathbf f^\top L\mathbf f with clamped labels gives LUUfU=WULyLL_{UU}\mathbf f_U=W_{UL}\mathbf y_L, whose rows say fi=∑jwijfj/dif_i=\sum_jw_{ij}f_j/d_i. Random-walk hitting probabilities solve the same equations with the same boundary values, so they are equal. Values flow along the graph, so a point far from every label in input space can still be confidently labeled if a dense path connects it to one.

Question 2

Ben-David, Lu & Pál (2008) let a semi-supervised learner know the input distribution PxP_{\mathbf x} exactly. For thresholds on the line in the realizable case, with PxP_{\mathbf x} absolutely continuous, what did they prove?

  1. Exact knowledge of PxP_{\mathbf x} reduces the labels needed from order 1/ε1/\varepsilon to order log⁡(1/ε)\log(1/\varepsilon)
  2. Knowing PxP_{\mathbf x} saves at most a factor of about 2 in labeled examples
  3. Knowing PxP_{\mathbf x} never helps at all, by any factor
  4. Semi-supervised learning is impossible for thresholds
Show the answer

B. Knowing PxP_{\mathbf x} saves at most a factor of about 2 in labeled examples

Supervised ERM needs at most ln⁡(1/δ)/ε\ln(1/\delta)/\varepsilon labels, while any semi-supervised algorithm needs about ln⁡(1/δ)/(2ε)\ln(1/\delta)/(2\varepsilon). Since any absolutely continuous distribution can be stretched into the uniform one, knowing its shape carries no label information; only an assumption tying labels to PxP_{\mathbf x} can buy more.

Question 3

A generative classifier (one Gaussian per class) is fitted by EM to 100 labeled and 100,000 unlabeled points. The true class densities are far from Gaussian. What can happen to its test error compared with fitting on the 100 labeled points alone?

  1. It can increase: the unlabeled points dominate the likelihood and pull a misspecified model away from a good boundary
  2. It must decrease, because more data always reduce variance
  3. It stays the same, because unlabeled points carry no information
  4. It converges to the Bayes error, by the Castelli–Cover theorem
Show the answer

A. It can increase: the unlabeled points dominate the likelihood and pull a misspecified model away from a good boundary

Cozman, Cohen & Cirelo (2003) showed exactly this: with a wrong model, semi-supervised maximum likelihood can be worse than supervised training. The likelihood rewards fitting the shape of PxP_{\mathbf x}, and with 1,000 times more unlabeled points, the fit to the inputs overrides the fit to the boundary.

Question 4

Which assumption lets co-training boost a weakly useful view-1 classifier into an accurate view-2 classifier using unlabeled data alone?

  1. The two views are uncorrelated
  2. View 1 is more informative than view 2
  3. The data are linearly separable in the concatenated views
  4. Each view suffices to predict the label, and the views are conditionally independent given the label
Show the answer

D. Each view suffices to predict the label, and the views are conditionally independent given the label

Conditional independence makes the view-1 classifier's mistakes, seen from view 2, depend on the true class only, a form of random classification noise; a noise-tolerant learner for view 2 then recovers the target. Real views are rarely conditionally independent, and later work studied weaker conditions.

Further reading

  • O. Chapelle, B. Schölkopf & A. Zien (eds.), Semi-Supervised Learning (MIT Press, 2006).
  • X. Zhu, Z. Ghahramani & J. Lafferty, "Semi-supervised learning using Gaussian fields and harmonic functions," Proceedings of ICML, 912–919 (2003).
  • S. Ben-David, T. Lu & D. Pál, "Does unlabeled data provably help? Worst-case analysis of the sample complexity of semi-supervised learning," Proceedings of COLT, 33–44 (2008).
  • K. Sohn, D. Berthelot, C.-L. Li, Z. Zhang, N. Carlini, E. D. Cubuk, A. Kurakin, H. Zhang & C. Raffel, "FixMatch: simplifying semi-supervised learning with consistency and confidence," NeurIPS (2020).
  • J. E. van Engelen & H. H. Hoos, "A survey on semi-supervised learning," Machine Learning 109, 373–440 (2020).