How neural networks learn
A neural network learns by guessing, measuring how wrong the guess was, and nudging its weights to be a little less wrong next time.
- 1
Layers of neurons
A network is layers of simple units. Every connection has a weight, a number the network learns.
- 2
Forward pass
Input values flow left to right. Each neuron adds up its weighted inputs plus a bias and applies a nonlinear activation such as ReLU.
- 3
Measure the error
The output is compared with the right answer. A loss function turns the gap into a single number.
- 4
Backpropagation
The error flows backward. Using the chain rule, backpropagation computes for every weight its gradient: how much the loss would change if that weight moved slightly.
- 5
Gradient descent
Each weight moves a small step against its gradient, usually computed on a mini-batch of examples. Optimizers like Adam adapt the step size for each weight.
Layers of neurons
A network is layers of simple units. Every connection has a weight, a number the network learns.
Forward pass
Input values flow left to right. Each neuron adds up its weighted inputs plus a bias and applies a nonlinear activation such as ReLU.
Measure the error
The output is compared with the right answer. A loss function turns the gap into a single number.
Backpropagation
The error flows backward. Using the chain rule, backpropagation computes for every weight its gradient: how much the loss would change if that weight moved slightly.
Gradient descent
Each weight moves a small step against its gradient, usually computed on a mini-batch of examples. Optimizers like Adam adapt the step size for each weight.
In short
- Training is a loop: forward pass, loss, backpropagation and update, repeated over many batches of examples.
- The learning rate sets the step size. Too large and training diverges, too small and it crawls.
- The same idea scales from this toy network to language models with billions of weights.
- Without the nonlinear activations, any stack of layers would collapse into a single linear function.
References
Share
Keep reading
All writingHow transformers and attention work
ExplainerWhat happens inside a large language model: tokens, embeddings, attention and next-token prediction.
5 stepsHow diffusion models generate images
ExplainerImage generators learn to remove noise, then start from pure noise and clean it up step by step.
5 stepsHow fine-tuning with LoRA works
ExplainerWhy LoRA trains a fraction of a percent of the weights and still adapts a model.