Key takeaways

  • A neural network is layers of simple units that multiply inputs by weights, add them up and pass the result on; training tunes those weights from examples.
  • Backpropagation, popularized by Rumelhart, Hinton and Williams in 1986, computes how to change every weight, and gradient descent makes the change.
  • Large language models are transformer neural networks: GPT-3 had 175 billion parameters, while a textbook digit reader has about 23,860.

A neural network is a computer program that learns a task from examples instead of following rules someone wrote. It is made of many small units, called neurons, that multiply their inputs by numbers called weights, add them up and pass the result on. Training nudges those weights until the answers match the examples. Every large language model, ChatGPT, Claude and Gemini included, is a neural network.

One neuron: weigh the evidence, then decide

The classic artificial neuron is the perceptron, which Frank Rosenblatt described in a 1958 paper in Psychological Review. It multiplies each input by a weight that says how much that input matters and adds them up. Above a threshold it outputs 1, below it 0. Michael Nielsen's free textbook Neural Networks and Deep Learning calls it "a device that makes decisions by weighing up evidence."

Modern neurons make one change. They pass the sum through a smooth activation function, so a small change in a weight makes a small change in the output, which is what lets a network learn. The textbook Deep Learning by Goodfellow, Bengio and Courville names the ReLU, which outputs the sum when it is positive and zero otherwise, as the default today.

Each neuron also adds a bias, a number that shifts how easily it fires. Weights and biases together are the parameters. When a model is said to have 175 billion parameters, these are the numbers.

Layers: how neurons become a network

Neurons are stacked in layers. The input layer holds raw data, such as pixels. Hidden layers each take the previous layer's outputs as inputs; nobody tells them what to compute. The output layer gives the answer.

Nielsen's example reads handwritten digits from the MNIST dataset. Each image is 28 by 28 pixels, so the input layer has 784 neurons. A hidden layer has 30 neurons, and the output layer has 10, one per digit. That is about 23,860 weights and biases. The PyTorch tutorial builds a similar network in a few lines of Python: 784 inputs, two hidden layers of 512 and 10 outputs, with a ReLU between layers.

"Deep learning" means networks with many hidden layers. Deep Learning notes that networks have doubled in size roughly every 2.4 years since hidden units were introduced.

How a neural network learns: gradient descent and backpropagation

A new network starts with random weights. Training repeats four steps:

  1. Forward pass. Run a training example through the layers to get an answer.
  2. Measure the error. A loss function scores how far the answer is from the right one.
  3. Backward pass. Work out, for every weight, which way to move it to shrink the error. That direction is the gradient.
  4. Update. Move every weight a small step that way. The step size is the learning rate.

This is gradient descent: walking downhill on the error. Networks use stochastic gradient descent, which estimates the gradient from a small random batch of examples. Nielsen's numbers: with 60,000 training images and batches of 10, each estimate costs 6,000 times less to compute.

Step 3 is backpropagation. It uses the chain rule from calculus to pass the error backward through the layers, finding every weight's gradient in one sweep. Nielsen notes it was introduced in the 1970s but took off with a 1986 Nature paper by David Rumelhart, Geoffrey Hinton and Ronald Williams. That paper showed hidden units learning useful features of a problem on their own, with nobody telling them what to look for. Deep Learning adds that backpropagation only computes the gradient; an optimizer such as stochastic gradient descent does the learning. PyTorch's autograd computes gradients automatically.

Nielsen's 784-30-10 network, trained for 30 passes with a learning rate of 3.0, read 95.42% of 10,000 test digits correctly at its best. With 100 hidden neurons it reached 96.59%. With a learning rate of 0.001 or 100, it did about as well as guessing.

The main kinds of neural networks

Kind Built for Key idea Landmark
Feedforward (MLP) Simple classification Data flows one way, every neuron connects to the next layer Rumelhart, Hinton and Williams, 1986
Convolutional (CNN) Images and other grids Small filters slide across the input, reusing weights LeCun, 1989; AlexNet, 2012
Recurrent (RNN) Text, speech, time series Feeds its state back in as memory LSTM
Transformer Language and other sequences Attention: each word looks at every other word Vaswani et al., 2017

Feedforward networks, or multilayer perceptrons, are the kind above: no output is fed back into the model.

Convolutional networks suit data on a grid, like an image. Instead of linking every pixel to every neuron, a small filter scans the image for one pattern, such as an edge, using the same weights everywhere. Deep Learning credits Yann LeCun's 1989 work, and LeCun's team applied it to handwriting in a 1998 paper. In 2012 the AlexNet paper by Alex Krizhevsky, Ilya Sutskever and Hinton trained a CNN with 60 million parameters on 1.3 million ImageNet photos in 1,000 categories. Its top-5 error, how often the right label was missing from its five best guesses, was 18.9%, well ahead of the previous best. It trained on GPUs.

Recurrent networks read a sequence step by step and carry a hidden state forward. Their weakness, per Deep Learning, is that gradients passed back through many steps tend to vanish, so patterns far apart are hard to learn. The LSTM eases this but doesn't remove it.

Transformers came from "Attention Is All You Need" in June 2017. They drop recurrence and convolution and rely on attention, which lets every word weigh every other word directly and processes them all at once. On English-to-French translation the model set a single-model record of 41.8 BLEU after 3.5 days on eight GPUs. Our transformer explainer covers attention, and a looped transformer reuses its layers.

How neural networks relate to ChatGPT, Claude and other LLMs

A large language model is a transformer trained on huge amounts of text to predict the next token, a word or piece of one. The parts are the same: weights, layers, a loss function, backpropagation, gradient descent. The difference is size. OpenAI's GPT-3 paper in May 2020 described a model with 175 billion parameters, ten times more than any earlier non-sparse model. Text enters as embeddings, lists of numbers that place similar words close together.

What neural networks can't do well

  • Learning can fail. A large enough network can represent almost any function, but Deep Learning warns that training may not find the right weights, or may overfit, memorizing examples instead of the pattern.
  • They are hard to inspect. Anthropic wrote in May 2024 that "we mostly treat AI models as a black box." Its interpretability research found each concept spread across many neurons, and each neuron in many concepts.
  • They can be fooled. A 2013 paper, "Intriguing properties of neural networks", made an image classifier mislabel pictures with changes too small to see.
  • They need data and compute. AlexNet needed 1.3 million labeled images and GPUs, and today's models need far more.
  • They are only loosely like brains. Deep Learning says the name comes from neuroscience, but modern research is guided mostly by math and engineering.

Both textbooks are free online: Nielsen's book builds the digit reader in Python, and Deep Learning covers the math.

Frequently asked questions

What is the difference between a neural network and a CNN?

A CNN, or convolutional neural network, is one kind of neural network. Instead of connecting every input to every neuron, it slides small filters across an image or other grid of data and reuses the same weights at each position, which suits images and audio.

What are forward and backward propagation in a neural network?

Forward propagation sends an input through the layers to produce an answer. Backward propagation, or backpropagation, passes the error back from the output to compute how each weight should change, and an optimizer such as gradient descent then makes the change.

Do artificial neural networks work like neural networks in the brain?

Only loosely. The textbook Deep Learning says the name comes from a loose inspiration in neuroscience, and that modern neural network research is guided mostly by math and engineering.

Is there a free book on neural networks and deep learning?

Yes. Michael Nielsen's Neural Networks and Deep Learning is free at neuralnetworksanddeeplearning.com, and Goodfellow, Bengio and Courville's Deep Learning is free to read at deeplearningbook.org.

Sources

  1. Learning representations by back-propagating errors (Nature 323, 1986)Nature
  2. The perceptron: A probabilistic model for information storage and organization in the brain (Psychological Review 65(6), 1958)American Psychological Association
  3. Gradient-based learning applied to document recognition (Proceedings of the IEEE, 1998)IEEE
  4. ImageNet Classification with Deep Convolutional Neural NetworksNeurIPS
  5. Attention Is All You NeedarXiv
  6. Language Models are Few-Shot LearnersarXiv
  7. Intriguing properties of neural networksarXiv
  8. Deep Learning, chapter 6: Deep feedforward networksGoodfellow, Bengio and Courville (MIT Press)
  9. Deep Learning, chapter 9: Convolutional networksGoodfellow, Bengio and Courville (MIT Press)
  10. Deep Learning, chapter 10: Sequence modelingGoodfellow, Bengio and Courville (MIT Press)
  11. Deep Learning, chapter 1: IntroductionGoodfellow, Bengio and Courville (MIT Press)
  12. Neural Networks and Deep Learning, chapter 1Michael Nielsen
  13. Neural Networks and Deep Learning, chapter 2: How the backpropagation algorithm worksMichael Nielsen
  14. Build the Neural NetworkPyTorch
  15. Automatic differentiation with torch.autogradPyTorch
  16. Mapping the mind of a large language modelAnthropic