Neural Network Basics

Perceptrons, layers, and why nonlinearity is what makes depth meaningful

Why

Every architecture — CNNs, RNNs, transformers — is built from the same primitive: a linear transform followed by a nonlinear activation. Understanding the primitive itself matters more than the frameworks built on top of it.

The single most common trap question is "why not just stack linear layers?" — if you can't answer it, you don't yet understand why depth helps at all.

Intuition

A single neuron is a weighted vote: multiply each input by how much it matters (weight), add a bias to shift the threshold, and squash the result through an activation function. Stack neurons into a layer, stack layers into a network, and each layer learns to re-represent the input in a way that makes the next layer's job easier.

Without the nonlinear squashing step, none of that re-representation matters — the whole network collapses to a single linear function, no matter how many layers you add.

Explanation
The perceptron and a layer
z = w·x + b (weighted sum + bias) a = f(z) (activation) Layer: a = f(Wx + b) W is a matrix, one row of weights per neuron Network: a2 = f(W2·a1 + b2), a3 = f(W3·a2 + b3), ...

Weights control how strongly each input influences a neuron; the bias shifts the decision boundary independent of the input. Training means adjusting W and b so the network's output matches the target.

Why nonlinearity is non-negotiable
If f were linear (or absent): a1 = W1x, a2 = W2a1 = W2W1x, a3 = W3W2W1x = (W3W2W1)x Any stack of linear layers reduces to ONE linear layer (product of matrices is still just a matrix). Depth would buy you nothing — no capacity gain, no ability to model curves, XOR, or anything non-linearly separable.

The activation function breaks that collapse — it's what lets each additional layer add real representational power instead of being algebraically absorbed into the layer before it.

Activation functions — tradeoffs that matter in practice
Sigmoid: σ(z) = 1/(1+e^-z) range (0,1) - saturates for |z| large → gradient ≈ 0 → vanishing gradient - not zero-centered → inefficient weight updates - still used for output gates / binary probability Tanh: tanh(z) range (-1,1) - zero-centered (better than sigmoid for hidden layers) - still saturates at the extremes → vanishing gradient persists ReLU: max(0, z) range [0, ∞) - no saturation for z > 0 → gradient is exactly 1, doesn't vanish - cheap: one comparison, no exponential - risk: "dead ReLU" — a neuron stuck at z < 0 forever has zero gradient - variants (Leaky ReLU, GELU) patch the dead-neuron problem

ReLU won out over sigmoid/tanh for hidden layers mainly because it keeps gradients alive through many layers — this is the single biggest practical reason deep networks became trainable at all.