Pseudo-labeling
伪标签学习
Audit confidence gates, full-batch loss scaling and a one-step confirmation-bias counterexample.
pseudo-labelingStart with the problem
A model labels an example that no person has labeled, then trains on its own prediction. This can extend a small labeled dataset, but it can also turn a mistake into a stronger belief. Pseudo-labeling therefore needs both a learning rule and an audit of which predictions are accepted.
FixMatch computes hard labels from weakly augmented inputs, keeps sufficiently confident predictions and trains against them on strongly augmented inputs. Arazo and colleagues analyze confirmation bias: fitting an incorrect pseudo-label can reinforce the original error. Their soft-label and regularization method is different from the hard thresholding example implemented here. FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence; Pseudo-Labeling and Confirmation Bias in Deep Semi-Supervised Learning — arXiv v1
We will calculate one frozen-target update on six unlabeled points. A hidden truth column is used only to audit accepted labels, never to generate their targets or gradients. The result makes the coverage–precision trade-off visible without promising that confidence is calibrated.
Definitions and derivation
For a binary classifier with sigmoid probability p, take the weak-view prediction before the update. A hard target and confidence mask are:
Both the target and mask are held fixed for the current gradient calculation. Recompute them at the next training step if continuing self-training. Combine labeled BCE with masked strong-view BCE, dividing the latter by the full unlabeled batch size U, not the number accepted:
This normalization follows FixMatch’s unlabeled-batch convention. If acceptance falls, the total unlabeled gradient naturally shrinks. Dividing by accepted count instead defines a different weighting rule and needs an explicit empty-mask policy. For fixed labels and mask, differentiate sigmoid BCE:
The code appends an intercept coordinate of one and evaluates BCE as logaddexp(0, logit) − label * logit. There is no gradient through hard label selection or the gate. Finite differences must reuse the frozen target/mask to check this derivative. The weak-to-strong construction follows the paper’s mechanism; our two-dimensional perturbations are not its image augmentation pipeline. FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence
Run the calculation
Run CPython 3.12.4 with NumPy 1.26.4. Two labeled points anchor the two classes; six additional points have a useful first coordinate and a nuisance second coordinate. The initial weight vector (1.5,1,0.1) is supplied, not learned in an unreported warm-up. Strong views reverse only the nuisance coordinate. At threshold 0.8 all six predictions are accepted but only four are correct; at 0.9, two are accepted and both are correct. At 0.99 none are accepted and audit precision is undefined. One fixed-target step of size 0.05 lowers loss from 1.105158435 to 1.085190849.
import numpy as np
LABELED=np.array([[-1.,0,1],[1,0,1]]);LABELS=np.array([0.,1.])
WEAK=np.c_[np.array([[-2.,.1],[-1.2,.2],[1.3,-.1],[2.,.2],[-.3,2],[.3,-2]]),np.ones(6)]
STRONG=WEAK.copy();STRONG[:,1]*=-1
def sigmoid(x):return np.exp(-np.logaddexp(0,-x))
def pseudo_targets(w,threshold):
if not .5<=threshold<=1:raise ValueError('Use a confidence threshold from 0.5 to 1.')
probability=sigmoid(WEAK@w);labels=(probability>=.5).astype(float);mask=np.maximum(probability,1-probability)>=threshold;return labels,mask,probability
def objective(w,targets,mask,weight=1.):
logits=LABELED@w;p=sigmoid(logits);loss=np.mean(np.logaddexp(0,logits)-LABELS*logits);g=LABELED.T@(p-LABELS)/len(LABELED);u=STRONG@w;pu=sigmoid(u);loss+=weight*np.sum(mask*(np.logaddexp(0,u)-targets*u))/len(STRONG);g+=weight*STRONG.T@(mask*(pu-targets))/len(STRONG);return float(loss),g
def initial():return np.array([1.5,1.,.1])
if __name__=='__main__':
w=initial();truth=(WEAK[:,0]>0).astype(float)
for threshold in (.5,.8,.9,.95,.99):
q,mask,p=pseudo_targets(w,threshold);precision=None if not mask.any() else float(np.mean(q[mask]==truth[mask]));loss,g=objective(w,q,mask);print('threshold',threshold,'accepted',int(mask.sum()),'coverage',float(mask.mean()),'diagnostic precision',precision,'objective',round(loss,9))
q,mask,p=pseudo_targets(w,.8);loss,g=objective(w,q,mask);next_w=w-.05*g;print('fixed-target one-step loss',round(loss,9),round(objective(next_w,q,mask)[0],9))
x=WEAK[4];p=float(sigmoid(x@w));reinforced=w-.1*(p-1)*x;print('isolated wrong-pseudo-label confidence',round(p,9),round(float(sigmoid(x@reinforced)),9),'true class used only for audit',0)
threshold 0.5 accepted 6 coverage 1.0 diagnostic precision 0.6666666666666666 objective 1.105158435
threshold 0.8 accepted 6 coverage 1.0 diagnostic precision 0.6666666666666666 objective 1.105158435
threshold 0.9 accepted 2 coverage 0.3333333333333333 diagnostic precision 1.0 objective 0.219184097
threshold 0.95 accepted 1 coverage 0.16666666666666666 diagnostic precision 1.0 objective 0.211086205
threshold 0.99 accepted 0 coverage 0.0 diagnostic precision None objective 0.202159075
fixed-target one-step loss 1.105158435 1.085190849
isolated wrong-pseudo-label confidence 0.83889105 0.849668633 true class used only for audit 0
When the method fails
The isolated final calculation deliberately reinforces a wrong pseudo-label on its original view. Confidence in the incorrect class rises from 0.838891050 to 0.849668633. The optimizer correctly minimizes the supplied objective; the supplied target is wrong. This is the feedback problem described as confirmation bias, not evidence that confidence thresholds solve it. Pseudo-Labeling and Confirmation Bias in Deep Semi-Supervised Learning — arXiv v1
The accepted subset can overrepresent easy examples or majority classes. Audit class coverage and error patterns, not just average confidence. Tune thresholds using labeled validation data; the truth column in this teaching table is an audit convenience, not information available for an unlabeled deployment set.
Strong transformations must preserve the target. Reversing a nuisance coordinate is harmless only because the constructed class depends on the first coordinate; reversing the useful coordinate would invalidate the label. Distribution shift, novel classes and systematic model mistakes can break pseudo-label assumptions.
With U unlabeled examples and d model coordinates, this linear update costs beyond the labeled pass. The practical cost for a neural model includes both weak and strong forward passes and a strong-view backward pass. A higher acceptance rate is not automatically more efficient learning if accepted labels are wrong.
Exercises with answers
- At threshold 0.8, what are coverage and audited precision?
Answer 1: Coverage is 6/6=1; precision is 4/6=2/3. Confidence alone did not identify the two wrong labels.
- What remains when the acceptance mask is empty?
Answer 2: Only the labeled loss and gradient; the unlabeled sum is zero and no division by accepted count occurs.
- Why freeze pseudo-targets during a finite-difference check?
Answer 3: The implemented update differentiates with respect to student predictions while holding the selected labels and mask fixed.
- If a wrong pseudo-label becomes more confident, must the gradient implementation be wrong?
Answer 4: No. Cross-entropy can correctly reinforce an incorrect supplied target.
Sources and next steps
Read FixMatch Section 2.2 for the full-batch denominator and weak-to-strong targets. Read Arazo et al. Section 3.1 for confirmation bias, keeping their soft-label method distinct from this example. Continue with consistency regularization to examine what the augmentation assumption itself asks a model to ignore. FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence; Pseudo-Labeling and Confirmation Bias in Deep Semi-Supervised Learning — arXiv v1
Make a prediction, then check
If no pseudo-label passes the confidence threshold, this objective does what?
Learning objectives
- Compute masked pseudo-label gradients with the correct denominator.
- Audit acceptance coverage and confirmation bias separately.
Prerequisites & connections
Explore related knowledge →References
- FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence
Kihyuk Sohn; David Berthelot; Chun-Liang Li; Zizhao Zhang; Nicholas Carlini; Ekin D. Cubuk; Alex Kurakin; Han Zhang; Colin Raffel · 2020 - Pseudo-Labeling and Confirmation Bias in Deep Semi-Supervised Learning — arXiv v1
Eric Arazo; Diego Ortego; Paul Albert; Noel E. O’Connor; Kevin McGuinness · 2019
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.
- Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, executable examples and corresponding bilingual equations, code and exercises. Not independent human or second-agent review.
- Four CPython 3.12.4 checks per chapter: spectra and exact recurrence with scale-aware tolerances, frozen ridge probes, literal graded retrieval metrics, whitening/SVD constraints, finite balancing marginals and stopped targets, pseudo-label denominator, exact noise expectation and temperature-weighted distillation as applicable, plus bilingual structure. All eight programs use NumPy 1.26.4; no real image/text benchmark reproduction claimed.
- 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.
- Compact bilingual Matplotlib 3.9.1 charts use executed functions for eigenvalue shares, accepted-label coverage/precision and shifted-test error. Numerical samples and both SVGs are hash-bound. Zero-variance and undefined-precision cases are not plotted as invented measurements.
Source locations checked:
- FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence · Physical page 3, Sections 2.1–2.2 Eqs. 2–4: hard labels, confidence threshold, weak/strong views and full unlabeled batch denominator.
- Pseudo-Labeling and Confirmation Bias in Deep Semi-Supervised Learning — arXiv v1 · Version 1 physical pages 3–4, Section 3 and Section 3.1: soft-label formulation and reinforcing incorrect predictions; not claimed to implement its warm-up/mixup recipe.
Related topics