Topic 1 of 5 · 4 min read
Neurons, weights and activation functions
Goal: Compute one neuron's output by hand and explain why removing the activation makes a deep network equivalent to one linear layer.
A neuron computes a weighted sum of its inputs, adds a bias, and passes the result through a nonlinear activation function; without that last step, any number of layers collapses into one linear map.
Check yourself · 1 of 3
A neuron has weights [1, -2], bias 1 and ReLU activation. The input is [3, 2]. What does it output?
Why it matters
Every network you will meet, from a small classifier to a large language model, is built from this one operation repeated millions of times. If you can compute one neuron by hand, you can read a layer definition, debug a shape error and see why a network can learn curves and not just straight lines.
How a neuron works
Take an input vector x, a weight vector w and a bias b. The neuron computes z = w · x + b, then outputs a = f(z). The weights say how much each input matters. The bias shifts the threshold. The function f is the activation.
Common activations:
- ReLU: f(z) = max(0, z). Negative values become zero, positive values pass through. Cheap and the default in many vision models.
- GELU: a smooth curve close to ReLU that lets small negative values through. Common in transformer models.
- Sigmoid: squashes any value into 0 to 1. Used on a final output when the answer is a probability, rarely inside deep stacks.
Worked example
import numpy as np
x = np.array([1.0, 3.0, 0.0])
w = np.array([0.5, -1.0, 2.0])
b = 0.5
z = w @ x + b # 0.5 - 3.0 + 0.0 + 0.5 = -2.0
a = max(0.0, z) # ReLU -> 0.0
The weighted sum is -2.0. ReLU turns it into 0, so this neuron is silent for this input. GELU would output about -0.045 instead.
Why the activation is not optional
Stack two layers with no activation: h = W1 x + b1, then y = W2 h + b2. Substitute and you get y = (W2 W1) x + (W2 b1 + b2). That is one matrix times x plus one vector, which is a single linear layer. Ten layers collapse the same way. A purely linear model can only draw a straight boundary, so it cannot solve a problem like XOR. The nonlinearity between layers is what lets depth add power.
Before and after
Weak: "A neuron is a tiny brain cell that fires when it is excited." This hides the arithmetic and gives you nothing to compute.
Better: "A neuron outputs f(w · x + b). With ReLU, it outputs the weighted sum when that is positive and 0 otherwise."
What goes wrong
- Leaving out the activation on a hidden layer. The code runs, trains and gives a model no better than linear regression or logistic regression.
- Sigmoid in every hidden layer of a deep network. Its slope is small for large inputs, which makes training slow (see the topic on depth).
- Dead ReLU units. If a unit's z is negative for every input, its output and its gradient are both zero, so it never recovers. Lower learning rates and good initialization reduce this.
Examples
Hand-checking one neuron
x = [2.0, 1.0, 0.5]
w = [0.5, -1.0, 2.0]
b = 0.5
z = sum(wi * xi for wi, xi in zip(w, x)) + b # 1.0 - 1.0 + 1.0 + 0.5 = 1.5
a = max(0.0, z) # 1.5
Do this on paper before you trust a framework's output on a toy input. If your number and the library disagree, the shapes or the order of arguments are wrong.
The missing activation
model = nn.Sequential(
nn.Linear(20, 64),
nn.Linear(64, 64),
nn.Linear(64, 1),
)
Three layers, but no nonlinearity between them. This is one linear map with extra parameters. Add nn.ReLU() between the layers and the model can fit curved data.
Key points
- A neuron computes z = w · x + b and then applies an activation function f(z).
- ReLU outputs max(0, z); GELU is a smooth variant that lets small negative values through.
- Two linear layers with no activation between them equal one linear layer, because W2(W1 x + b1) + b2 = (W2 W1) x + (W2 b1 + b2).
- The activation is what lets extra layers represent curved decision boundaries.
- A ReLU unit that is negative for every input outputs zero gradient and stops learning.
Common mistakes
- Describing a neuron as a biological cell instead of as the formula f(w · x + b).
- Forgetting that a deep stack with no activation is still one linear function.
- Putting a softmax or sigmoid inside hidden layers because the output layer uses one.
- Assuming more layers always means more power, regardless of activations.
Check yourself · 2 of 3
A network has three Linear layers and no activation functions. What can it represent?
Check yourself · 3 of 3
A hidden ReLU unit has a negative weighted sum for every training example. What happens to it?
Practice items, not counted towards your mastery.
Start here
- Neural networks series (3Blue1Brown) (opens in a new tab)VideoFree
Animated walk through neurons, layers, gradient descent and backpropagation with the chain rule drawn out.
- Neural Networks and Deep Learning (Michael Nielsen) (opens in a new tab)BookFree
Free online book that derives backpropagation step by step and builds a digit classifier in Python.
- Deep Learning (Goodfellow, Bengio, Courville) (opens in a new tab)BookFree
The standard textbook; chapters on feedforward networks, optimization and regularization.