Lesson 3 of 8 · The Idea
What Neural Networks Can Do
What neural networks can learn: tasks that turn an input into an output, from images and speech to proteins and weather, plus the limits to keep in mind.
- 6 min read
- Beginner
- Reviewed
- How almost any task can be described as input in, output out
- What the universal approximation theorem says, and what it does not
- Where neural networks are used today, from vision to science
- The limits every engineer should keep in mind
Input in, output out
A neural network is a function: it takes numbers in and gives numbers out. That sounds limited, but a huge range of tasks can be described this way:
| Task | Input | Output |
|---|---|---|
| Image classification | The pixel values of a photo | A probability for each of 1,000 categories |
| Speech recognition | Audio samples, 16,000 per second | The words that were spoken |
| Language model | The text so far | A probability for every possible next word |
| Board games | The position of every piece | The move to play |
| Protein structure | A chain of amino acids | The 3D shape the protein folds into |
If you can collect many examples of inputs with their correct outputs, a network can try to learn the mapping between them.
Enough neurons can fit almost any shape
The idea is easier to see than to prove. Below, each hidden neuron is a ReLU (it outputs 0 for negative inputs and passes positive inputs through). Each one adds a bend. With more neurons, the network's output follows the target curve, sin(π·x) between 0 and 1, more and more closely.
import math
def relu(z):
return max(0.0, z)
def target(x):
return math.sin(math.pi * x)
def build_network(n):
# n hidden neurons: the output joins n + 1 points on the curve with straight pieces
knots = [i / n for i in range(n + 1)]
values = [target(k) for k in knots]
slopes = [(values[i + 1] - values[i]) * n for i in range(n)]
out_weights = [slopes[0]] + [slopes[i] - slopes[i - 1] for i in range(1, n)]
def network(x):
return values[0] + sum(w * relu(x - k) for w, k in zip(out_weights, knots))
return network
xs = [i / 200 for i in range(201)]
for n in [2, 4, 8, 16, 32]:
net = build_network(n)
worst = max(abs(net(x) - target(x)) for x in xs)
print(f"{n:2d} hidden neurons -> largest error {worst:.4f}")Each time the number of neurons doubles, the largest error shrinks to about a quarter. That is the theorem in action.
Where neural networks are used today
- Vision: finding pedestrians and traffic lights for self-driving cars, reading X-rays, colouring every pixel of a street scene by what it shows, and generating images and video from text.
- Language: translation, summaries, writing code and chatbots such as ChatGPT, Claude and Gemini.
- Sound: live captions, voice assistants and natural-sounding synthetic speech.
- Science: AlphaFold predicted the 3D shapes of over 200 million proteins, a problem biologists had worked on for 50 years. Google DeepMind's GraphCast makes 10-day weather forecasts that beat a leading traditional system on most of the measures tested.
What they cannot do
- Guarantee they are right. A network gives its most likely answer, not a proven one. Language models can state false things with full confidence.
- Handle data unlike their training data. A driving model trained only on sunny roads may behave unpredictably in snow.
- Resist small, deliberate changes. Researchers have fooled image classifiers with tiny pixel changes that people cannot see, turning a confident "school bus" into "ostrich".
- Come cheap. Training the largest models takes thousands of specialised chips and huge amounts of electricity.
Common mistakes
Three ReLU neurons can make a bump that rises from 0 to 1 and falls back to 0. Bumps like this, added together, are how a network builds up any shape. Complete bump so it prints the expected values.
def relu(x):
return max(0.0, x)
def bump(x):
# Use three ReLU neurons: relu(x) - 2 * relu(x - 1) + relu(x - 2)
return 0.0
for x in [0.0, 0.5, 1.0, 1.5, 2.0, 3.0]:
print(x, bump(x))
# Output must be exactly:
# 0.0 0.0
# 0.5 0.5
# 1.0 1.0
# 1.5 0.5
# 2.0 0.0
# 3.0 0.0
What does the universal approximation theorem guarantee?
Summary
- Many tasks can be written as input in, output out, which is what a network learns.
- The universal approximation theorem says enough hidden neurons can approximate any continuous function.
- It promises that a good network exists, not that training will find it.
- Neural networks power vision, language, sound and science, but they can be confidently wrong and fail on unfamiliar data.
Next: why deep learning took off only after 2012.
Finished reading? Tick it off to track your progress.