Supervised learning
Supervised learning is the most common form of machine learning. The system is given a dataset where each example has an input and a known correct output. The model learns a mapping from input to output.
For example, an email spam filter sees thousands of emails labeled spam or not spam. It learns features like word frequencies, sender reputation, and punctuation patterns that help it classify new emails.
Key idea: learning is search. The algorithm searches through possible models for the one that makes the fewest mistakes on the training data while staying simple enough to work on new data.
Features and labels
In supervised learning, each example is a pair: features and a label.
- Features are the measurable properties of the example, like the length of an email or the number of red pixels in an image.
- Labels are the correct answers, like spam or not spam, or the species of a flower.
Choosing good features is often more important than choosing a fancy algorithm. Garbage in, garbage out still applies.
Loss and optimization
A loss function measures how wrong the model is. During training, the model tries to minimize the average loss across the training set.
Optimization is the algorithm that updates the model's parameters to reduce loss. The simplest version, gradient descent, looks at the slope of the loss and takes a small step downhill. Repeat many times, and the model usually gets better.
Modern deep learning uses much larger models and more advanced optimizers, but the idea is the same: define a loss, compute gradients, update parameters.
Memorization vs generalization
A model can get perfect accuracy on its training data just by memorizing it. But that is useless if the model fails on new data. The ability to perform well on unseen examples is called generalization.
Overfitting happens when a model memorizes noise or specific examples instead of learning the underlying pattern. It performs well on training data but poorly in the real world. Underfitting happens when the model is too simple to capture the pattern at all.
The art of machine learning is finding the right complexity: not too simple, not too tailored to the training set.
Real-world note: LLMs can appear to generalize because they have seen so much data. But they can still fail on questions that are different from their training distribution.
Train a line classifier
The points on the grid below are labeled blue or red. Adjust the line's slope and intercept to separate them. Then click Run one gradient step to let the computer improve the line automatically.
Gradient descent in Python
This example finds the slope of the line y = 2x by starting with a random weight and walking downhill on the loss function.
Check yourself
Explain the difference between a loss function and an optimizer.
Your answer:
Sample answer: A loss function measures how far the model's predictions are from the correct labels. An optimizer uses those measurements to update the model's parameters, moving them in a direction that reduces the loss.
Quick quiz
1. In supervised learning, the known correct output is called the:
2. What does a loss function measure?
3. What is overfitting?
Keep learning
You now understand the supervised learning pipeline. Next, apply it to language: what is a large language model?
Part of the advanced remake of the “Are LLMs Smarter Than a 5th Grader?” series.