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

<div data-sim="specx" data-spec="{&#34;head&#34;:&#34;Pseudo-labelling with a confidence threshold, the FixMatch way&#34;,&#34;sub&#34;:&#34;Forty unlabelled handwritten digits, the model&#39;s confidence on each and whether its guess is right. Set the threshold: only confident guesses become training labels for the strongly augmented copy.&#34;,&#34;params&#34;:[{&#34;id&#34;:&#34;tau&#34;,&#34;label&#34;:&#34;Confidence threshold τ&#34;,&#34;min&#34;:0.5,&#34;max&#34;:0.99,&#34;step&#34;:0.01,&#34;value&#34;:0.95,&#34;note&#34;:&#34;FixMatch default 0.95&#34;},{&#34;id&#34;:&#34;wu&#34;,&#34;label&#34;:&#34;Unlabelled loss weight λu&#34;,&#34;min&#34;:0,&#34;max&#34;:2,&#34;step&#34;:0.1,&#34;value&#34;:1,&#34;note&#34;:&#34;FixMatch default 1&#34;}],&#34;data&#34;:{&#34;columns&#34;:[&#34;img&#34;,&#34;conf&#34;,&#34;correct&#34;,&#34;p_strong&#34;],&#34;rows&#34;:[[1,0.279,0,0.416],[2,0.818,1,0.766],[3,0.978,1,0.921],[4,0.777,1,0.143],[5,0.983,1,0.871],[6,0.851,1,0.696],[7,0.298,0,0.251],[8,0.977,1,0.903],[9,0.868,1,0.465],[10,0.953,1,0.833],[11,0.842,1,0.782],[12,0.979,1,0.789],[13,0.918,0,0.851],[14,0.917,1,0.903],[15,0.437,0,0.157],[16,0.425,1,0.422],[17,0.856,1,0.938],[18,0.455,1,0.407],[19,0.853,1,0.641],[20,0.938,1,0.972],[21,0.994,1,0.982],[22,0.829,0,0.796],[23,0.947,1,0.925],[24,0.585,1,0.371],[25,0.96,1,0.982],[26,0.977,1,0.913],[27,0.904,1,0.765],[28,0.905,1,0.789],[29,0.994,1,0.941],[30,0.964,1,0.952],[31,0.639,1,0.404],[32,0.947,1,0.914],[33,0.485,1,0.304],[34,0.508,0,0.368],[35,0.956,1,0.702],[36,0.699,1,0.353],[37,0.946,1,0.953],[38,0.85,1,0.623],[39,0.936,1,0.902],[40,0.877,1,0.796]],&#34;note&#34;:&#34;Computed with scikit-learn on the digits dataset: logistic regression trained on 30 labelled digits. conf is its top probability on an unlabelled digit, correct whether that guess is right, p_strong the probability it gives that guess on a shifted, noisy copy.&#34;},&#34;row&#34;:[{&#34;id&#34;:&#34;mask&#34;,&#34;label&#34;:&#34;used as label&#34;,&#34;expr&#34;:&#34;ge(conf, tau)&#34;,&#34;fmt&#34;:&#34;i&#34;,&#34;tex&#34;:&#34;m_i = \\mathbb{1}\\big[\\max_c\\, p(c \\mid \\alpha(u_i)) \\ge \\tau\\big]&#34;},{&#34;id&#34;:&#34;good&#34;,&#34;label&#34;:&#34;right label used&#34;,&#34;expr&#34;:&#34;mask*correct&#34;,&#34;fmt&#34;:&#34;i&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;bad&#34;,&#34;label&#34;:&#34;wrong label used&#34;,&#34;expr&#34;:&#34;mask*(1 - correct)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;lost&#34;,&#34;label&#34;:&#34;right label discarded&#34;,&#34;expr&#34;:&#34;(1 - mask)*correct&#34;,&#34;fmt&#34;:&#34;i&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;ce&#34;,&#34;label&#34;:&#34;cross-entropy on strong view&#34;,&#34;expr&#34;:&#34;-ln(p_strong)&#34;,&#34;tex&#34;:&#34;H(\\hat q_i, p(\\cdot \\mid \\mathcal{A}(u_i))) = -\\ln p(\\hat q_i \\mid \\mathcal{A}(u_i))&#34;},{&#34;id&#34;:&#34;lu&#34;,&#34;label&#34;:&#34;unlabelled loss&#34;,&#34;expr&#34;:&#34;mask*(-ln(p_strong))&#34;},{&#34;id&#34;:&#34;cacc&#34;,&#34;label&#34;:&#34;confidence if used&#34;,&#34;expr&#34;:&#34;mask*conf&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;pacc&#34;,&#34;label&#34;:&#34;strong-view prob if used&#34;,&#34;expr&#34;:&#34;mask*p_strong&#34;,&#34;hide&#34;:true}],&#34;derived&#34;:[{&#34;id&#34;:&#34;nused&#34;,&#34;label&#34;:&#34;Pseudo-labels used&#34;,&#34;expr&#34;:&#34;sum(mask)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;maskrate&#34;,&#34;label&#34;:&#34;Mask rate&#34;,&#34;expr&#34;:&#34;mean(mask)&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;\\text{mask rate} = \\frac{1}{\\mu B}\\sum_i m_i&#34;},{&#34;id&#34;:&#34;nbad&#34;,&#34;label&#34;:&#34;Wrong pseudo-labels used&#34;,&#34;expr&#34;:&#34;sum(bad)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;plabacc&#34;,&#34;label&#34;:&#34;Accuracy of used pseudo-labels&#34;,&#34;expr&#34;:&#34;sum(good)/max(nused, 1)&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;\\text{acc} = \\frac{\\sum_i m_i\\,\\mathbb{1}[\\hat q_i = y_i]}{\\sum_i m_i}&#34;},{&#34;id&#34;:&#34;meanconf&#34;,&#34;label&#34;:&#34;Mean confidence of used labels&#34;,&#34;expr&#34;:&#34;sum(cacc)/max(nused, 1)&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;nlost&#34;,&#34;label&#34;:&#34;Right guesses thrown away&#34;,&#34;expr&#34;:&#34;sum(lost)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;lossu&#34;,&#34;label&#34;:&#34;Unlabelled loss ℓu&#34;,&#34;expr&#34;:&#34;mean(lu)&#34;,&#34;tex&#34;:&#34;\\ell_u = \\frac{1}{\\mu B}\\sum_{i=1}^{\\mu B} m_i\\, H\\big(\\hat q_i,\\ p(\\cdot \\mid \\mathcal{A}(u_i))\\big)&#34;},{&#34;id&#34;:&#34;wloss&#34;,&#34;label&#34;:&#34;Weighted ℓu added to the loss&#34;,&#34;expr&#34;:&#34;wu*mean(lu)&#34;,&#34;tex&#34;:&#34;\\ell = \\ell_s + \\lambda_u\\, \\ell_u&#34;},{&#34;id&#34;:&#34;rawacc&#34;,&#34;label&#34;:&#34;Accuracy of all guesses&#34;,&#34;expr&#34;:&#34;mean(correct)&#34;,&#34;fmt&#34;:&#34;p&#34;}],&#34;chart&#34;:{&#34;title&#34;:&#34;Confidence of each guess, whether it is right, and the cut-off&#34;,&#34;x&#34;:{&#34;var&#34;:&#34;t&#34;,&#34;label&#34;:&#34;Model confidence on the weak view (the digit itself)&#34;,&#34;from&#34;:0.3,&#34;to&#34;:1},&#34;y&#34;:{&#34;from&#34;:-0.05,&#34;to&#34;:1.05},&#34;series&#34;:[{&#34;label&#34;:&#34;Used as a label (1) or ignored (0)&#34;,&#34;expr&#34;:&#34;ge(t, tau)&#34;},{&#34;label&#34;:&#34;Perfect calibration&#34;,&#34;expr&#34;:&#34;t&#34;,&#34;dash&#34;:true}],&#34;points&#34;:{&#34;x&#34;:&#34;conf&#34;,&#34;y&#34;:&#34;correct&#34;,&#34;label&#34;:&#34;Digit (1 = guess right, 0 = wrong)&#34;},&#34;fit&#34;:{&#34;x&#34;:&#34;conf&#34;,&#34;y&#34;:&#34;pacc&#34;,&#34;label&#34;:&#34;Strong view&#39;s probability for used labels&#34;},&#34;mark&#34;:&#34;tau&#34;},&#34;level&#34;:&#34;intermediate&#34;,&#34;bars&#34;:{&#34;title&#34;:&#34;Unlabelled loss of each digit (0 when masked out)&#34;,&#34;y&#34;:&#34;lu&#34;,&#34;label&#34;:&#34;img&#34;},&#34;steps&#34;:[{&#34;title&#34;:&#34;Guess on the weak view&#34;,&#34;text&#34;:&#34;The model labels each unlabelled digit from a lightly augmented copy. Over all forty, its guesses are right {rawacc:p} of the time.&#34;,&#34;show&#34;:[&#34;rawacc&#34;]},{&#34;title&#34;:&#34;Keep only confident guesses&#34;,&#34;text&#34;:&#34;A guess becomes a pseudo-label only if its confidence is at least τ = {tau}: {nused} digits pass, a mask rate of {maskrate:p}.&#34;,&#34;show&#34;:[&#34;nused&#34;,&#34;maskrate&#34;]},{&#34;title&#34;:&#34;Check their quality&#34;,&#34;text&#34;:&#34;{plabacc:p} of the used pseudo-labels are right ({nbad} wrong), at a mean confidence of {meanconf:p}; {nlost} correct guesses are thrown away.&#34;,&#34;show&#34;:[&#34;plabacc&#34;,&#34;nbad&#34;,&#34;nlost&#34;]},{&#34;title&#34;:&#34;Train on the strong view&#34;,&#34;text&#34;:&#34;Each kept pseudo-label is the target for a heavily augmented copy. The cross-entropy, averaged over all forty digits with masked ones counting zero, is ℓu = {lossu}.&#34;,&#34;show&#34;:[&#34;lossu&#34;]},{&#34;title&#34;:&#34;Add it to the supervised loss&#34;,&#34;text&#34;:&#34;With weight λu = {wu}, {wloss} is added to the labelled loss for this batch. Repeat every step: as the model improves, more digits pass the bar.&#34;,&#34;show&#34;:[&#34;wloss&#34;]}]}"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

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

1. **Weak view.** Predict a class distribution from a lightly augmented copy (here simply the digit itself).
2. **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`.
3. **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.
4. **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).
5. **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](/ai-simulations/precision-recall-threshold) and [conformal prediction](/ai-simulations/conformal-prediction), which turns confidences into guarantees.

## Sources

- [Google Research: FixMatch code (fixmatch.py)](https://github.com/google-research/fixmatch/blob/master/fixmatch.py)
- [Google Research: FixMatch README](https://github.com/google-research/fixmatch/blob/master/README.md)
- [scikit-learn: SelfTrainingClassifier source](https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/semi_supervised/_self_training.py)
- [scikit-learn: the digits dataset description](https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/datasets/descr/digits.rst)
