The short answer
A 3 layer neural network is a network with three layers, but the count depends on convention. Some sources count the input layer, which gives one hidden layer plus an output layer. Others count only the layers that have learnable weights, which gives two hidden layers plus an output layer. Check which convention a source uses before you compare networks.
The three kinds of layers
- Input layer: holds the features that describe one example, such as pixel values or measurements. It has no learnable weights of its own.
- Hidden layers: each neuron computes a weighted sum of its inputs, adds a bias, and applies an activation function such as ReLU or sigmoid. They are called hidden because their values are not the final answer.
- Output layer: produces the result, such as a class probability or a number.
Counting the layers
Take a network with 3 input values, one hidden layer of 4 neurons, and 2 outputs. If you count the input layer, it has three layers. If you count only the layers with learnable weights, it has two, because there are two sets of weights: input to hidden, and hidden to output. A network that the second convention calls 3 layers would have two hidden layers and an output layer.
A small worked example
Take the network above and count its learnable parameters, which are the weights and biases:
- Input to hidden: 3 × 4 = 12 weights, plus 4 biases, for 16 parameters.
- Hidden to output: 4 × 2 = 8 weights, plus 2 biases, for 10 parameters.
- Total: 16 + 10 = 26 learnable parameters.
Adding neurons or layers quickly increases this count.
A short code example
In PyTorch, the same network looks like this:
import torch.nn as nn
model = nn.Sequential(
nn.Linear(3, 4), # input (3 values) to hidden layer (4 neurons)
nn.ReLU(),
nn.Linear(4, 2), # hidden layer (4 neurons) to output (2 values)
)
Calling sum(p.numel() for p in model.parameters()) returns 26.
What a small network can and cannot do
A small network like this can learn simple relationships, such as separating two classes in a table of numbers.
The universal approximation theorem says that a network with one hidden layer and enough neurons can approximate many functions. In practice, the number of neurons needed can be impractically large, and stacking layers can often do the same job with far fewer neurons.
For images, a fully connected network like this is a poor fit. A 224 × 224 color image has 150,528 values, so even one hidden layer of 1,000 neurons needs about 150 million weights. Convolutional layers reduce that cost by sharing filters across the image.
Deep versus shallow
“Deep” generally means many hidden layers, but there is no official cutoff. People often ask about the difference between artificial neural networks and deep neural network, and much of that difference comes down to depth. A network with one or two hidden layers is often called shallow, while one with dozens of layers is called deep.
Key takeaways
- A 3 layer network has an input layer, hidden layers, and an output layer. The count depends on convention, so check the source.
- Each hidden neuron computes a weighted sum, adds a bias, and applies an activation function.
- Parameter counts add up quickly. The example here has 26.
- Depth, more than the number 3 itself, is what usually separates basic networks from deep ones.