A project has 300 labeled photos and 30,000 photos that nobody has labeled. The unlabeled photos can enter training in very different ways. Semi-supervised learning uses them alongside the supplied labels for the same task, self-supervised learning builds its own targets from them to learn a representation for later tasks, and active learning asks a person to label the ones a rule selects. This lesson defines each approach, works through its main calculations, and shows the assumptions under which unlabeled data help and the ways they can quietly make a model worse. All data on this page are constructed for teaching.
Key terms
Semi-supervised learning
Definition Semi-supervised learning fits a model for a supervised task from a labeled set and an unlabeled set of inputs from the same input space,
where the labels of the inputs are not available to the learner and usually is much larger than . Unlabeled inputs describe only the distribution of the inputs, so they can help predict labels only through an assumption that links that distribution to the labels. A common one is the cluster assumption, that inputs in one dense region tend to share a label, which suggests that a decision boundary should run through regions where inputs are rare. A semi-supervised procedure also declares its data access. An inductive procedure produces a rule for any future input, and it is judged on labeled inputs that took no part in fitting in any form, with or without their labels. A transductive procedure only has to label the particular inputs in , which may be exactly the inputs that need predictions, and it is judged on a random sample of those inputs whose labels are obtained for the audit and kept out of training. If the unlabeled inputs come from a different population than the cases the model will face, or if their clusters follow something other than the label, adding them can make the model worse than a model fitted on alone.
In plain words Unlabeled inputs show where the data lie, not what they are. If the classes form separate clumps, knowing the clumps tells a classifier where its boundary can go, and a handful of labels then names each clump. The whole benefit rests on the clumps matching the classes.
Example A constructed problem has one feature. The labeled points are in class 0 and in class 1, and the unlabeled inputs are 1, 2, 3, 4, 6, 7 and 9.5. With the labeled points alone, a nearest-neighbor rule puts the threshold halfway, at 5. A low-density rule instead places the threshold between the two labeled points as far as possible from every input, labeled or not. The widest gap among all nine inputs runs from 7 to 9.5, so the threshold moves to 8.25, at distance 1.25 from the nearest input. The two rules disagree only about the inputs 6 and 7. If the classes follow the clusters, the unlabeled inputs correct both of those predictions. If the true boundary is at 5, for example because the gap reflects a change of camera rather than of class, the same unlabeled inputs turn two correct predictions into errors. Nothing in the unlabeled data tells these two situations apart. Only labeled cases held outside the procedure can.
Pseudo-labeling
Definition Pseudo-labeling, a form of self-training, is a semi-supervised procedure for classification. For a binary task with a confidence threshold in it runs as follows.
- Fit a classifier on the labeled set .
- For each unlabeled input , compute the predicted probability of class 1 and the pseudo-label , which is 1 when and 0 otherwise.
- Accept the pseudo-label only when the prediction is confident, that is, when or .
- Refit on the labeled set together with the accepted pairs , and if desired repeat from step 2 with the new model.
With classes the pseudo-label is the class with the largest predicted probability, and it is accepted when that probability is at least . A pseudo-label is a model output, not an annotation. The threshold selects by the model’s confidence, and confidence is not correctness, since a poorly calibrated model, or one applied to inputs unlike its training data, can be confidently wrong. An accepted mistake becomes a training target, which tends to shift the boundary so that inputs like the mislabeled one get the same wrong class, and so to produce more mistaken pseudo-labels in later rounds, a failure known as confirmation bias. Calibration does not remove the errors either. If the probabilities are calibrated, so that among cases given probability a fraction is positive, the expected number of wrong pseudo-labels is the sum of over the accepted cases, which is positive unless every accepted probability is exactly 0 or 1. The threshold and the number of rounds are tuned on validation data with genuine labels, the final evaluation uses genuinely labeled cases kept outside the whole selection and refitting procedure, and a report counts pseudo-labels separately from supplied labels.
In plain words The model labels new cases itself and keeps the answers it feels sure about. Feeling sure is not being right, and each accepted mistake is taught back to the model as if it were a fact, so a wrong start can feed on itself.
Example Four constructed unlabeled cases receive the probabilities 0.95, 0.82, 0.08 and 0.55, and the threshold is . The first case is accepted with pseudo-label 1 and the third with pseudo-label 0, while the second and fourth stay unlabeled. Suppose a later human inspection shows that the third case is positive. The refit has then trained on a wrong target, which pushes the boundary toward placing positive cases like it on the negative side, and the next round can accept more of the same mistake. Even if the four probabilities were perfectly calibrated, the expected number of wrong labels among the two accepted cases would be , so a confident pseudo-label is never a verified one.
Consistency regularization
Definition Let be a family of random transformations chosen so that each one preserves the correct label for the task, and let be the model’s vector of predicted class probabilities. Consistency regularization adds to the supervised loss a penalty for disagreement between the predictions on two views and of the same input, with and drawn independently from each time the input is used,
where is a supervised loss such as cross-entropy, sets the strength of the penalty, and
compares the two probability vectors with a discrepancy , such as the squared distance. With the objective is ordinary supervised training, and the penalty is often applied to labeled inputs as well. A transformation is label-preserving for a task when every input the task covers keeps its correct label after the transformation, which depends on the task and not on the transformation alone. Penalizing disagreement under a transformation that changes the label teaches the model a wrong invariance. A model that outputs the same probability vector for every input has zero penalty, so consistency cannot replace the supervised term or another signal that forces the model to tell inputs apart.
In plain words Two harmless edits of the same image should get the same answer, and the model pays a price when they do not. This teaches the right lesson only if the edits are truly harmless for the task at hand. Agreement is also easy to fake by giving one answer to everything, which is why the labeled examples stay in the objective.
Example A constructed right-pointing arrow is the binary grid
and the task label is the direction the arrow points. Placed on a larger blank canvas, the arrow keeps its direction under a shift by one pixel that leaves it entirely inside the canvas, and under a modest dimming that multiplies every intensity by 0.7 and so keeps the same pixels lit. A half-turn gives a left-pointing arrow, so pairing an image with its half-turned view would demand the same direction label for a right-pointing and a left-pointing arrow. For the task “is this an arrow” the half-turn is harmless, while for the direction task it is not. If a binary model gives the positive-class probabilities 0.8 and 0.6 to two permitted views, the squared penalty is . A model that returns 0.5 for every image has penalty 0 on every pair while knowing nothing about direction.
Self-supervised learning
Definition Self-supervised learning trains a model on a pretext task whose targets are constructed from unlabeled inputs by a declared procedure, without using labels of the task the model is finally meant for. Typical pretext tasks hide part of an input and predict it, such as a masked patch of an image or a masked word, predict the next token of a sequence, or identify which of several candidates is another view of the same example. The objective is as explicit as a supervised loss. Only the source of the targets differs, and those targets reflect design choices, such as what is hidden and which views count as the same, rather than categories revealed by the data. The usual aim is a representation, an encoder that maps inputs to vectors reused by a downstream supervised task. The encoder is then either frozen, with a small prediction head trained on the labeled training split, or fine-tuned under a declared validation procedure. A low pretext loss does not show that the representation helps downstream, because a shortcut, such as matching image borders or acquisition artifacts, can solve the pretext task without capturing what the downstream task needs. Pretraining choices, such as the pretext task, the augmentations and the training length, are tuned on validation data, and the final test set is used once, after all of them are fixed. If the pretraining pool contains the test inputs without labels, the report says so. That access suits a transductive question about those inputs, but for a claim about unseen future inputs, test inputs or near-copies of them in the pretraining pool make the score less informative.
In plain words The data supply questions whose answers we already hold, such as the hidden part of an image. Answering them forces the model to describe its inputs, and that description can then be reused for a task with real labels. Whether it helps is decided on that labeled task.
Example Hide one pixel of the arrow grid , the 1 in row 2 and column 4. The input is the grid with that entry replaced by a mask value, and the target is 1. Each of the 25 positions gives such an input and target from a single image, with no annotation at all. The target is a pixel value chosen by the masking design, and it says nothing directly about which way the arrow points. Whether features learned this way help the direction task is a downstream question. It is answered by freezing the encoder, training a head on labeled direction examples and checking that head on validation data.
Contrastive learning and representation collapse
Definition Contrastive learning is a self-supervised method that trains an encoder by comparing views. A view is an input after a random transformation from a family chosen to keep what downstream tasks need. The encoder maps each view to an embedding, often normalized to unit length, and the similarity of two embeddings is their dot product, which equals the cosine similarity when both have unit length. For an anchor view, the positive pair is the anchor with another view of the same original example, and the negative pairs are the anchor with views of other examples, often the rest of the batch. Let be the set of candidates, the positive and the negatives but never the anchor itself, let be the anchor’s similarity to candidate and its similarity to the positive, and let be a temperature. The contrastive loss of the anchor, often called InfoNCE, is
and the batch loss averages it over anchors. It is the cross-entropy of a softmax over the candidates whose correct class is the positive, so its targets come from sample identity and augmentation, not from class labels. A smaller temperature sharpens the softmax, so differences in similarity count for more. Two different examples of the same class still form a negative pair, a false negative that a setup based only on sample identity cannot avoid. Representation collapse is the failure in which distinct inputs receive identical or nearly identical embeddings, so the embedding keeps little or no information about the input. In a partial form the embeddings vary along only a few directions. If all embeddings are equal, every similarity is the same, each candidate gets probability , and the loss is at every temperature. Negative pairs make that solution costly. Methods without negative pairs rely on other mechanisms, such as asymmetric networks, stopped gradients or constraints on the statistics of the embeddings.
In plain words Two edits of one image should land close together and away from other images. Each anchor faces a multiple-choice question, which candidate came from the same image, and the answer key comes from bookkeeping rather than annotation. An encoder that sends everything to one point can only guess, so the negatives keep pushing different images apart.
Example One anchor has similarity 1 to its positive and 0 to each of two negatives, with . The positive receives probability
and the loss is . With the scaled scores are 2, 0 and 0, the probability of the positive rises to and the loss falls to about 0.2395. If the encoder collapses, all three similarities are equal and the loss is at any temperature, the cross-entropy of a uniform guess among three candidates. Collapse is not the worst case, since a positive that is less similar than the negatives does worse. For example the similarities , and give a loss of about 2.7586 at . The value is what an encoder that carries no information scores, and any later classifier that reads only its embeddings gives every input the same prediction.
Active learning
Definition Active learning spends a labeling budget on examples chosen by a rule. Starting from a small labeled set and a pool of unlabeled inputs, it repeats three steps until the budget is used. It fits a model on the current labeled set, applies an acquisition rule to choose one or more pool inputs, and has a person supply their true labels, which join the labeled set. Uncertainty sampling, the simplest acquisition rule for a binary classifier with predicted probabilities , requests
with a tie-breaking rule declared in advance. Other rules favor diverse inputs or the expected improvement of the model. The requested labels are genuine annotations, unlike pseudo-labels. Uncertainty sampling relies on the model’s own probabilities, so it gives the lowest priority to inputs on which the current model is confidently wrong. The labeled set it produces is chosen by the rule rather than drawn at random, so it cannot serve as an evaluation set for claims about the intended population, which needs a separately drawn representative sample. Its class proportions and mix of inputs can differ from those of the population, which can distort calibration and any population estimate computed from it, so a report states how the examples were selected.
In plain words When labels are expensive, ask for the ones the model is least sure about rather than random ones. The answers come from a person, so they are real labels, but the cases were picked for being hard, not for being typical.
Example For the four probabilities 0.95, 0.82, 0.08 and 0.55 the distances from 0.5 are 0.45, 0.32, 0.42 and 0.05, so uncertainty sampling requests the fourth case first. Without refitting, the next requests would be the second case and then the third. The third case, later found to be positive, is a confident mistake, yet it waits behind the case at 0.82 because its probability looks decisive. Confidence alone cannot reveal that it may be the more consequential error. If two cases had the probabilities 0.45 and 0.55, they would tie at distance 0.05, and only the declared tie-breaking rule would decide which comes first.
Check yourself
- A contrastive setup has one positive and one negative candidate, the anchor’s similarity to both is 0, and . What is the loss? What is it when the positive similarity rises to 1 while the negative stays at 0?
Show the answer
Both candidates get probability , so the loss is , the cross-entropy of a fair guess between two candidates.
With similarities 1 and 0 the positive gets probability , and the loss is
Raising the similarity of the positive relative to the negative lowers the loss.
- A downstream task separates images of the digits 6 and 9. Should a half-turn rotation be used for consistency regularization or to create positive pairs? Name transformations that are safer.
Show the answer
No. A half-turn makes a 6 look like a 9 and a 9 look like a 6, so it changes the correct label. Consistency regularization would push the model to give a 6 and its half-turned view the same prediction, and a positive pair would pull their embeddings together. Both teach the model to ignore exactly the difference the task depends on.
Safer choices are small shifts that keep the digit inside the frame, mild changes of brightness or contrast, and rotations by a few degrees. Each one still has to be checked against the label definition. The same half-turn could be harmless for a task whose label does not depend on orientation, which is why a transformation is judged for a task and not on its own.
- A report says a classifier was trained on 1,000 labeled images, 200 with supplied labels and 800 with pseudo-labels accepted by one model at . The threshold was chosen to give the best accuracy on a test set of 300 images that were part of the unlabeled pool and were labeled by hand afterward. If that model’s probabilities were calibrated, at most how many of the 800 pseudo-labels would be expected to be wrong? What else is wrong with the report, and how should it be fixed?
Show the answer
Every accepted case has or , so its chance of a wrong pseudo-label under calibration, , is at most 0.1. The expected number of wrong pseudo-labels is therefore at most , with equality only if every accepted probability sits exactly at 0.9 or 0.1. If the model is overconfident, there can be more.
The report has three further problems. First, the 800 pseudo-labels are model outputs, so the training data should be reported as 200 supplied labels and 800 pseudo-labels, with the selection rule. Second, the threshold was tuned on the test set, which makes the test part of model selection and its score optimistic. The threshold should be chosen on a validation set with genuine labels. Third, the test images sat in the unlabeled pool, which is transductive access. That is acceptable only if the job is to label exactly that pool and the report says so. For a claim about future images, the test set must consist of genuinely labeled images that took no part in training in any form, evaluated once after every choice is fixed.