Sub topic 15
Beyond the Two: Semi-Supervised, Self-Supervised, and Reinforcement Learning
This chapter assumes you know the difference between supervised learning (learning from labeled examples) and unsupervised learning (finding structure without labels). It also assumes you know what features, labels, and a loss function are. Supervised and unsupervised learning cover most introductory work, but three other paradigms are common in practice.
Why two paradigms are not enough
Supervised learning needs labels, and labels are often expensive. A radiologist must read each scan. A lawyer must tag each contract. Unlabeled data is usually cheap and plentiful. Some problems also have no fixed "right answer" for each input, only a result that arrives after a series of choices. The three paradigms below address these cases.
Semi-supervised learning
Semi-supervised learning trains on a small set of labeled examples and a large set of unlabeled ones. The unlabeled examples show the model the shape of the data. Points that sit close together probably share a label, so the few labels can be spread to their neighbors.
A common method is self-training. You train on the labeled data, predict labels for the unlabeled data, keep the predictions the model is most confident about, and retrain.
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.semi_supervised import SelfTrainingClassifier
from sklearn.linear_model import LogisticRegression
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=0, stratify=y
)
# Hide 80% of the training labels. scikit-learn marks them with -1.
rng = np.random.default_rng(0)
y_partial = y_train.copy()
y_partial[rng.random(len(y_train)) < 0.8] = -1
model = SelfTrainingClassifier(LogisticRegression(max_iter=200))
model.fit(X_train, y_partial)
print(model.score(X_test, y_test))The risk is that early mistakes get reused as training labels and reinforce themselves. Always score on a test set with true labels.
Self-supervised learning
Self-supervised learning builds its labels from the data itself. You hide part of each example and train the model to predict the hidden part. No human labeling is needed, yet the training loop is the same as in supervised learning: predict, compare, reduce the loss.
Examples:
- A language model sees the words of a sentence so far and predicts the next word.
- An image model sees a photo with a patch removed and predicts the missing patch.
The result is a model that has learned useful representations of the data. These are often reused and then fine-tuned with a small labeled set for a specific task. Large language models are trained this way first.
Reinforcement learning
In reinforcement learning, an agent interacts with an environment. At each step it observes a state, chooses an action, and receives a reward. The goal is a policy, a rule for choosing actions, that maximizes total reward over time.
Three features set it apart from supervised learning:
- Feedback is a reward, not a correct answer.
- Rewards can be delayed. A chess move may only be judged by the final result.
- The agent's actions change the data it sees next, so it must balance exploring new actions against exploiting ones that already work.
Comparing the paradigms
| Paradigm | Training signal | Typical use |
|---|---|---|
| Supervised | Human-provided labels | Spam detection, price prediction |
| Unsupervised | None | Clustering, compression |
| Semi-supervised | A few labels plus many unlabeled examples | Medical imaging with costly labels |
| Self-supervised | Labels derived from the data | Pretraining language and image models |
| Reinforcement | Reward from an environment | Game playing, robot control |
Exercise
A team has 100,000 product photos but only 500 are labeled with a category. Which paradigm fits best, and why?
Show answer
Semi-supervised learning. The 500 labeled photos give the model a supervised signal, and the many unlabeled photos help it learn the structure of the data. Self-supervised pretraining on all photos followed by fine-tuning on the 500 labels is also a reasonable choice.
Exercise
Why is reinforcement learning different from supervised learning even though both use a feedback signal?
Show answer
The feedback is a reward rather than the correct answer, it can arrive long after the action, and the agent's own actions change which data it sees next.