Foundations

Semi-Supervised Learning With a Few Labels and Many Examples

Learn how pseudo-labels, label propagation and consistency training use unlabeled data, when they help and how to test them honestly.

Key takeaways

  • Semi-supervised methods rely on an assumption linking the shape of the input data to the labels.
  • Self-training, graph-based propagation and consistency regularization are three common strategies.
  • A model that trusts its own wrong guesses can reinforce them, so filter pseudo-labels and monitor them by class.
  • Evaluate on labeled data that played no part in training, and compare against a well-tuned supervised baseline.
  • Labeling a few more well-chosen examples is often a strong alternative.

Semi-supervised learning trains a model using a small set of labeled examples together with a much larger set of unlabeled ones. The unlabeled data shows where inputs tend to lie and how they cluster. If that structure lines up with the labels, the model can draw a better boundary than the few labels alone would support.

The condition in that last sentence is the whole story. When it holds, gains can be large. When it fails, unlabeled data can make a model worse.

The assumptions underneath

Unlabeled inputs tell you about the distribution of x. They tell you about y only if you assume a connection. The usual versions are these.

  • Smoothness: points that are close in a dense region tend to share a label.
  • Cluster: data forms groups, and a decision boundary should pass through sparse gaps between them.
  • Manifold: high-dimensional data lies near a lower-dimensional surface, and distance along that surface is meaningful. See the manifold hypothesis.

Picture two crescent-shaped bands that interlock. With one labeled point on each, a straight line drawn halfway between them cuts through both crescents. Following the chain of neighbors along each band gets almost every point right.

Now picture groups that reflect something unrelated to your target, such as photos clustering by lighting when you want to identify species. The same methods will confidently spread labels along the wrong structure.

Self-training and pseudo-labels

Self-training is the simplest recipe. A pseudo-label is a label that the model itself assigned.

  1. Train a model on the labeled examples.
  2. Predict on the unlabeled pool.
  3. Keep predictions whose confidence passes a threshold, and treat them as labels.
  4. Retrain on real and pseudo-labels together.
  5. Repeat until little changes or validation stops improving.
The self-training loop
Check Measure on held-out real labels. Filter Keep only confident, balanced picks. Train Fit on real labels plus accepted pseudo-labels. Predict Score the unlabeled pool. 1 2 3 4 Train Fit on real labels plus accepted pseudo-labels. 1 Predict Score the unlabeled pool. 2 Filter Keep only confident, balanced picks. 3 Check Measure on held-out real labels. 4

The main danger is confirmation bias: an early error becomes a training label, which makes the model surer of the same error. Confidence is not correctness, particularly for neural networks, whose softmax outputs are often overconfident. Helpful guards include a high threshold, a cap per class so easy classes do not take over, down-weighting pseudo-labels in the loss, and recomputing them each round so mistakes can be reversed.

Choosing the confidence threshold

The threshold in self-training trades quantity against purity. A threshold of 0.99 admits few pseudo-labels, mostly easy ones that resemble what the model already knows. A threshold of 0.6 admits many, with more errors among them.

You can estimate the trade directly. On labeled validation data, count how many predictions pass each threshold and what share of those are correct. Say 40 percent of cases pass at 0.95 and 98 percent of them are right, while 70 percent pass at 0.80 and 90 percent are right. Applied to 10,000 unlabeled examples, and assuming the pool resembles the validation set, the strict setting would add about 4,000 labels with roughly 80 errors. The loose one would add about 7,000 with roughly 700.

Which is better depends on how robust your model is to label noise, so try both. Also break the figures down by class. A threshold that works for the common class may admit almost nothing from a rare one, and repeating the loop then makes the imbalance steadily worse. Per-class thresholds or per-class quotas counter this.

Spreading labels through a graph

Another approach connects each example to its nearest neighbors and lets labels flow along the edges. In a basic version, every unlabeled node takes the average of its neighbors' scores, repeatedly, while labeled nodes stay fixed.

Take a chain A, B, C, D. A is labeled 1, D is labeled 0, and B and C are unknown.

B = (A + C) / 2 = (1 + C) / 2
C = (B + D) / 2 = B / 2
so B = 1/2 + B/4  →  B = 2/3
and C = 1/3

B leans toward class 1 because it sits nearer A, and C leans toward 0. The quality of the graph decides everything, so the choice of features and distance matters more than the propagation rule. Large graphs need approximate neighbor search.

Try it on two moons

This script gives each method 10 labels out of 400 pool points and tests on 200 others.

import numpy as np
from sklearn.datasets import make_moons
from sklearn.linear_model import LogisticRegression
from sklearn.semi_supervised import LabelSpreading

X, y = make_moons(n_samples=600, noise=0.08, random_state=0)
X_pool, y_pool = X[:400], y[:400]   # shapes (400, 2), (400,)
X_test, y_test = X[400:], y[400:]

for seed in range(5):
    rng = np.random.default_rng(seed)
    labeled = np.concatenate([
        rng.choice(np.where(y_pool == c)[0], 5, replace=False)
        for c in (0, 1)])
    y_partial = np.full(len(y_pool), -1)   # -1 means unlabeled
    y_partial[labeled] = y_pool[labeled]

    sup = LogisticRegression().fit(X_pool[labeled], y_pool[labeled])
    semi = LabelSpreading(kernel="rbf", gamma=30, max_iter=200)
    semi.fit(X_pool, y_partial)
    print(seed, round(sup.score(X_test, y_test), 3),
          round(semi.score(X_test, y_test), 3))

In one run, logistic regression scored roughly 0.77 to 0.88 across seeds, while label spreading scored roughly 0.89 to 1.0. The data was built to suit the method, so read this as a demonstration of the assumption. Lower gamma, add noise and watch the advantage change.

Consistency regularization

Modern neural approaches often add a rule: the prediction should not change when the input is perturbed in a way that preserves its meaning. For an unlabeled image, you make a lightly altered view and a heavily altered one, then penalize disagreement between the model's outputs on them. Several methods combine this with confident pseudo-labels from the light view as targets for the heavy view.

As in self-supervised learning, your choice of perturbation states what should not matter. A change that can flip the true label will teach the model the wrong invariance.

A related route is two-stage: pretrain on all the data without labels, then fine-tune on the labeled part. With strong pretrained models available for text and images, this is often the first thing to try.

Transductive and inductive use

Some methods only label the pool you gave them. That is transductive learning: the unlabeled examples are exactly the ones you care about, as when sorting a fixed archive of documents. Inductive learning produces a function that also works on inputs arriving later.

Basic graph propagation is naturally transductive, although libraries may offer a way to score new points by looking at their neighbors. Self-training yields an ordinary model, so it is inductive. Decide which you need before choosing a method.

The distinction affects testing too. If you include test inputs, without their labels, in the graph or the pretraining pool, your score describes performance on a known pool. That is legitimate for a transductive job and optimistic for a system that must handle tomorrow's data. State which setup you used.

Cost also differs. A naive graph method compares every example with every other, which grows with the square of the number of examples. Sparse neighbor graphs reduce memory use considerably.

When the unlabeled pool is different

The pool you collected may not match the labeled set. Common mismatches:

Mismatch What can go wrong
Classes absent from the labeled set They get forced into known classes
Different class proportions Pseudo-labels drift toward the labeled mix
Different source or period Structure reflects the source, not the label
Many near-duplicates A few mistakes are copied widely

Before training, compare feature distributions, and read a random sample of the pool. Adversarial validation, which trains a classifier to tell the two sets apart, is a quick screen.

Evaluate without fooling yourself

With few labels, evaluation is the hard part. A validation set of 50 examples gives very noisy scores, so thresholds tuned on it may be arbitrary. Keep a test set that is never pseudo-labeled and never used for choosing settings. Repeat the experiment with several random choices of labeled examples and report the spread.

Give the supervised baseline the same care: the same architecture, the same augmentation, the same pretrained starting point. Much of an apparent semi-supervised gain can vanish when the baseline is given equal tuning.

Semi-supervision or more labels?

Sometimes the cheapest improvement is another few hundred labels. Plot performance against the number of labeled examples, as in a learning curve. If the curve is still climbing steeply, labeling pays. Active learning chooses which examples to send to annotators, and the two ideas combine well: ask people about uncertain cases and let confident ones be pseudo-labeled, while auditing a random sample of both.

Document which labels came from people and which from a model. Later users of the dataset need to know, and you will need it to debug a result that drifts.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 42 articles in Foundations →

Latest news on this topic