← All posts

AI basics › From statistics to AGI

What is deep learning? How neural networks learn from data

What deep learning is, how layers of artificial neurons learn from data, why it took off after 2012, and when a simpler model still does the job better.

If you’ve followed news about AI over the past few years, you’ve almost certainly heard the words deep learning more than once. They tend to come up whenever people talk about chatbots that answer questions or phones that find faces in photos, and the large language models behind those chatbots are deep learning models too. In 2024, even the Nobel Prize in Physics went to John Hopfield and Geoffrey Hinton “for foundational discoveries and inventions that enable machine learning with artificial neural networks” (press release).

Deep learning is a kind of machine learning in which an artificial neural network, built from many stacked layers, learns features from data on its own. A 2015 review in Nature by Yann LeCun, Yoshua Bengio, and Geoffrey Hinton, titled Deep learning, says much the same. It describes a way for models made of multiple processing layers to learn representations of data with multiple levels of abstraction. It’s the third topic in the series “From statistics to AGI.” If machine learning means learning rules from data instead of writing them by hand, you can think of deep learning as also learning what to pay attention to.

Artificial neurons and layers

A neural network is made of small units called artificial neurons. The idea was inspired by neurons in the brain, but an artificial neuron is far simpler. It multiplies each number it receives by a weight, adds one more number called a bias, and sums everything up. Then it passes the sum through an activation function and sends the result on to the next layer. A weight decides how strongly one input counts, so perhaps it helps to picture the volume knobs on a mixing board. Weights and biases together are called parameters, and learning comes down to finding a good set of values for them.

The activation function bends the output so that it isn’t a straight line. A common one, ReLU, turns negative numbers into 0, and tanh squeezes any number into the range from -1 to 1. Without this step, stacking layers would get you nowhere, since a weighted sum of weighted sums is still just one weighted sum. Neurons placed side by side form a layer. Data comes in through the input layer, passes through one or more hidden layers, and leaves the output layer as an answer. Hidden simply means that a layer is neither input nor output, so you don’t see it from outside.

Loss, gradient descent, and backpropagation

At first the weights are set at random, so the network’s answers are close to guesses. That’s why learning starts by measuring, in a single number, how wrong those answers are. That number is called the loss. The way to lower it is gradient descent. If you were looking for the valley on a foggy hillside, you’d take a step in the direction the ground slopes down under your feet, then feel the slope again, over and over. Gradient descent moves the weights a little at a time in the direction that lowers the loss, and the size of each step is called the learning rate.

Backpropagation is how that direction gets worked out for every weight at once. It starts from the error at the output and goes backward through the layers, calculating how much each weight contributed to that error. In 1986, David Rumelhart, Geoffrey Hinton, and Ronald Williams described this procedure in Nature, noting that along the way the hidden units come to represent important features of the task. In PyTorch, a single line, loss.backward(), takes care of this calculation (autograd tutorial).

Watching a small network learn XOR

Now let’s check all this on the smallest problem where one hidden layer makes the difference. XOR takes two inputs, each 0 or 1, and outputs 1 only when they differ. If you plot the four points, (0, 1) and (1, 0), which give 1, sit on one diagonal, while (0, 0) and (1, 1), which give 0, sit on the other, so no single straight line can separate them. The textbook Deep Learning by Ian Goodfellow and colleagues also names XOR as the most famous limitation of linear models.

The code below uses PyTorch to train two models on the same four points. train repeats three things 2,000 times, measuring the loss, running backpropagation, and taking one gradient descent step, and it prints the loss every 500 steps. At the end it shows the outputs turned into probabilities by a sigmoid.

import torch
from torch import nn

torch.manual_seed(0)  # same starting weights on every run
X = torch.tensor([[0., 0.], [0., 1.], [1., 0.], [1., 1.]])
y = torch.tensor([[0.], [1.], [1.], [0.]])  # XOR: 1 only when the inputs differ

def train(model, steps=2000):
    print("parameters:", sum(p.numel() for p in model.parameters()))
    loss_fn = nn.BCEWithLogitsLoss()  # one number for how wrong the predictions are
    opt = torch.optim.SGD(model.parameters(), lr=0.5)  # lr is the learning rate
    for step in range(steps + 1):
        loss = loss_fn(model(X), y)
        if step % 500 == 0:
            print(f"step {step:4d}  loss {loss.item():.4f}")
        opt.zero_grad()
        loss.backward()  # backpropagation: how each weight affects the loss
        opt.step()       # gradient descent: nudge every weight to lower the loss
    probs = torch.sigmoid(model(X)).squeeze(1)
    print("predictions:", " ".join(f"{p:.3f}" for p in probs.tolist()))

The first model is a linear model with a single neuron, which is the same thing as logistic regression. The second puts a hidden layer of four neurons with tanh in front of it. The seed is fixed and everything runs on the CPU, so you should get the same numbers when you run it.

print("== linear model (logistic regression)")
train(nn.Linear(2, 1))
print("== neural network with one hidden layer of 4 neurons")
train(nn.Sequential(nn.Linear(2, 4), nn.Tanh(), nn.Linear(4, 1)))
== linear model (logistic regression)
parameters: 3
step    0  loss 0.7168
step  500  loss 0.6931
step 1000  loss 0.6931
step 1500  loss 0.6931
step 2000  loss 0.6931
predictions: 0.500 0.500 0.500 0.500
== neural network with one hidden layer of 4 neurons
parameters: 17
step    0  loss 0.7048
step  500  loss 0.0154
step 1000  loss 0.0060
step 1500  loss 0.0037
step 2000  loss 0.0027
predictions: 0.000 0.997 0.997 0.004

The linear model stops at a loss of 0.6931 within 500 steps and answers 0.500 for all four inputs. That’s the loss you get by saying fifty-fifty to everything, and on this problem it’s the best a straight line can do. Chapter 6 of the same textbook shows the same result, a linear model that outputs 0.5 everywhere. The network, with its 17 parameters, brings the loss down to 0.0027 and gets all four right.

What made the difference is the hidden layer. It turns the two inputs into four new numbers, and in that new description of the data, a single straight line is enough to split the 1s from the 0s. Nobody told the network which numbers to make, so it found them on its own while lowering the loss. On a very small scale, that’s what it means to learn features by itself.

What “deep” means

The deep in deep learning refers to the number of layers, so the network above, with only one hidden layer, counts as shallow. A deep network stacks many layers, and each one builds a new description on top of the one made by the layer before it. The Deep Learning textbook illustrates this with an image model in which the first hidden layer finds edges, the second finds corners and contours, and the third finds parts of objects, before the output names the object. When you draw how these concepts build on one another, the book explains, “the graph is deep, with many layers,” and that’s where the name comes from. Of course, it also adds that there’s no consensus on how many layers it takes to count as deep.

Why it took off in the 2010s

These ideas aren’t new, since backpropagation was already in Nature in 1986, but the result that drew wide attention came in 2012. That year, Alex Krizhevsky, Ilya Sutskever, and Geoffrey Hinton of the University of Toronto entered the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) as a team called SuperVision. Their model was a deep convolutional network now usually called AlexNet. The task was to sort photos into 1,000 categories, and the model’s top-5 error, the share of images where the right answer wasn’t among its five best guesses, was 15.3 percent. The second-place team’s was 26.2 percent, and even their other entry, trained only on the contest’s own data, scored 16.4 percent (results).

Their paper makes clear the two ingredients behind that result. One was ImageNet, which held over 15 million labeled images in about 22,000 categories, and the contest used roughly 1.2 million of them for training. The other was the GPU, a graphics chip that runs a great many calculations at the same time. The network had 60 million parameters and trained for five to six days on two NVIDIA GTX 580 cards with 3 GB of memory each. The authors even wrote that their results could be improved simply by waiting for faster GPUs and bigger datasets.

After that, deep networks spread to many other kinds of data. A convolutional neural network (CNN), like AlexNet, slides small filters across an image to find patterns such as edges, which makes it strong on images. A recurrent neural network (RNN) reads ordered data one step at a time while keeping a memory of what came before, and the 2015 Nature review points to what RNNs achieved on sequential data such as text and speech. And the transformer, introduced in 2017 in Attention Is All You Need, drops recurrence and convolution and uses attention to let words look at one another all at once. Most of today’s large language models are built on it.

How it differs from other machine learning

Deep learning is one branch of machine learning, so the biggest difference from methods such as logistic regression, decision trees, and gradient boosting lies in who decides the features. A feature is a number that describes the data in a way that helps the prediction. For a spam filter, a person might pick the number of links in an email or whether certain words appear and hand those to a model, which is called feature engineering. But try to find cars in photos, as in an example from the Deep Learning textbook, and you get stuck at the first step. Shadows and glare keep changing how a wheel looks, so it’s very hard to describe one exactly in pixel values. That’s why deep learning, like the hidden layer in the XOR example, learns the features themselves from raw data, an approach called representation learning.

Other machine learning Deep learning
Who makes the features Often people, by design The model, from the data
Data it suits best Tables with set columns Images, sound, and text
Data and compute Often fine with less data and a CPU Often uses more data and GPUs
Typical models Logistic regression, decision trees, gradient boosting CNNs, RNNs, transformers

When it fits and when it doesn’t

Deep learning often fits best when there’s plenty of raw data such as photos, sound, or text. Small tables of data, the kind you might keep in a spreadsheet, are a different story. In a paper presented at NeurIPS 2022, Léo Grinsztajn and colleagues compared deep learning models with tree-based models such as XGBoost and random forests on 45 tabular datasets. They found that on medium-sized data of around 10,000 rows, tree-based models remained the state of the art, even before counting their speed advantage. Of course, this area keeps moving. In January 2025, the team behind TabPFN, a transformer-based model, reported in Nature that it outperformed all previous methods on datasets with up to 10,000 samples.

So with tabular data, I’d suggest training a tree-based model such as gradient boosting first and using it as the baseline a neural network has to beat. Deep learning also tends to need more computing power, and it’s hard to explain why it gave a particular answer, so in fields where every decision needs a reason, that’s worth weighing too.

Where to start

If you’re new to this, I’d suggest running the XOR example above yourself. Install PyTorch by following the official instructions, put the two code blocks in one file, and run it, with no GPU needed. Then try changing one thing at a time. When I ran it with 50 different seeds, from 0 to 49, the network with four hidden neurons solved XOR every time, but with two hidden neurons it solved it only 31 times. That’s because, depending on where the weights start, training can get stuck before it finds an answer.

After that, I’d recommend PyTorch’s Learn the Basics tutorial. It trains a network from start to finish to sort FashionMNIST clothing images into 10 classes, and each part has a link to run it in Google Colab. The Deep Learning textbook is also free to read online. The next piece in the series looks at large language models, which use deep learning on vast amounts of text to predict the next token. I ran the example on October 27, 2026, on macOS with Python 3.13.12 and PyTorch 2.14.1 on the CPU.

AI tools helped with the research for this post.