AI Wiki中文/EN

Pseudo-labeling

伪标签学习

Audit confidence gates, full-batch loss scaling and a one-step confirmation-bias counterexample.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Start 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:

piw=σ((xiw)⊤w),y^i=1[piw≥1/2],ai=1[max⁡(piw,1−piw)≥τ].p_i^w=\sigma((x_i^w)^\top w),\qquad \hat y_i=\mathbf1[p_i^w\ge1/2],\qquad a_i=\mathbf1[\max(p_i^w,1-p_i^w)\ge\tau].

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:

L=1Nl∑i∈LBCE⁡(yi,pi)+λU∑i=1UaiBCE⁡(sg⁡(y^i),pis),pis=σ((xis)⊤w).L=\frac1{N_l}\sum_{i\in\mathcal L}\operatorname{BCE}(y_i,p_i)+\frac\lambda U\sum_{i=1}^{U}a_i\operatorname{BCE}(\operatorname{sg}(\hat y_i),p_i^s),\qquad p_i^s=\sigma((x_i^s)^\top w).

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:

∇wL=1Nl∑i∈L(pi−yi)xi+λU∑i=1Uai(pis−y^i)xis.\nabla_wL=\frac1{N_l}\sum_{i\in\mathcal L}(p_i-y_i)x_i+\frac\lambda U\sum_{i=1}^{U}a_i(p_i^s-\hat y_i)x_i^s.

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

Accepted coverage and correctness on the fixed six-point teaching table. Threshold positions are categorical. At 0.99 nothing is accepted, so precision is undefined and no point is drawn. Audit truth is never used to create pseudo-targets.
Accepted coverage and correctness on the fixed six-point teaching table. Threshold positions are categorical. At 0.99 nothing is accepted, so precision is undefined and no point is drawn. Audit truth is never used to create pseudo-targets.

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 O(Ud)O(Ud) 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

  1. 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.

  1. 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.

  1. 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.

  1. 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?

Choose one answer

Learning objectives

  • Compute masked pseudo-label gradients with the correct denominator.
  • Audit acceptance coverage and confirmation bias separately.

Prerequisites & connections

Explore related knowledge →

References

  1. 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
  2. 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:

Related topics

No matches. Try a synonym or acronym.

0 results shown

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