← CS Lab AI & Machine Learning / Activation Functions Open standalone ↗

An activation function is the nonlinear twist a neuron applies after the weighted sum. A layer computes z = Wx + b — a straight line. The activation a = f(z) bends it, and that bend is the only reason a deep network can learn anything a single line cannot.

Where you meet it

What it does

It maps the raw pre-activation z to an output a in a controlled range, and — crucially — does so nonlinearly. That nonlinearity is what lets stacked layers compose into arbitrarily complex functions instead of collapsing back into a single linear map.

Strip the nonlinearity and a hundred layers collapse into one line — the kink is the depth.

How it works

After the weighted sum, each unit passes z through f. The three classics:

ReLU:    f(z) = max(0, z)        # range [0, ∞), a hard kink at 0
Sigmoid: f(z) = 1 / (1 + e^-z)   # range (0, 1), smooth S-curve
tanh:    f(z) = (e^z - e^-z)/(e^z + e^-z)  # range (-1, 1), zero-centered

Why nonlinear at all? Suppose every f were the identity. Then two stacked layers give W₂(W₁x + b₁) + b₂ = (W₂W₁)x + (W₂b₁ + b₂) — still just one affine map. Add a hundred layers and they still collapse to a single linear function: a deep linear net is no more expressive than a one-layer net. The kink in ReLU or the curve in sigmoid is what breaks that collapse and buys you depth.

Watch out

  • Vanishing gradients. Sigmoid and tanh saturate — their tails go flat, so f'(z) ≈ 0 for large |z|. Backprop multiplies these tiny slopes layer by layer, and the gradient to early layers fades to nothing.
  • Dying ReLU. A unit stuck at z < 0 outputs 0 and has zero gradient — it can stop learning permanently. Leaky ReLU (max(0.01z, z)) or GELU give the negative side a nonzero slope.
  • Not zero-centered. Sigmoid outputs are all positive, which biases gradient updates; tanh is zero-centered and usually preferred over sigmoid in hidden layers.
  • Match the output activation to the loss. Sigmoid + binary cross-entropy, softmax + categorical cross-entropy. Don't put a squashing activation on a regression output.

Go deeper

Eine Aktivierungsfunktion ist der nichtlineare Knick, den ein Neuron nach der gewichteten Summe anwendet. Eine Schicht berechnet z = Wx + b — eine Gerade. Die Aktivierung a = f(z) biegt sie, und genau dieser Knick ist der einzige Grund, warum ein tiefes Netz mehr lernen kann als eine einzelne Gerade.

Wo es vorkommt

Was es tut

Es bildet die rohe Pre-Aktivierung z auf eine Ausgabe a in einem kontrollierten Wertebereich ab — und das entscheidend nichtlinear. Diese Nichtlinearität lässt gestapelte Schichten zu beliebig komplexen Funktionen verschmelzen, statt zu einer einzigen linearen Abbildung zu kollabieren.

Nimm die Nichtlinearität weg und hundert Schichten kollabieren zu einer Geraden — der Knick ist die Tiefe.

Wie es funktioniert

Nach der gewichteten Summe schickt jede Einheit z durch f. Die drei Klassiker:

ReLU:    f(z) = max(0, z)        # Bereich [0, ∞), harter Knick bei 0
Sigmoid: f(z) = 1 / (1 + e^-z)   # Bereich (0, 1), glatte S-Kurve
tanh:    f(z) = (e^z - e^-z)/(e^z + e^-z)  # Bereich (-1, 1), null-zentriert

Warum überhaupt nichtlinear? Angenommen, jedes f wäre die Identität. Dann ergeben zwei gestapelte Schichten W₂(W₁x + b₁) + b₂ = (W₂W₁)x + (W₂b₁ + b₂) — immer noch nur eine affine Abbildung. Hänge hundert Schichten aneinander und sie kollabieren trotzdem zu einer einzigen linearen Funktion: ein tiefes lineares Netz ist nicht ausdrucksstärker als ein einschichtiges. Erst der Knick in ReLU oder die Krümmung in Sigmoid bricht diesen Kollaps und verschafft dir echte Tiefe.

Worauf achten

  • Vanishing Gradients. Sigmoid und tanh sättigen — ihre Enden werden flach, also f'(z) ≈ 0 für große |z|. Backprop multipliziert diese winzigen Steigungen Schicht für Schicht, und der Gradient zu den frühen Schichten verschwindet.
  • Dying ReLU. Eine Einheit, die bei z < 0 feststeckt, gibt 0 aus und hat Gradient null — sie kann dauerhaft aufhören zu lernen. Leaky ReLU (max(0.01z, z)) oder GELU geben der negativen Seite eine Steigung ungleich null.
  • Nicht null-zentriert. Sigmoid-Ausgaben sind alle positiv, was die Gradienten-Updates verzerrt; tanh ist null-zentriert und wird in versteckten Schichten meist gegenüber Sigmoid bevorzugt.
  • Ausgabe-Aktivierung zur Loss-Funktion passen. Sigmoid + Binary Cross-Entropy, Softmax + Categorical Cross-Entropy. Keine quetschende Aktivierung auf eine Regressionsausgabe setzen.

Mehr dazu

Next up
AI & Machine LearningForward Propagation AI & Machine LearningBackpropagation All concepts →