Skip to main content

What Is an Activation Function? The Tiny Decision Inside Every Neuron

Updated 7 min readMarkdown

To put it simply, an activation function is the tiny decision a neuron makes after adding up its inputs: how much of that signal to pass on, and how much to hold back.

Last time, we looked at backpropagation — how a neural network learns from its mistakes by nudging its weights a little after every wrong answer. That post left one question hanging, and it is the most important question in the whole network: after a neuron adds up its weighted inputs, what does it do with the total? If it just passes the number along unchanged, the network never learns anything interesting. The activation function is what stops that from happening.

Short version: without an activation function, a hundred-layer network is no smarter than one layer. The function bends the signal — cutting off the negatives, squeezing it into a range — and that bend is where all the learning power lives.

Think of a bouncer at a club door. People arrive all evening, each one with a different story — the inputs, weighted by how convincing they are. The bouncer adds it all up and makes one call: you are in, you are out, or you are in but only halfway. The activation function is that bouncer. It stands between the sum and the next layer, and nothing gets through without its say-so.

An activation function at a glance

A network without one is just a straight line

A neuron's job, stripped down, is simple arithmetic. It takes its inputs, multiplies each by a weight, and adds them up. That is a weighted sum, and a weighted sum is a straight line. It can say "more of this input means more output," and it can say it in either direction. What it cannot say is "a little of this helps, but a lot of it hurts." It cannot draw a curve. It cannot say "only fire when two things happen together."

Here is the trap. Stack ten layers of pure weighted sums on top of each other and the whole stack is still, mathematically, one weighted sum. A straight line of a straight line of a straight line is a straight line. Ten layers, a million weights, hours of training — and the network can still only draw straight lines through the data. It could never learn that a face is eyes plus a nose plus a mouth in a particular arrangement, because that arrangement is not a straight line.

The activation function breaks the line. After the sum, it applies a small bend: cut off everything below zero, or squeeze the result into a range between zero and one, or flatten the extremes. Each bend is small. But a hundred layers of small bends, one after another, can trace any shape at all — curves, corners, thresholds, combinations. That is the whole secret of deep learning, and it lives in a function you can write in one line.

A signal passes through one neuron

ReLU: the one that runs the modern world

The most common activation function today is called ReLU, short for rectified linear unit. Its rule could fit on a napkin: if the number is negative, output zero. If it is positive, output the number unchanged.

def relu(x):
    return max(0, x)

relu(-3.5)  # 0
relu(2.0)   # 2.0
relu(0.0)   # 0

max(0, x) is the whole function. There is nothing else to it. A neuron using ReLU stays silent for every negative sum and speaks plainly for every positive one. That silence is doing real work: in a big network, roughly half the neurons are quiet at any moment, and that sparsity is part of why the network can represent so many different things at once. A neuron that never fires for cat pictures but fires for dog pictures is a feature detector, and ReLU is what lets it say no most of the time.

ReLU has one more advantage that made it the default: its gradient is either zero or one. Remember backpropagation from the last post — the network learns by passing error signals backwards, and each layer multiplies the signal by the slope of its activation function. A slope of one means the signal travels through unchanged, no matter how many layers it crosses. The older functions squeezed the signal smaller at every layer, and in a deep network the error signal faded to nothing before it reached the early layers. ReLU does not squeeze. That is why networks went from a handful of layers to a hundred almost overnight.

It is not perfect. A neuron whose weights push its sum negative for every training example will output zero forever, and its gradient will be zero forever, so it can never recover. People call it a dead ReLU. In practice it is rare enough that most teams just use plain ReLU and move on.

Sigmoid and tanh: the older pair, still earning their keep

Before ReLU took over, two other functions ran the show. Sigmoid squeezes any number into the range between zero and one, like a probability. A huge positive sum becomes 0.99, a huge negative sum becomes 0.01, and zero becomes exactly 0.5. It is smooth and gentle, and it looks like a yes-or-no answer with a maybe in the middle. That makes it perfect for the very last layer of a network that answers a yes-or-no question — is this email spam, is this transaction fraud. You read the output as a confidence score.

Tanh is sigmoid's sibling, squeezed into the range between minus one and one instead, centred on zero. Negative inputs give negative outputs, which keeps the signal balanced and helps the next layer learn a little faster. It was the standard for the hidden layers of the nineties and the 2000s.

Both have the same flaw, and it is the flaw ReLU fixed: at the extremes, they go flat. Once the input is large, the output barely changes, and the slope — the gradient backpropagation needs — drops to almost zero. A flat slope means the neuron has stopped learning. So the modern rule is simple: ReLU in the hidden layers, sigmoid or tanh only where the shape of the answer genuinely needs them.

ReLU Sigmoid Tanh
Output range 0 to infinity 0 to 1 −1 to 1
Rule Negative becomes zero Squeezes into a probability Squeezes, centred on zero
Gradient 0 or 1 — never fades Fades at the extremes Fades at the extremes
Best used for Hidden layers, the default Final yes/no output Hidden layers in older networks

Verdict: if you are building a network today and you are not sure, use ReLU everywhere inside and sigmoid only at the very end, where the answer needs to look like a probability.

What each function does to a number

Next time in this little series: the loss function — the single number that tells the network how wrong it was, and why choosing the right one matters more than most beginners think.

  • Without an activation function, every layer is a straight line, and a hundred straight lines are still one straight line.
  • ReLU — negative becomes zero, positive passes through — is the default because its gradient never fades.
  • Sigmoid belongs at the output when the answer is a probability; tanh is its centred sibling from an earlier era.
  • A dead ReLU is a neuron that never fires again, and it is the one price of the function's simplicity.

References and further reading

— Min SiThu Software Engineer & Tech Content Creator https://minsithu.org

About the author

  • Nubbad Developer. | Now I accidentally create problems.

No comments yet. Be the first to comment.

More from this blog