How Neural Networks Learn
How Neural Networks Learn
From a Plinko board to a learning machine
A ball dropped onto a Plinko board bounces unpredictably from peg to peg. If the pegs could be adjusted, however, the board might be tuned to guide particular objects to particular exits: a ball to one bin, a cube to another, and a toy dinosaur to a third.
The way to tune the board would be to try, check, and adjust. Send an object through, compare its landing place with the intended bin, and change the pegs when the result is wrong. Repeating that process could make the board better at sorting the objects.
A trained neural network works on the same broad principle. Instead of pegs and bouncing objects, it uses numbers and connected calculations. The network receives an input and produces an output. During learning, its adjustable settings are changed repeatedly so that its outputs become closer to the intended answers.
Learning is a repeated process of making a prediction, checking it against the desired result, and adjusting the network’s settings to reduce the error.
The Plinko analogy also highlights an important distinction: the board does not adjust itself. An outside training process checks the outcome and changes the settings. Neural networks are trained in much the same way.
Think About It
If a board sent one shape to the wrong bin, what would make a useful adjustment: changing a peg without checking the result, or changing it and then testing the shape again?
The simplest neuron: one input and one decision
A neural network is built from small calculation units called neurons. A single neuron can be understood through a simple example: a sound-activated light.
Suppose a microphone represents the sound level in a room with a number from zero to one. Zero represents silence, and one represents a very loud sound. The neuron receives that number and produces a score. The light then turns off or on according to the score.
The neuron multiplies the input by a weight. The weight controls how strongly the input affects the score. If the input is x and its weight is w, the score is:
score=wxFor the light example, the output needs to be a yes-or-no decision. One possible finishing rule is to round the score: values below 0.5 become zero, and values at or above 0.5 become one. Zero means “off”; one means “on.”
That rounding rule is not a universal part of every neural network. The final step depends on the task. A light switch needs a binary decision, while another task may need a probability or a different kind of answer.
Suppose the goal is for the light to turn on whenever the sound level is at least 0.3. With a weight of one, an input of 0.4 produces a score of 0.4. That score is below 0.5, so the light stays off—even though the desired answer is on. The input was right, but the neuron’s setting was not.
One way to fix the problem is to increase the weight. With a weight of about 1.67, an input of 0.3 produces a score just above 0.5:
0.3×1.67≈0.501The light can then turn on at the intended threshold. But a network usually does not begin with the right settings already in place. It must learn them.
Training by trying, checking, and adjusting
To train the light neuron, a collection of example sound levels can be used. For each example, the desired answer is known: below 0.3, the light should be off; at or above 0.3, it should be on.
The training process starts with a weight, tests an example, and checks whether the output is correct. If a sound level should turn the light on but the score is too low, the weight can be nudged upward. If the light turns on when it should stay off, the weight can be nudged downward. Correct answers need no adjustment for that example.
The adjustment is a nudge: a small change to a setting. Repeating the process across examples can move the weight toward a value that works well. In the illustration, the weight eventually settles near 1.67. The network can then be checked on fresh sound levels it did not practise on. Correct answers on new examples show that it has learned a useful pattern rather than merely reacting to the examples it saw during training.
For this simple one-weight problem, a direct calculation could find a suitable answer more quickly. The example is useful because it makes the learning process visible. Real networks can contain millions or even billions of adjustable values, and there is no single formula that solves all those settings at once. A systematic process of trying, checking, and adjusting can be applied even when the network is much larger.
Think About It
Why should a trained neuron be tested on sound levels it did not practise on? Correct answers on practice examples alone may not show whether it learned a general rule.
From one input to a full neuron
Real inputs often consist of many numbers. A sound-activated light might use one sound-level value, but describing an image can require a number for every pixel. A neuron can therefore receive several inputs, each with its own weight.
The neuron multiplies each input by its weight and adds the results into a single total. It may also add a bias, a number belonging to the neuron itself:
z=i=1∑nwixi+bHere, xi is an input, wi is the corresponding weight, b is the bias, and z is the total before the neuron’s final response is calculated.
The bias matters because an input of zero does not always mean that the correct response should be zero. Without a bias, if every input is zero, every weighted input is zero too, and the total must be zero. But zero can still carry useful information. Silence may tell something about a room, and a dark area may tell something about an image. A bias allows the neuron to produce a nonzero total even when all its inputs are zero. During training, both the weights and the bias are adjusted.
The bias can also shift the point at which a neuron changes its response. In the light example, the threshold could be reached by scaling the sound with a weight of about 1.67. Another option is to keep the weight at one and use a bias of −0.3:
z=x−0.3The score is zero when the sound level is 0.3, negative below that, and positive above it. If the neuron’s decision rule turns a nonnegative score into “on,” this bias places the decision point at the desired sound level. Weights scale and combine inputs; biases help set the neuron’s starting point and shift its decision boundary.
The neuron’s response is called its activation. A typical neuron first combines its weighted inputs and bias, then applies a rule that determines its activation.
A neuron’s basic calculation is: weight the inputs, add them together, include a bias, and apply an activation rule.
Why networks need layers and nonlinear activations
One neuron can make only a limited decision. More complex tasks require many neurons working together.
There are two main ways to add neurons. A layer can contain several neurons side by side, all reading the same inputs but using their own weights and biases. Alternatively, one layer can feed into another. In that arrangement, the later layer reads the earlier layer’s activations rather than the original inputs.
The layers between a network’s input and output are called hidden layers. Their number and size are design choices. A layer with more neurons is wider. A network with more successive hidden layers is deeper.
Adding layers alone, however, does not automatically make a network capable of representing complex patterns. The neuron’s calculation must include a nonlinear activation.
Why a stack of linear calculations is still limited
Before an activation is applied, a neuron’s weighted sum plus bias is a linear calculation. Linear calculations are useful, but their outputs are limited to straight-line relationships. Stacking one linear calculation after another does not remove that limitation: the combined result is still linear. Even many layers of linear operations can ultimately represent only another line.
That is not enough for patterns that bend, form peaks, or contain more intricate shapes. To build those patterns, the network needs a nonlinear step.
One common activation is ReLU, short for rectified linear unit. ReLU turns any total at or below zero into zero, while leaving a positive total unchanged:
ReLU(z)=max(0,z)For example, a total of −2 becomes zero, while a total of 3.2 remains 3.2. The result is flat for nonpositive totals and rises for positive ones, creating a bend rather than a single unbroken line.
With nonlinear activations, neurons can combine their responses to form more varied shapes. A few simple responses can combine into a V shape, a peak, or a wave. Further layers can transform those shapes again, allowing the network to represent much more complex patterns.
This layered process can also build useful interpretations in stages. In an image, small visual details may contribute to edges; edges may contribute to shapes such as circles; shapes may contribute to parts such as eyes; and those parts may contribute to a representation of a face. Later stages can reuse patterns discovered by earlier stages. Without such stages, a single layer might need a separate rule for every possible face variation.
Most neurons in modern networks end with a nonlinear activation. ReLU is a common choice, though it is one of many. The central recipe remains: weigh, add, include a bias, and bend the result with a nonlinear rule.
Think About It
Why can a deep stack of linear calculations still be limited to line-like relationships, while nonlinear activations allow more complex patterns?
Choosing a network’s width and depth
Once the basic neuron is understood, a network can be designed by deciding how many hidden layers it will have and how many neurons each layer will contain. For example, a network might have one hidden layer with three neurons, or one with five. It might instead have three hidden layers with three neurons apiece.
A wider layer provides more neurons that can compute different responses from the same inputs. A deeper network provides more stages, with each layer working from the previous layer’s results. Deep learning refers to using networks with several processing layers.
The input and output tasks can remain the same even when the hidden layers change. But neither greater width nor greater depth guarantees better answers. The useful arrangement depends on the task and must be measured rather than assumed.
A handwritten-digit example
A digit-recognition network can be trained to identify handwritten numerals from zero through nine. Handwriting varies from person to person, so the network must learn patterns that remain useful despite those differences.
In the example, each image is a grid of 28×28 pixels, or 784 pixels in total. Each pixel is represented by a brightness value between zero and one. The input layer therefore receives 784 numbers.
The first hidden layer has 32 neurons. Each neuron reads all 784 pixel values through its own set of weights, combines them with a bias, and applies an activation rule. The result is one response per neuron, giving the next layer 32 values to work with.
The output layer has 10 neurons because there are ten possible digits. Each output neuron produces a score for one digit. A finishing step called softmax converts the ten scores into probabilities that add up to one. The digit with the highest probability is the network’s prediction.
Before training, the probabilities may be poorly placed—for example, the correct digit might not have a high score. Training adjusts the weights and biases so that the probability assigned to the correct digit rises while probabilities assigned to incorrect digits fall.
In the described experiment, the network was trained on 60,000 images for five passes through the data. For one shown example, the trained network assigned the correct digit a probability of 98.6%. That probability is a measure of the model’s confidence for that example; it is not, by itself, the same thing as overall accuracy.
A comparison used a network with one hidden layer of 32 neurons and another with two hidden layers of 64 and 32 neurons. On a separate set of 10,000 images that neither network had seen during training, the first network correctly identified 95.58% of the images, while the second correctly identified 96.35%. The second network had about twice as many adjustable values, called parameters. Parameters include all the weights and biases.
The larger network performed better in this particular experiment, but it was both wider and deeper. The result therefore cannot show that depth alone caused the improvement. Nor does one experiment establish that a larger network will always be better.
Think About It
What does a test on previously unseen images reveal that a probability for one training example cannot reveal?
Measuring mistakes with a loss function
To improve a network systematically, training needs a numerical measure of how wrong its prediction is. That measure is called the loss.
Consider a network that should identify a handwritten seven. If it assigns the seven a probability of 100% and every other digit a probability of zero, it is perfectly right for that example, so the loss should be zero. If it gives the correct digit a smaller probability, the loss should be larger. A useful loss function therefore gives a larger penalty when the correct answer is assigned a smaller probability.
A common choice for this kind of classification task is cross-entropy loss. For one correct class with predicted probability p, the loss is:
L=−ln(p)When p=1, the loss is zero. As p approaches zero, the loss rises sharply. In the small demonstration, the network assigned the correct digit a probability of about 9%, producing a loss of about 2.37. A lower cross-entropy means that the network’s predictions are closer to the desired answers.
Different tasks can use different loss functions. Cross-entropy is the choice used in this digit-recognition demonstration because it penalizes low probabilities for the correct class in the desired way.
Derivatives, slopes, and backpropagation
Once the loss is known, training needs to determine how each weight and bias affects it. A small change to one parameter may improve the prediction or make it worse. The amount and direction of that effect are described by a derivative, or slope.
A derivative answers a question such as: if one quantity changes slightly, how much does another quantity change? For a neuron with input x, weight w, bias b, and output y,
y=wx+bIf the input is 5, the weight is 2, and the bias is 1, the output is 11. Raising the weight by one changes the output to 16, a change of 5. That change equals the input. Thus, the derivative of the output with respect to the weight is the input:
∂w∂y=xRaising the bias by one changes the output by one, so:
∂b∂y=1Raising the input by one changes the output by the weight, so:
∂x∂y=wThese examples show what derivatives measure: the sensitivity of one quantity to a change in another.
Following a slope backward through a network
A small network can have two neurons in sequence. The first produces an intermediate value, and the second uses that value to produce the final output:
x2=w1x1+b1 x3=w2x2+b2A loss function then compares the final output x3 with the expected answer. To improve the network, training needs the slope of the loss with respect to every weight and bias.
The loss directly depends on the final output, so the first step is to find how the loss changes when x3 changes. From there, the chain rule carries that information backward through the calculations. For example, the slope with respect to the second weight is:
∂w2∂L=∂x3∂L∂w2∂x3The first factor tells how the loss responds to a change in the output. The second tells how the output responds to a change in the weight. Multiplying them gives the weight’s effect on the loss.
The same idea applies to the second bias. Then the calculation determines how a change in the intermediate value x2 affects the loss. That information is passed back to the first neuron, where it can be combined with the first neuron’s local derivatives to find the slopes for w1 and b1.
At each step, the process has two parts:
- Multiply the slope arriving from later in the network by the local derivative for the current calculation.
- Keep the resulting slopes for the current neuron’s weights and bias, and pass the slope for its input backward.
The key benefit is that a layer does not need to recalculate all the work performed by later layers. The slope passed backward already summarizes how those later calculations affect the loss.
This systematic backward calculation is called backpropagation. It measures the slope for every weight and bias in the network in one backward pass. It does not itself change the network’s settings, and it does not tell each neuron what its output should be. It only calculates how the loss would respond to changes in the settings.
Backpropagation measures the effect of each parameter on the loss; a separate update process uses those measurements to change the parameters.
From individual slopes to a gradient
For a network with many parameters, backpropagation collects all the slopes into a list called the gradient. Each entry describes how sensitive the loss is to one weight or bias, assuming the other parameters stay fixed while that sensitivity is measured.
Finding the slopes one parameter at a time would be extremely costly. In the small demonstration, there were 38 adjustable values. A digit network had 25,450 weights and biases, and training involved 2,345 updates. Changing one parameter at a time and rerunning the network would require nearly 60 million full reruns. Modern networks may have billions of weights. Backpropagation makes the computation practical by finding all the slopes together in a backward pass.
Think About It
Why is it useful to pass a slope backward from one layer to the previous layer instead of recalculating the entire network separately for every parameter?
Gradient descent: using the slopes to learn
After backpropagation measures the gradient, the parameters can be updated. The method that uses the slopes to move parameters in a direction that reduces loss is called gradient descent.
A large slope means the loss is sensitive to that parameter, while a small slope means it is less sensitive. A learning step moves all the weights and biases at once, with each movement guided by its slope.
The step size is controlled by the learning rate, a shared setting that determines how large each update should be. In simplified form, a parameter θ is updated by:
θnew=θold−η∂θ∂LHere, η is the learning rate. The minus sign indicates movement opposite the slope, toward lower loss.
Steps cannot be too large. A slope describes the loss near the current settings; if the settings change dramatically, that local measurement may no longer be reliable. But steps cannot be too small either. Tiny steps make learning slow and can leave the network stuck in a shallow low point, even when a better solution lies beyond a rise in the loss.
The learning rate is therefore chosen by experimentation: take a step, check the result, and adjust the rate if needed. In the example, a learning rate of 0.2 reduced the loss from 2.37 to 2.08 after one update. The network still predicted the wrong digit, but it had improved. Training repeats the process across many examples.
Batches and epochs
A single update based on one example may help that example while harming another. If two examples suggest opposite changes to a weight, training can calculate the gradient for each example and average the suggested changes. The examples handled together are called a batch. The network then makes one shared update based on the batch.
An epoch is one complete pass through the training data. Training usually involves many batches per epoch and many epochs overall. In the digit example, each pass through the training images involved hundreds of updates, and the loss eased down over successive passes.
The learning rate has a strong effect on this process. In an illustration using two examples, a rate of 0.05 made only a small improvement, while a rate of 2 produced a larger reduction in loss. A rate of 20 made the loss explode instead of fall. The step was so large that it overshot the region where the measured slopes could guide it reliably.
In practice, training involves repeated batches, appropriately sized steps, and multiple passes through the data.
Think About It
Why might a learning rate that seems to make progress at first eventually be too large for reliable learning?
Generalization, overfitting, and held-back data
A network can improve on the examples it trains on while becoming worse on new examples. This happens when it starts memorizing the training data rather than learning patterns that generalize.
To detect this, data can be separated into distinct groups:
- Training data is used to adjust the network’s parameters.
- Validation data is kept out of training and used to monitor performance during training.
- Test data is held back until the end to provide a final evaluation.
A smaller experiment used only about 1,000 training images and compared a narrow network with a wider one. The wider network’s training loss kept falling, but its validation loss eventually turned upward. That change indicated that the network was moving away from useful general learning and toward memorization.
The validation data identified the best point as epoch ten. The network was saved at checkpoints during training, and the version from that point was selected. It was then evaluated once on the test data, achieving 88.83% accuracy. Choosing the version preferred by the validation data rather than the final version is called early stopping.
Several approaches can help reduce memorization:
- Use more training examples. More examples and greater variety leave less room for simply memorizing particular cases. In the described digit experiment, a similar network trained on 60,000 images achieved 95.58% accuracy.
- Choose a network size that fits the data. A smaller network may memorize less, though it may also learn less.
- Add penalties that discourage extreme weights.
- Randomly silence some neurons during training so that the network does not rely too heavily on one path.
- Create additional variety by stretching, shifting, or tilting training images.
These approaches share the same aim: help the network learn patterns that work on new data, not just details of the training examples. The final verdict comes from data the network has not used to adjust itself.
Why neural networks use matrices and GPUs
A network’s calculations can be organized into matrices, which are rectangular grids of numbers. For one layer, each connection has a weight. The weights can be arranged so that each row corresponds to an input and each column corresponds to a neuron.
For a single example, the weighted input to each neuron is found by multiplying the inputs by the corresponding weights and adding the products. Doing this for every column at once is a matrix multiplication. The bias and activation are then applied to the result for each neuron.
A layer with 784 inputs and 32 neurons can use a weight matrix with 784 rows and 32 columns. If a batch of examples is arranged as rows in another matrix, one multiplication can compute the weighted sums for every example and every neuron in the batch.
The arithmetic in the resulting grid consists of many independent multiply-and-add calculations. They can be carried out simultaneously. The next layer must still wait for the previous layer’s results, but computations within a layer can run in parallel.
That structure suits a graphics processing unit, or GPU. A central processing unit, or CPU, is designed to handle a broad range of tasks. A GPU is designed to perform many similar calculations at once. At the scale of neural networks, the parallel calculations in matrix operations make GPUs useful for training.
Modern language models can contain billions of weights. Their training uses the same broad loop—make predictions, measure errors, and adjust parameters—but at a much larger scale and with more elaborate architectures. Training can take days or weeks and use thousands of processors working together.
How the same ideas apply to language
A language model must first convert text into numbers, just as an image network receives pixel brightness values. Text is divided into tokens: chunks that may be whole words, parts of words, or punctuation. The exact divisions depend on the tokenizer.
Each token has a learned list of numbers, often called its representation. These numbers are adjusted during training along with the network’s weights and biases.
A common task is to predict what token comes next, given the tokens that came before. The preceding text is the context. The model produces scores for possible next tokens, and softmax converts those scores into probabilities. The model can choose the token with the highest probability or sample from the probabilities so that a less likely token can sometimes be selected. The chosen token is added to the text, and the process is repeated.
Training can use real text by asking the model to predict a next token that is already known. The known next token provides the correct answer. The loss measures how much probability the model assigned to it; backpropagation calculates the gradients; and an optimizer adjusts the weights, biases, and token representations.
Next-token prediction is not the only task language models can learn. Networks can also be trained to translate, summarize, or answer questions. Modern language models include additional mechanisms, especially attention, which helps the model decide which earlier words matter most for the current prediction. The shared foundations remain prediction, error measurement, and adjustment.
Review: one learning process, many forms
The Plinko board provides a useful picture of neural-network learning: try a setting, check the outcome, and adjust when the result misses the target. In a network, the adjustable settings are weights and biases, and the outcomes are calculated from numerical inputs.
A neuron combines weighted inputs, adds a bias, and applies an activation. Layers place neurons side by side or in sequence. Nonlinear activations let successive layers represent patterns more complex than straight-line relationships. The network’s width and depth are design choices whose value must be tested.
During training, a loss function measures how far predictions are from desired answers. Derivatives describe how each parameter affects the loss. Backpropagation calculates those sensitivities throughout the network, and gradient descent uses them to adjust all the parameters. Batches and epochs organize the repeated learning process, while the learning rate controls the size of each update.
Validation and test data reveal whether a network has learned a general pattern or merely memorized its practice examples. Matrix multiplication makes the calculations efficient, and GPUs perform the many similar operations in parallel. The same underlying principles support networks for images, speech, and language.
Across these applications, the central cycle remains the same: make a prediction, compare it with the desired result, measure how the settings affect the error, and nudge the settings toward better answers.

Ask anything
We've read this whole study set, so questions about it get the best answers.