Neural networks and other machine learning models learn in one basic way: they make a prediction, measure how wrong it was, and change their internal numbers a little so the next prediction is less wrong. Repeat that over many examples and the model’s behavior shifts. The sections below cover each part of that loop, a worked example, and the limits to keep in mind.
What “learning” means here
When people say a model “learns,” they mean something specific. A model is a mathematical function with adjustable numbers, usually called weights or parameters. Training changes those numbers so the model’s outputs move closer to the correct answers in a set of example data. The model does not understand those examples the way a person does. It is tuned to make fewer mistakes on the cases it has seen.
The goal is not to be perfect on the training examples. The goal is to do well on new inputs the model has never seen. Most of the difficulty in machine learning comes from the gap between those two things.
The four parts of a learning setup
Most machine learning systems, neural networks included, have four parts.
Data. Learning needs examples. In supervised learning, each example pairs an input with a label, the correct answer for that input. Raw data is often cleaned and formatted before training. The reasons are covered in “Why Data Preprocessing Is Needed in Machine Learning.”
A model. This is the function with adjustable weights. A neural network is one kind of model, built from layers of simple units. Others include linear regression and decision trees.
A loss function. This turns the gap between prediction and target into one number, where lower is better. For predicting a number, mean squared error is a common choice. For choosing among categories, cross-entropy loss is common.
An optimizer. This is the rule that uses the loss to decide how to change the weights. The most common approach is gradient descent, and most neural networks train with a variant of it.
One training step
Each pass through the loop has four stages.
- Forward pass. The input moves through the model, layer by layer, to produce an output.
- Loss. The output is compared with the target, giving a loss value.
- Backward pass (backpropagation). The training system works out how much each weight contributed to the error, starting at the output and moving back toward the input.
- Update. Each weight moves a small step in the direction that lowers the loss. The size of the step is set by the learning rate.
Modern frameworks compute the backward pass automatically, so practitioners rarely work out these calculations by hand.
A small numeric example
Take a model with one weight, w, that makes predictions as prediction = w × x. There is one training example with x = 2 and a correct output of 6, so the ideal weight is 3. Start with w = 0, use a learning rate of 0.1, and measure loss as the squared error, (prediction − target)².
| Step | Weight at start | Prediction (w × 2) | Loss |
|---|---|---|---|
| 0 | 0 | 0 | 36 |
| 1 | 2.4 | 4.8 | 1.44 |
| 2 | 2.88 | 5.76 | 0.0576 |
| 3 | 2.976 | 5.952 | 0.0023 |
At step 0 the prediction is 0 and the error is −6. With squared error, the gradient of the loss with respect to w is 2 × error × x, which here is 2 × (−6) × 2 = −24. Moving w in the opposite direction by 0.1 × 24 gives w = 2.4. Each step lowers the loss, and the weight moves toward 3.
The learning rate matters. With a learning rate of 1.0 instead of 0.1, the same first step jumps to w = 24, and the next step jumps to w = −144, moving away from the answer. A step that is too large can overshoot and diverge. A step that is too small can make training very slow.
Why training repeats
One full pass through the training data is called an epoch. Most training uses mini-batches, which are small groups of examples processed together. This makes each update cheaper and somewhat noisier. Training usually runs for many epochs and stops when performance on separate validation data stops improving.
Learning is not memorizing
A flexible model can memorize its training examples, including their noise. This is called overfitting. An overfit model scores well on the data it trained on and poorly on new data.
To catch this, data is usually split into three parts:
- a training set, used to adjust the weights
- a validation set, used to compare models and choose settings
- a test set, kept aside for a final check
Common ways to reduce overfitting include collecting more data, using a simpler model, regularization (which discourages very large weights), dropout (which randomly switches off some units during training), and early stopping.
Settings: what the feedback looks like
Learning setups differ in the kind of feedback they receive.
- Supervised learning uses labeled examples and learns to map inputs to the labels. Several variants are described in “Supervised Learning Types With Examples.”
- Unsupervised learning uses unlabeled data and looks for structure, such as groups of similar items or a smaller set of features that captures most of the variation.
- Reinforcement learning has an agent take actions and receive rewards. It learns to choose actions that tend to earn more reward over time.
- Self-supervised learning creates labels from the data itself. A model might see a sentence with one word hidden and learn to predict it. Large language models are largely trained this way in their first stage.
The same weight-adjusting loop applies to most of these settings, though the way the loss is defined changes.
Where neural networks fit
Neural networks are one family of machine learning models. Each layer computes weighted sums of its inputs, adds a bias, and applies an activation function. The activation function is what lets the stack learn curved and complicated relationships rather than only straight lines. Deep learning refers to neural networks with many layers. Where the line falls between a basic network and a deep one is covered in “The Difference Between Artificial Neural Networks and Deep Neural Networks.”
The learning loop described here applies to neural networks broadly, including large language models. The architectures differ a great deal, but they are trained on the same basic idea: adjust weights to lower a loss.
Once training ends, the weights stop changing. Using the model on new inputs is called inference. For a fuller definition, see “What Is Inference in the Context of AI Models?”
Limits to keep in mind
- A model learns what the data shows, including its gaps, errors, and biases. Skewed training data often leads to skewed predictions, even when the training loss looks good.
- A low loss on training data does not guarantee good results elsewhere.
- Large neural networks can need a great deal of data and computing power to train.
- Learned patterns are statistical associations. A model can be right for reasons that do not carry over to a different setting.
- No single method is best on every problem. “The No Free Lunch Rule in Machine Learning” makes the point that, averaged over every possible problem, no method beats the others.
The short version
Learning in neural networks and machine learning is a repeating cycle. The model predicts, the loss measures the error, and the optimizer adjusts the weights to reduce it. Training sets the weights using example data, and testing on data the model has not seen shows whether the learning carries over. Once that loop is clear, the details of specific models become easier to follow.