Pseudo-labelling with a confidence threshold: how FixMatch turns unlabelled data into labels
Semi-supervised learning gets labels for free by trusting the model's own confident guesses. The confidence threshold decides how many guesses you use and how many mistakes you train on. Here a real model trained on thirty labelled digits labels forty more, and you set the bar.
Interactive simulation. It needs JavaScript; the text below explains what it shows.
What you are looking at
A logistic regression was trained with scikit-learn on just 30 labelled images from the digits dataset (three per digit, 8 × 8 pixels each). It then looked at 40 unlabelled digits. For each one the table holds its confidence (the highest class probability), whether that guess is actually right (we know the true labels, the model does not), and p_strong: the probability the same model gives its guess on a strongly augmented copy of the digit, with a 2 × 2 patch blanked out and pixel noise added. Every number came out of that run; none is invented.
On the chart each digit is a dot placed at its confidence, at the top if the guess is right and at the bottom if it is wrong. The step line shows which digits pass the threshold τ and become pseudo-labels. The dashed diagonal is perfect calibration, and the fitted markers show how confidently the strong view still agrees with each used pseudo-label: low values mean a large loss. The bars show each digit's contribution to the unlabelled loss.
The algorithm
FixMatch, from Google Research, combines two older ideas: pseudo-labelling (train on your own confident predictions) and consistency regularisation (a prediction should not change when the input is perturbed). For every unlabelled image in a batch:
- Weak view. Predict a class distribution from a lightly augmented copy (here simply the digit itself).
- Threshold. If the top probability is at least τ, the top class becomes a hard pseudo-label and the mask is 1; otherwise the image is ignored this step. The released code uses τ = 0.95 and logs the share of masked-in images as
monitors/mask. - Strong view. Predict on a heavily augmented copy (CTAugment plus Cutout in the released code; a blanked patch and noise here) and take the cross-entropy against the pseudo-label.
- Average. The unlabelled loss is the mean of mask × cross-entropy over the whole unlabelled batch, so ignored images count as zero. In the code the unlabelled batch is seven times the labelled one (uratio = 7).
- Combine. The total loss is the supervised loss plus λu times the unlabelled loss, with λu = 1 by default.
As training goes on the model gets better and more confident, more images pass the threshold and the unlabelled data does more of the work. The danger is confirmation bias: a confident wrong pseudo-label teaches the model its own mistake, and nothing in the loss corrects it.
Worked example
At the FixMatch default τ = 0.95, 11 of the 40 digits pass (a mask rate of 27.5%). All 11 are right, at a mean confidence of 97.4%, while the model's guesses over all 40 digits are right only 85% of the time. The price is that 23 correct guesses are thrown away. Their cross-entropies on the strong view, for example −ln 0.702 = 0.354 for digit 35, sum to 1.333; divided by all 40 digits that is ℓu = 0.0333, and with λu = 1 the same 0.0333 is added to the labelled loss.
Things to try
- Lower τ to 0.90. Twenty digits are used, but digit 13, a wrong guess at 91.8% confidence, now gets in; accuracy of the used labels drops to 95%.
- Lower τ to 0.80: 29 digits, two of them wrong (digit 22 at 82.9% joins), 93.1% accurate, and ℓu rises to 0.138. Compare the mean confidence of the used labels, 92.1%, with their accuracy: this model is roughly calibrated in that range.
- Go to τ = 0.50: 34 digits, 3 wrong, ℓu = 0.285. scikit-learn's SelfTrainingClassifier defaults to 0.75 and warns that its threshold needs a well calibrated classifier.
- Push τ to 0.99: only 2 digits pass and the unlabelled loss almost disappears. Too strict a bar wastes the unlabelled data.
- Look at digit 13: its strong view agrees with the wrong label at 0.851. Consistency does not protect you from a confident mistake.
How it works in real systems
The threshold trades quantity against quality, and the right value depends on calibration. Deep networks are often over-confident, which is why FixMatch uses a very high τ, and why its weak-strong pairing matters: the strong augmentation makes the task hard enough that the model keeps learning from the labels it trusts. Self-training in scikit-learn works the same way but in rounds: fit, add every unlabelled sample whose probability passes the threshold (or the k best), and fit again. Large language models use the same idea under other names: filtering generated training data by a verifier or reward model is pseudo-labelling with a threshold. If you can afford to label a few examples instead, choosing which ones is the job of active learning. Related simulations: precision and recall against a threshold and conformal prediction, which turns confidences into guarantees.