How Neural Networks Learn
Neural Networks: Structure, Learning, and Applications
1. Learning as repeated adjustment
A Plinko board illustrates the basic idea of learning. A ball bounces unpredictably among pegs and eventually reaches an exit. If the board’s pegs could be adjusted, their positions could guide different objects—such as a ball, a cube, or a toy dinosaur—to different exits.
The learning process would be:
Send an object through the board.
Check which exit it reaches.
Compare that exit with the intended one.
Adjust the pegs if the result is wrong.
Repeat with other objects.
A board whose peg settings have been adjusted to sort objects is analogous to a trained neural network. The network receives an input and produces an output; training repeatedly compares the output with the desired answer and adjusts the network’s internal settings.
Real neural networks do not use pegs or bouncing objects. They use numbers and connected mathematical calculations. The analogy captures the essential pattern: try, check, and adjust. The board itself does not know how to improve; an external process checks its results and changes its settings.
2. A neuron’s basic calculation
A neuron is a small computational unit. At its simplest, it takes a number as input, scales it, and produces a response.
A one-input example: a sound-activated light
Suppose a microphone measures the sound level in a room as a number from 0 to 1:
0 represents silence.
1 represents a very loud sound.
The neuron’s output controls a light:
0 means off.
1 means on.
The neuron multiplies the sound level by a weight. The weight determines how strongly the input affects the neuron’s score. In this simplified example, the score is rounded to decide whether the light turns on:
A score below 0.5 rounds to 0.
A score of 0.5 or higher rounds to 1.
This rounding step is a choice for the light-switch example, not a required part of every neural network. Different tasks use different output-processing steps.
Suppose the light should turn on whenever the sound level is at least 0.3. With a weight of 1, an input of 0.4 produces a score of 0.4,whichroundsdownto0$. The output is wrong: the light stays off even though the sound is above the desired threshold.
Increasing the weight can correct the result. A weight of approximately 1.67 scales the sound level so that an input of 0.3 produces a score near 0.5, enough to turn the light on. The neuron’s setting has been adjusted to better match the desired behavior.
Training through examples
A simple way to find a useful weight is to practice on examples whose correct answers are known:
For an input of 0.4, the desired output is on. If the neuron says off, its score is too low, so the weight should increase.
For an input of 0.2, the desired output is off. If the neuron already says off, no correction is needed.
For an input of 0.36, the desired output is on. If the neuron says off, the weight should increase.
For an input of 0.28, the desired output is off. If the neuron says on, the neuron is too sensitive, so the weight should decrease.
This repeated process of checking examples and modifying settings is training. In a real neural network, the adjustments are usually calculated mathematically rather than chosen by hand. The example nevertheless shows the basic purpose of training: change internal settings so that the network’s outputs better match desired answers.
3. Multiple inputs, weights, and bias
Real data usually contains many numbers. An image, for example, can be represented by one brightness value for each pixel. A neuron that receives several inputs assigns a separate weight to each one, combines their weighted values into a score, and produces an output called its activation.
For inputs x1,x2,…,xn, weights w1,w2,…,wn, and a bias b, the score before activation is:
The terms wixi represent the weighted inputs. The neuron adds them together and then adds its bias. A further rule, called an activation function, may transform this score into the neuron’s final output.
Why a neuron needs a bias
Without a bias, a neuron receiving only zero-valued inputs must produce a score of zero: every input multiplied by its weight is zero. But zero can carry meaningful information. Silence can tell something about a room, and a dark image region can be informative.
The bias is a number added by the neuron itself. It gives the neuron a starting score even when every input is zero. Training adjusts both the weights and the bias.
A bias can also shift a neuron’s decision boundary. In the sound-light example, the same threshold behavior can be described in two ways:
Scale the sound with a weight of about 1.67 and use the original output threshold.
Keep the weight at 1 and use a bias of −0.3, making the score the sound level minus 0.3.
In the second version, the light turns on when the score is at least zero. The bias shifts where the neuron’s decision changes, while the weight controls how strongly the input affects the score.
A neuron’s basic calculation combines weighted inputs with a bias, then applies an output rule. Training adjusts the weights and bias to improve the neuron’s behavior.
4. Layers and the need for nonlinear activation
One neuron can make only a simple decision. More complex tasks require multiple neurons working together.
Growing a network in two directions
A network can become larger in two main ways:
Wider: Multiple neurons can read the same inputs side by side. Each neuron has its own weights and bias and produces its own response. A group of neurons at the same processing stage forms a layer.
Deeper: A later layer can read the outputs of an earlier layer rather than the original inputs. This creates a sequence of stages, with each stage building on the preceding one.
A layer’s output therefore becomes the next layer’s input. Deeper networks can construct more complex representations through successive processing.
Why stacking linear operations is not enough
The calculation “multiply by weights and add a bias” is linear. Linear equations can represent lines, but chaining linear operations together still produces a linear operation. A long sequence of such layers can shift, tilt, or reverse the resulting line, but it cannot produce a fundamentally more complex boundary.
Consequently, a network made only of linear calculations cannot represent many complex patterns, regardless of how many linear layers are stacked.
ReLU and nonlinear behavior
A network gains greater representational power by applying a nonlinear rule to neuron outputs. One common rule is ReLU, short for rectified linear unit. It sets nonpositive scores to zero and lets positive scores pass through unchanged:
For example:
If z≤0, the activation is 0.
If z=3.2, the activation is 3.2.
ReLU’s graph is flat at zero for nonpositive inputs and rises linearly for positive inputs. This bend makes the overall network nonlinear. Combining and stacking such nonlinear responses lets a network represent patterns more complex than a line.
Layers as stages of feature building
Different inputs can activate different combinations of neurons. Each layer can use the preceding layer’s responses to build more useful features:
Early processing might detect dots or edges.
Later processing might combine edges into shapes such as circles.
Further stages might use shapes to identify parts such as eyes.
Later stages might combine parts to recognize a face.
The example illustrates feature reuse: a deeper network can learn a useful component once and use it in many later combinations. A single layer would have to represent many complete patterns directly, potentially requiring an enormous collection of separate rules.
Nearly every neuron in a typical network uses a nonlinear activation function. ReLU is one of the most common choices, though other nonlinear functions also exist. Modern networks may add further mechanisms, but the central sequence remains: weight inputs, add them, include a bias, and apply a nonlinear rule.
5. Network architecture: width and depth
A network’s architecture describes how its layers are arranged, including how many neurons each layer contains.
The input and output layers are determined by the task. Layers between them are called hidden layers because they perform intermediate processing. A network might have:
One hidden layer with three neurons.
One wider hidden layer with five neurons.
Three hidden layers with three neurons each.
A wider layer has more neurons calculating from the same preceding inputs. A deeper network has more processing stages, with each layer working on the results of the layer before it.
Networks with several processing layers are commonly described as deep learning. Neither added width nor added depth automatically guarantees better results. Architectural choices must be evaluated by measuring performance on appropriate data.
6. Worked application: recognizing handwritten digits
Handwritten-digit recognition shows how the basic components fit together in a practical network.
Representing an image as numbers
A handwritten digit can look different depending on who wrote it. To a network, the image is represented as a grid of pixel values. A 28×28 image has 784 pixels, and each pixel’s brightness is represented by a number from 0 to 1.
The input layer therefore contains 784 numbers, one per pixel. The image determines the input size.
Hidden and output layers
In one example architecture:
The hidden layer has 32 neurons.
Each hidden neuron receives all 784 pixel values, with its own 784 weights and its own bias.
Each neuron applies the usual weighted-sum, bias, and activation calculation.
Each hidden neuron outputs a number describing how strongly it responded.
The output layer contains 10 neurons, one for each digit from 0 through 9. Each output neuron reads the 32 hidden-layer responses and produces a score for its digit.
The scores are converted into probabilities using softmax. Softmax produces values that add up to 1, allowing the outputs to be interpreted as a probability distribution across the ten digit classes. The digit with the largest probability is the network’s prediction.
A common mathematical form of softmax is:
Here, si is the score for digit i, and pi is its softmax probability. Because each probability is nonnegative and the probabilities sum to 1, they can be compared as competing estimates for the image’s class.
Training and evaluating the digit network
Before training, the network’s probabilities may be poor. Training aims to increase the probability of the correct digit and decrease the probabilities of incorrect digits by adjusting the weights and biases.
In the described experiment, a network was trained on 60,000 images for five passes. For one example of a handwritten seven, the probability assigned to seven rose to 98.6%, making seven the highest-probability answer.
A second network used two hidden layers, containing 64 and 32 neurons. The networks were then evaluated on 10,000 images neither had seen during training:
The network with one hidden layer achieved 95.58% accuracy, correctly identifying 9,558 images.
The network with two hidden layers achieved 96.35% accuracy, correctly identifying 77 more images.
The larger network had about twice as many adjustable values. The adjustable weights and biases together are called the network’s parameters. Because the second network was both wider and deeper, the result does not show that depth alone caused the improvement. It also does not prove that larger networks always perform better. The result applies to that experiment, architecture, and dataset.
7. Loss: measuring how wrong an answer is
Training needs a numerical way to assess a network’s output. A single measure of error for a particular example is called the loss.
For digit classification, a desirable loss should have these properties:
It should be zero or very small when the correct class receives probability 1.
It should increase as the probability assigned to the correct class decreases.
A common choice is the negative logarithm of the correct class’s probability. For correct-class probability p, the loss is:
This function rises steeply as p approaches zero. If a network gives the correct answer only about 9% probability, the loss is approximately 2.37 in the example. A higher probability for the correct answer produces a smaller loss; a lower probability produces a larger loss.
This loss is a form of cross-entropy, a widely used choice for classification. Other tasks may use other loss functions, since the loss needs to reflect what counts as a useful answer for that task.
8. Slopes, derivatives, and the gradient
Once the loss is measured, training needs to determine how changing each parameter would affect it.
A direct experiment can estimate this effect for a single weight:
Run the network and record its loss.
Increase one weight by a small amount.
Run the network again.
Compare the new loss with the old one.
If increasing a weight makes the loss fall, increasing it helps. The size of the change indicates how strongly the loss responds to that weight. This direction and strength together describe the weight’s slope.
More generally, a derivative measures how much one quantity changes in response to a change in another. For a neuron with input x, weight w, and bias b,
the derivatives are:
These relationships follow directly from the equation:
Changing the weight by one changes the output by the input’s value.
Changing the bias by one changes the output by one.
Changing the input by one changes the output by the weight.
The collection of derivatives of the loss with respect to all weights and biases is called the gradient. It summarizes how each parameter influences the loss at the current settings.
9. Backpropagation: calculating slopes efficiently
A network may have many thousands, millions, or billions of parameters. Testing each parameter separately by changing it and rerunning the entire network would be far too slow.
Backpropagation calculates the loss’s derivatives for all parameters efficiently by working backward through the network.
The chain rule
Consider two neurons in sequence:
The network’s answer is x3, and the loss depends on that answer. To find how a parameter in an earlier calculation affects the loss, the derivative is passed through the intervening calculations using the chain rule. For instance:
The first factor describes how the loss responds to the final output. The second describes how the final output responds to w2. Multiplying them gives the effect of w2 on the loss.
The same method carries the effect backward to the preceding neuron:
The derivative ∂x2∂L already incorporates the effects of calculations downstream from x2. The preceding layer can therefore use that carried derivative rather than recomputing all later effects from scratch.
The backward pass through a network
At each layer, backpropagation follows the same pattern:
Start with the derivative of the loss with respect to the layer’s output.
Calculate derivatives for the layer’s weights and biases and keep them as that layer’s parameter slopes.
Calculate how the loss depends on the layer’s inputs.
Pass those input slopes backward to the preceding layer.
A neuron’s input may feed several neurons in the following layer. In that case, its incoming slope includes the contributions from all those downstream paths, which are added together.
After a single backward pass, the network has a slope for every weight and bias. Backpropagation itself does not change the parameters. It only measures how the loss responds to them. It also does not tell individual neurons what their outputs should be; it calculates how parameter changes affect the overall loss.
For a small network with 38 parameters, individual tests might seem manageable. For a larger example with 25,450 parameters and 2,345 updates, one-at-a-time testing would require nearly 60 million full network reruns. Backpropagation obtains the needed slopes through backward passes instead.
10. Gradient descent and the learning rate
Once the gradient has been calculated, the parameters can be updated to reduce the loss. This process is called gradient descent.
For a parameter θ with loss derivative ∂θ∂L, a basic update is:
Here, η is the learning rate. The negative sign means that the update moves in the direction expected to reduce the loss. All weights and biases can be updated together using their respective slopes.
A larger slope indicates a stronger local effect on the loss, so it leads to a larger parameter adjustment for the same learning rate. A small slope leads to a smaller adjustment.
Choosing a learning rate
The learning rate controls the size of the update:
If it is too small, learning progresses slowly. Very small steps can also fail to get out of a shallow local dip.
If it is too large, the parameter changes may overshoot the region described by the measured slopes, causing the loss to increase or behave unstably.
The example network used a learning rate of 0.2, so each parameter moved by one fifth of its slope in the update direction. There is no universal formula that selects the best rate for every network and task. It is generally selected by trying values, measuring results, and adjusting.
In one demonstration, a single update reduced the loss from 2.37 to 2.08, even though the network still chose the wrong digit. Training can improve an answer before it makes the answer correct.
The slope is a local measurement: it estimates the loss’s sensitivity to one parameter while the other parameters remain fixed. If all parameters move only a little, the measurement remains useful. Large simultaneous changes can make the original slopes less reliable, which is another reason updates should not be too large.
11. Batches and epochs
A parameter change that helps one training example may harm another. Training must therefore account for multiple examples rather than relying on just one.
For a group of examples, the network can calculate a gradient for each example and average the suggested changes. It then makes one shared update. A group processed together is called a batch.
Training continues batch by batch. Once every example in the training dataset has been processed, the network has completed an epoch—one full pass through the training data.
The learning rate remains important when updates are based on batches. In one comparison using the same two examples and starting parameters:
At a rate of 0.05, the loss changed only from 2.00 to 1.97.
At a rate of 2, the loss dropped to 0.92.
At a rate of 20, the loss increased to 8.99.
The very large update went far beyond what the measured slopes could reliably guide. In practice, training uses repeated updates on batches and multiple passes through the data, with a learning rate that allows useful progress without destabilizing learning.
12. Overfitting and the use of held-out data
A network can perform increasingly well on its training images while performing worse on new images. This happens when it starts overfitting: rather than learning patterns that generalize, it begins to memorize details of the training examples.
Training, validation, and test data
A common approach separates data into three sets:
Training data are used to update the network’s parameters.
Validation data are not used for those updates. They are checked during training to monitor performance on examples the network is not practicing on.
Test data are held back for a final evaluation and are used only at the end.
The distinction matters because repeated decisions based on test results would turn the test set into another source of feedback, weakening its value as an independent final check.
Early stopping
In a deliberately data-limited experiment, a network trained on about 1,000 images continued to reduce its training loss, while its validation loss began to rise. The validation results showed that the network was moving from learning useful patterns toward memorizing the training images.
The validation set identified epoch ten as the best point. The network saved at that point achieved 88.83% accuracy on the test set. Continuing to train beyond epoch ten was not better, so the saved earlier version was used. This practice is called early stopping: training ends, or the saved model is selected, at the point that validation performance is best.
Other ways to reduce overfitting
Several strategies can help a network learn patterns rather than memorize particular training examples:
More training data: A wider variety of examples makes memorization less useful. A network trained on all 60,000 images in the earlier digit experiment reached 95.58% accuracy, compared with the poorer result from the limited-data experiment.
Appropriate model size: A larger network can represent more patterns, but it may memorize more easily. A smaller network may overfit less while also learning less.
Penalties on extreme weights: Regularization can discourage parameters from becoming excessively large.
Randomly silencing neurons during training: This makes it harder for the network to depend on a single path or memorized combination.
Data augmentation: Training images can be shifted, tilted, or otherwise transformed to create useful variation.
All of these methods aim to help the network learn general patterns. Their effectiveness must ultimately be judged using data the network has not trained on.
13. Matrix multiplication and parallel computation
A network’s calculations can be organized into matrix operations. This organization is important both mathematically and computationally.
Weights as a matrix
For one layer, weights can be arranged in a grid:
Each row corresponds to an input.
Each column corresponds to a neuron.
A grid of numbers is a matrix. For each neuron, multiplying the inputs by the weights in its column and adding the results produces that neuron’s weighted sum. Calculating the weighted sums for all neurons in a layer is a matrix multiplication. The biases and activation functions are then applied to the resulting neuron values.
For the first layer of the digit network, the weight matrix has 784 rows and 32 columns: one row per pixel input and one column per hidden neuron.
Batches and parallelism
A batch can be represented by stacking several examples as rows in another matrix. A single matrix multiplication can then compute the weighted sums for all neurons and all examples in the batch.
Each cell in the result depends on its own set of multiply-and-add calculations. These calculations can be performed independently and simultaneously, making matrix operations well suited to parallel hardware. Layers still have to be processed in sequence because a later layer needs the previous layer’s outputs. Thus, computation can be parallel within a layer while proceeding one layer after another.
A CPU is a general-purpose processor designed to handle many kinds of tasks. A GPU is designed to perform many similar calculations in parallel. For large neural-network matrix operations, GPUs can be especially effective.
This computational structure matters at scale. Modern language models can contain billions of weights, and their training still follows the same broad loop—predict, check, and adjust—implemented through gradient-based methods. Large training runs can require thousands of processors operating over days or weeks.
14. Language models and next-token prediction
Language models apply the same network principles to text. Before a network can process text numerically, text must be converted into numbers.
Tokens and learned representations
Text is split into tokens, which may be whole words, parts of words, or punctuation. The exact divisions depend on the tokenizer. Each token is assigned a learned list of numbers, called its representation. These numbers are adjusted during training, alongside the network’s weights and biases.
Predicting what comes next
A language model uses the preceding text, or context, to estimate what token is likely to come next. It produces a score for each token in its vocabulary. Softmax converts the scores into probabilities, just as it converts the ten digit scores into probabilities in digit recognition.
The next token can be selected in different ways:
Choose the token with the highest probability.
Sample from the probability distribution, which sometimes allows a less likely token to be chosen.
The chosen token is added to the text, and the model predicts again using the expanded context.
Training language models
A basic next-token training process takes real text and asks the model to predict a missing or next token. The actual next token provides the correct answer. The loss measures how much probability the model assigned to that answer; backpropagation calculates the parameter slopes; and an optimizer updates the model’s weights, biases, and learned token representations.
Next-token prediction is not the only task language models can learn. Networks can also be trained for translation, summarization, and question answering. Modern language models add mechanisms beyond the basic network described here. One major example is attention, which helps a model determine which earlier words in the context are most relevant.
15. The shared principle across neural networks
Neural networks are used for tasks including digit recognition, object detection, image understanding, speech processing, and language modeling. Their architectures and output procedures can differ, but they share a central pattern:
Convert the input into numbers.
Process those numbers through connected layers of weighted calculations.
Compare the result with a desired or observed answer using a loss.
Use backpropagation to measure how parameters affect that loss.
Update the parameters with an optimizer.
Repeat and evaluate performance on data the network has not seen.
The Plinko analogy captures this loop: a setting is tried, the result is checked against the goal, and the settings are adjusted. In a neural network, the adjustable settings are parameters such as weights and biases, and the adjustments are calculated from the loss.
A neural network is a stack of mathematical operations whose parameters are tuned through repeated measurement and adjustment. Its responses are not perfect, but training can make them progressively better.

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