Trace one rectified linear unit

Read a complete operation before typing its result. · 211 words

A dense layer sends every input to every neuron. Consider one neuron with two inputs, x1 = 2 and x2 = -1. Its weights are w1 = 0.5 and w2 = 3, and its bias is b = 1. First compute the pre-activation z by multiplying each input by its matching weight, adding the results, and then adding the bias: z = (2 x 0.5) + (-1 x 3) + 1 = 1 - 3 + 1 = -1. The weights control how strongly each input affects the neuron. The bias is a constant offset that lets the neuron shift its threshold.

The rectified linear unit, or ReLU, is the activation function applied to z. It keeps a positive value unchanged and replaces a negative value with zero: ReLU(z) = max(0, z). For the neuron above, ReLU(-1) = 0, so its output is 0. Now try a distinct case with inputs x1 = 3 and x2 = 2, the same weights, and the same bias. The weighted sum is z = (3 x 0.5) + (2 x 3) + 1 = 1.5 + 6 + 1 = 8.5, so ReLU(8.5) = 8.5. Tracing one neuron means showing this path from inputs, through weights and bias, to z, and finally through ReLU.

Check your recall

What does a ReLU output when its pre-activation z is -2, and what does it output when z is 5?

Check your answer

The ReLU outputs 0 for z = -2 and 5 for z = 5.

Sources and credits

Original KeyTouch lesson. Background reading · Google · Neural networks.