Neural networks
What a neural network actually computes: weighted sums, a bend, and layers. One tiny network with nine numbers is worked through by hand, then we see why the bend matters and how the numbers are learned.
In 30 seconds
A neural network is built from neurons. Each one multiplies its inputs by weights, adds a bias, and passes the total through a simple bend called an activation function.
Neurons are arranged in layers. Feeding numbers in at one end and computing layer by layer to the other is the forward pass.
The bend is essential: without it, any stack of layers is no more powerful than a single straight-line formula. The weights are not written by people. Training nudges them, over and over, to make the outputs less wrong.
Neural networks, step by step
The weights here were chosen by hand so the sums stay easy. ReLU is one of several activation functions, and real networks have thousands to billions of weights.
- Step 1: One neuron: a weighted sum. A neuron is a small calculation. It multiplies each input by a weight, which says how much that input counts, adds the results, and adds one more number of its own, the bias, which shifts the total up or down. With inputs 1 and 1, weights 2 and 2 and bias −2, the sum z is 2.
- Step 2: Then an activation. Before passing its sum on, the neuron puts it through an activation function. A common one is ReLU: negative sums become 0, positive sums pass through unchanged. With inputs 0 and 0 the same neuron gets z = −2 and outputs 0. That kink at zero is what makes the function non-linear.
- Step 3: Neurons in layers. A network is neurons wired in layers. The inputs feed two hidden neurons, h1 and h2, and their outputs feed one output neuron, y. Every arrow carries a weight and every neuron has a bias: nine numbers in all. Those nine numbers are the whole network; change them and it computes something else.
- Step 4: Forward pass: hidden layer. Running the network is called a forward pass: feed in the inputs and compute layer by layer. With x1 = 1 and x2 = 1, hidden neuron h1 sums 1 + 1 + 0 = 2 and h2 sums 2 + 2 − 2 = 2. Both sums are positive, so ReLU passes them on unchanged.
- Step 5: Forward pass: output. The output neuron treats the hidden values as its inputs: 1×2 + (−1)×2 + 0 = 0. Repeat the pass for the other inputs and a pattern appears: the output is 1 when exactly one input is 1, and 0 otherwise. This pattern is called XOR, a famous test case: no single neuron can produce it.
- Step 6: Why the bend matters. Remove ReLU and the layers collapse: a weighted sum of weighted sums is just one weighted sum, here y = 2 − x1 − x2. Plotted against x1 + x2 that is a straight line, and no straight line goes up and then down. ReLU lets h2 switch on part-way, which bends the output. More neurons and layers stack more bends into richer shapes.
- Step 7: Training, in one line. Nobody picks the weights by hand. They start random. Training runs a forward pass on an example, measures how wrong the output is (the loss), works out for every weight which direction would shrink the loss, and nudges each weight a little that way. Repeated over many examples, the loss falls and the weights settle.
Try it yourself
Learn this first
Learn next
- Recurrent neural networks and LSTMsA network with a loop remembers a sequence, forgets too fast, and gains gates to fix it. Intermediate
- The attention mechanismA word scores every other word, turns the scores into shares, and blends what they offer. Intermediate
- Pre-training vs fine-tuningTrain once on a mountain of raw text, then briefly on a small labelled set for one job. Beginner
Spotted a mistake on this page?