What does it mean to learn from data?
A training example needs a signal that rewards some outputs over others. Where that signal comes from determines what the model can learn.
Open this chapter with experiments and audio
Where does the correct answer come from?
In supervised learning you provide an input and a target. A photo might come with a label identifying a bicycle, or a property record with a recorded sale price. A feature is a measurement available as input. A label or numerical target is the value you ask the model to predict. During evaluation the target is available to the evaluator and must be kept out of the model input.
A loss defines what counts as an error. Choosing squared price error makes a large miss especially costly. Choosing a classification loss can instead reward probability assigned to the correct label. The objective is a design decision. A low loss only has meaning in relation to that objective and the examples used to measure it.
How can plain text provide its own targets?
A causal language model trains on the next token in a sequence. The text itself supplies the targets. For a tiny example, let each word in “the room is square” be a token. Three input positions form three prediction problems. The target for a position is the actual following token. A causal mask prevents the network from reading that future token directly.
| Visible prefix | Target |
|---|---|
| the | room |
| the room | is |
| the room is | square |
tokens = "the room is square".split()
for i in range(1, len(tokens)):
print(" ".join(tokens[:i]), "->", tokens[i])The resulting pairs support self-supervised learning because no person labelled the next word separately. The final target “square” was present in the original string. This construction teaches conditional prediction. It does not directly ask the model to verify the geometry of the room.
What if there is no target per example?
In clustering, the algorithm groups inputs according to a chosen measure of similarity. With properties described by area and price, a distance-based algorithm may find compact groups. Rescaling one feature can change those groups because it changes relative distances. A cluster number has no automatic interpretation such as “family home”. Someone must examine the points in it.
In reinforcement learning, actions affect subsequent observations and rewards. A system choosing a sequence of moves may only receive a score at the end. The learning problem includes assigning credit across earlier choices. A reward that measures speed alone can encourage behaviour quite different from what a human would prefer.
Notice that a label can be a number, a category or a token ID. Its data type does not by itself determine the learning setup. The question to ask is how the target was obtained and what was visible to the model at prediction time.
Identify the training signal
For each project, write down one row that could enter training. List what the model sees before it predicts, what result a trainer can observe later, and how error or reward is computed. This simple exercise often exposes an unavailable input or an objective that differs from the desired real-world behaviour.
Is next-token prediction unsupervised because no one wrote the labels?
Self-supervised is the precise description here. There is a target for each prediction, and the data-processing rule produces it from the original sequence.
Hugging Face · Causal language modeling
For the room example, a calculator program consumes two dimensions and applies the rule for rectangular area. A supervised area predictor consumes dimensions and measured areas during training. A causal language model consumes text and learns from the observed next token. These three processes can return the same string “25 m²” while having used different evidence. Identifying the training signal gives you a way to distinguish their claims about the world.
What can a robot learn from the same trip record?
A warehouse log records the aisle a driver entered, the route they chose, travel time and damage on arrival. A supervised predictor can use the aisle and route to estimate travel time, with the observed time as its target. An imitation learner can instead take the aisle as input and the driver’s choice as target. An unsupervised algorithm could group trips by similar time and damage. The rows are identical. The choice of inputs, targets and objective changes what counts as a useful answer.
For a robot choosing a route, suppose the task ends after one trip. The wide aisle earns a certain 3 points. The short aisle earns 6 with probability 0.75 and −6 with probability 0.25. Its expected reward is 0.75 × 6 + 0.25 × (−6) = 3. An agent maximizing average reward is indifferent in this case, even though an individual trip through the short aisle can have a much worse outcome.
If a damaged delivery now costs 10 points, what changes in the system?
The expected reward for the short aisle becomes 4.5 − 2.5 = 2, so the wide aisle wins. The observed travel times and the imitation labels can stay the same. The policy depends on how consequences are valued. If the old log never contains the short route in some aisle, its consequences there must be estimated from other evidence or observed in a suitable trial.
Identify which observation supplies a learning signal in each task →
Further reading · UC Berkeley · Value iteration and policy extraction