FXJ Wiki

Back

Two classes of points separated by folded creases beside a sawtooth wave
20 min read
English Deep Learning / Neural Networks / Transformer

Why Neural Networks Need Depth

From perceptrons, Novikoff's proof, XOR, and ReLU folding to depth's exponential expressivity, √d_k scaling, and residual connections.
views | comments

A Brief Introduction to Deep Learning covered forward propagation and backpropagation. This post addresses two structural questions:

  1. Expressivity: Why can’t a single neuron solve XOR? Given the same budget of neurons, why does stacking them deeply represent far more complex functions than arranging them in a single wide layer?
  2. Trainability: As networks grow deeper or wider in dimension, why do vanishing/exploding gradients and Softmax saturation appear? How do dk\sqrt{d_k} scaling and residual connections alter gradient flow?

Perceptrons: A Single Hyperplane and Convergence Proof#

Introduced by Rosenblatt in 1958 [1], the perceptron computes a weighted sum followed by a step threshold. For input x=(x1,x2)x=(x_1,x_2), weights w=(w1,w2)w=(w_1,w_2), and bias bb:

z=w⋅x+b=w1x1+w2x2+b,y^={1,z>00,z≤0z = w\cdot x + b = w_1 x_1 + w_2 x_2 + b, \qquad \hat{y} = \begin{cases} 1, & z > 0 \\ 0, & z \le 0 \end{cases}

When w≠0w \ne 0, w⋅x+b=0w\cdot x + b = 0 defines a line (a hyperplane in higher dimensions) with normal ww pointing toward the +1+1 side and distance ∣b∣/∥w∥|b|/\|w\| from the origin. A single neuron can therefore only partition input space with one hyperplane.

Perceptron Update Rule#

Let the true label be t∈{+1,−1}t \in \{+1, -1\}. Whenever a sample xx is misclassified (t(w⋅x+b)≤0t(w\cdot x + b) \le 0), update with learning rate η>0\eta > 0:

w←w+η t x,b←b+η t.w \leftarrow w + \eta\, t\, x, \qquad b \leftarrow b + \eta\, t.

The new linear score becomes z′=z+η t (∥x∥2+1)z' = z + \eta\, t\,(\|x\|^2 + 1), so the signed score tz′t z' strictly increases and the boundary moves toward classifying xx correctly.

Novikoff’s Convergence Theorem (1962)#

If a dataset is linearly separable, can sample-by-sample updates cycle forever? Novikoff proved that the number of updates has a finite upper bound.

Proof: Fold the bias into the weights via x~i=(xi,1)\tilde{x}_i = (x_i, 1) and w~=(w,b)\tilde{w} = (w, b). Assume ∥x~i∥≤R\|\tilde{x}_i\| \le R for all samples, and there exists a unit vector uu (∥u∥=1\|u\|=1) with margin γ>0\gamma > 0 such that ti(u⋅x~i)≥γt_i (u \cdot \tilde{x}_i) \ge \gamma for all ii.

Take η=1\eta = 1 without loss of generality and start from w~0=0\tilde{w}_0 = 0. On the kk-th mistake (ti(w~k−1⋅x~i)≤0t_i (\tilde{w}_{k-1} \cdot \tilde{x}_i) \le 0), w~k=w~k−1+tix~i\tilde{w}_k = \tilde{w}_{k-1} + t_i \tilde{x}_i:

  1. Lower bound on inner product: u⋅w~k=u⋅w~k−1+ti(u⋅x~i)≥u⋅w~k−1+γ  ⟹  u⋅w~k≥kγ.u \cdot \tilde{w}_k = u \cdot \tilde{w}_{k-1} + t_i (u \cdot \tilde{x}_i) \ge u \cdot \tilde{w}_{k-1} + \gamma \implies u \cdot \tilde{w}_k \ge k\gamma.
  2. Upper bound on squared norm: ∥w~k∥2=∥w~k−1∥2+2ti(w~k−1⋅x~i)+∥x~i∥2≤∥w~k−1∥2+R2  ⟹  ∥w~k∥2≤kR2.\|\tilde{w}_k\|^2 = \|\tilde{w}_{k-1}\|^2 + 2 t_i (\tilde{w}_{k-1}\cdot \tilde{x}_i) + \|\tilde{x}_i\|^2 \le \|\tilde{w}_{k-1}\|^2 + R^2 \implies \|\tilde{w}_k\|^2 \le k R^2.

By Cauchy–Schwarz, u⋅w~k≤∥u∥ ∥w~k∥=∥w~k∥u \cdot \tilde{w}_k \le \|u\|\,\|\tilde{w}_k\| = \|\tilde{w}_k\|, so:

kγ≤k R  ⟹  k≤(Rγ)2.k\gamma \le \sqrt{k}\,R \implies \boxed{k \le \left(\frac{R}{\gamma}\right)^2.}

A wider margin γ\gamma yields a smaller upper bound on convergence steps.

Linear Cut controls
Extra coordinate
25 of 40 misclassified.
w

0.60x1−0.80x2+0.10=00.60x_1-0.80x_2+0.10=0

The arrow is w=(w1,w2)w=(w_1,w_2), perpendicular to the boundary and pointing toward the circle class.

Circle: class 1Diamond: class 0; ringed points are misclassified

ErrorsUpdates →

XOR and Multilayer Networks#

Switching the dataset above to XOR (quadrants I & III vs. II & IV) prevents errors from ever reaching zero. For the four corners (1,1),(−1,−1)(1,1),(-1,-1) vs. (1,−1),(−1,1)(1,-1),(-1,1), a separating line would require:

w1+w2+b>0,−w1−w2+b>0,w1−w2+b≤0,−w1+w2+b≤0.\begin{aligned} w_1 + w_2 + b &> 0, & -w_1 - w_2 + b &> 0, \\ w_1 - w_2 + b &\le 0, & -w_1 + w_2 + b &\le 0. \end{aligned}

Summing the top row gives 2b>02b > 0; summing the bottom row gives 2b≤02b \le 0 — a contradiction. Minsky and Papert analyzed this limitation in Perceptrons (1969). Two paths overcome linear inseparability:

Path 1: Nonlinear Feature Lifting#

Lifting each point to (x1,x2,x1x2)(x_1, x_2, x_1 x_2) lets a single 3D hyperplane w1x1+w2x2+w3x1x2+b>0w_1 x_1 + w_2 x_2 + w_3 x_1 x_2 + b > 0 separate XOR (projecting back to a hyperbola in 2D). The drawback is manual feature engineering: a different distribution requires handcrafting new coordinates.

Path 2: Multilayer Composition and Differentiable Activations#

Two layers of threshold neurons express Boolean XOR (x1,x2∈{0,1}x_1, x_2 \in \{0,1\}) exactly:

h1=[x1+x2−0.5>0],h2=[x1+x2−1.5>0],y=[h1−h2−0.5>0].h_1 = [x_1 + x_2 - 0.5 > 0], \qquad h_2 = [x_1 + x_2 - 1.5 > 0], \qquad y = [h_1 - h_2 - 0.5 > 0].

The bottleneck then shifts to training: hidden units lack direct labels, and the step function has zero derivative everywhere z≠0z \ne 0. Replacing the step with differentiable activations such as Sigmoid σ(z)=11+e−z\sigma(z) = \frac{1}{1+e^{-z}} enables chain-rule backpropagation [2]. Because σ′(z)≤14\sigma'(z) \le \frac{1}{4} causes deep gradient decay, hidden layers later switched to ReLU.

Piecewise-Linear Geometry of ReLU and Depth Advantage#

Without nonlinearities, W2(W1x+b1)+b2=(W2W1)x+(W2b1+b2)W_2(W_1 x + b_1) + b_2 = (W_2 W_1)x + (W_2 b_1 + b_2) collapses to one affine map. With relu(z)=max⁡(0,z)\mathrm{relu}(z) = \max(0, z), each neuron zeroes one half-space and stays linear on the other, creating a crease along w⋅x+b=0w\cdot x + b = 0. Inside each connected region carved by all creases, every neuron’s active/inactive pattern is constant, so the network is a piecewise-affine function.

Polynomial Limit of Width#

In 2D, nn ReLU units in a single hidden layer draw nn lines. Line kk intersects at most k−1k-1 prior lines, splitting at most kk regions, so nn lines produce at most:

1+(1+2+⋯+n)=1+n+(n2)=n2+n+221 + (1 + 2 + \cdots + n) = 1 + n + \binom{n}{2} = \frac{n^2 + n + 2}{2}

regions (3737 for n=8n=8). For fixed input dimension, single-layer region count grows only polynomially in width.

Exponential Folding via Depth: Worked 1D Sawtooth#

On [0,1][0, 1], two ReLU neurons construct a tent function:

f(x)=2 relu(x)−4 relu ⁣(x−12)={2x,0≤x≤122−2x,12<x≤1f(x) = 2\,\mathrm{relu}(x) - 4\,\mathrm{relu}\!\left(x - \tfrac{1}{2}\right) = \begin{cases} 2x, & 0 \le x \le \tfrac{1}{2} \\ 2 - 2x, & \tfrac{1}{2} < x \le 1 \end{cases}

Composing ff with itself gives g(x)=f(f(x))g(x) = f(f(x)):

  • x∈[0,14]x \in [0, \tfrac{1}{4}]: 4x4x (0→10 \to 1)
  • x∈[14,12]x \in [\tfrac{1}{4}, \tfrac{1}{2}]: 2−4x2 - 4x (1→01 \to 0)
  • x∈[12,34]x \in [\tfrac{1}{2}, \tfrac{3}{4}]: 4x−24x - 2 (0→10 \to 1)
  • x∈[34,1]x \in [\tfrac{3}{4}, 1]: 4−4x4 - 4x (1→01 \to 0)

Each composition doubles the number of linear segments. Composing kk times uses only 2k2k ReLU neurons to generate 2k2^k segments of slope ±2k\pm 2^k, whereas a single hidden layer needs at least 2k−12^k - 1 ReLU units (for k=20k=20: 4040 vs. 1,048,5751{,}048{,}575 neurons).

Folding controls
Task
Activation
Stage 4 · One straight cut divides all 4 enclaves (64/64, 100%): unfold this single line back to the map on the right to see the complex multi-enclave border emerge!
Feature space (folding)
(−0.22, −0.05)
Original map (unfolded border)
(−0.52, −0.95)

Telgarsky (2016) [4] formalized this depth separation, and Montúfar et al. (2014) [3] established exponential lower bounds on linear regions with depth. This does not contradict the Universal Approximation Theorem [6]: a single hidden layer can approximate any continuous function on a compact domain, but the required width can grow exponentially.

Two-Spiral Training Experiment#

Training controls
Activation
Randomly initialized 2 → 8 → 1 network (48% accuracy). Press Train to start.
Shape
2 → 8 → 1
Params
33
Steps
0
Loss
0.730
Train acc.
48%

73×73 grid sampled 28 activation patterns; a single hidden layer of 8 units can cut at most 37 planar regions. Grid sampling can miss tiny regions, and distinct patterns may still share the same output.

CircleDiamond

LossSteps →

Under identical seed and optimization settings on 200 two-spiral points:

Hidden LayersParametersAccuracy at 6000 StepsSampled Linear Regions
1 × 83369%23
2 × 810598%89
3 × 8177100% (2370 steps)172

Two caveats: (1) Hanin & Rolnick (2019) [5] showed that at typical random initialization, the expected number of regions along a 1D line grows only linearly with total neurons rather than hitting the exponential ceiling; (2) if a ReLU unit outputs negative pre-activations on all samples, its gradient stays 00 (“dying ReLU”), which narrow layers hit more easily.

Gradient Issues in Deep and High-Dimensional Training#

Scaling Dot Products by dk\sqrt{d_k}#

If q,k∈Rdkq, k \in \mathbb{R}^{d_k} have independent entries with mean 00 and variance 11, then Var(qiki)=1\mathrm{Var}(q_i k_i) = 1 and Var(q⋅k)=dk\mathrm{Var}(q \cdot k) = d_k. At dk=256d_k = 256, the standard deviation is 1616, pushing Softmax toward one-hot distributions where the Jacobian ∂pi∂zj=pi(δij−pj)\frac{\partial p_i}{\partial z_j} = p_i(\delta_{ij} - p_j) vanishes. Dividing by dk\sqrt{d_k} [7] restores unit variance and keeps gradients alive (distinct from numerical overflow prevention via subtracting max⁡jzj\max_j z_j).

Scaling controls
Max weight 0.29, entropy 2.62 bits: clear preference while other positions still keep non-zero weight.
Scores q·k / √dₖ (y-axis ±2)k10.26k2k30.15k4k5k6k7k80.29Softmax weights (y-axis 0–1)
Score std dev
0.78 expected single-score std dev: 1
Max weight
0.294
Entropy
2.62 bits uniform = 3
∥∂p/∂s∥F\|\partial p/\partial s\|_F
0.372

Gradient Products and Residual Connections#

Backpropagating across LL layers multiplies LL Jacobians:

∂L∂h0=∂L∂hL∏l=1L∂hl∂hl−1.\frac{\partial \mathcal{L}}{\partial h_0} = \frac{\partial \mathcal{L}}{\partial h_L} \prod_{l=1}^{L} \frac{\partial h_l}{\partial h_{l-1}}.

With scalar gain aa, L=32L = 32 layers shrink a=0.9a=0.9 to 0.0340.034 and blow up a=1.1a=1.1 to 21.121.1.

Residual controls
Gradient reaching layer 1 is about 10−1.0 (1 at the top output). Already shrunk by about 11×; deeper behavior depends on the matrices and activation.
1e-211e2Layer 1 (closest to input)Layer 32
Each layer computes hl=tanh⁡(gWlhl−1)h_l=\tanh(gW_lh_{l-1}) (width 32, entries of WlW_l drawn from N(0,1/32)\mathcal N(0,1/32)). Bars show ∥∂L/∂hl−1∥\|\partial \mathcal L/\partial h_{l-1}\|, geometric mean over 8 fixed random inputs with a unit-vector inner-product loss. Gradient-flow demo only; no training is performed.

Residual connections [8] set hl=hl−1+F(hl−1)h_l = h_{l-1} + F(h_{l-1}), turning each Jacobian into I+∂F∂hl−1I + \frac{\partial F}{\partial h_{l-1}}. Expanding the product preserves an identity path II for gradients to flow directly to early layers. To prevent variance from growing with depth, GPT-2 [10] scales residual output projections by 1/N1/\sqrt{N} at initialization, and Pre-LN Transformers [9] stabilize early gradients further.

Open Questions#

Three core questions still lack a complete unified theory: (1) why overparameterized networks generalize under gradient descent instead of merely memorizing; (2) why first-order optimization rarely stalls in bad local minima on billion-dimensional non-convex landscapes; and (3) how to reliably identify and causally verify superposed features and circuits.

Further Reading#

  1. Welch Labs ↗ · François Fleuret: The Little Book of Deep Learning ↗.
  2. Papers: Rosenblatt (1958) ↗, Rumelhart et al. (1986) ↗, Montúfar et al. (2014) ↗, Telgarsky (2016) ↗, Hanin & Rolnick (2019) ↗, Cybenko (1989) ↗, Vaswani et al. (2017) ↗, He et al. (2016) ↗, Xiong et al. (2020) ↗, GPT-2 (2019) ↗.
Why Neural Networks Need Depth
https://fxj.wiki/en/blog/deep-learning-folding
Author MakkaPakka
Published at November 1, 2026
Comment seems to stuck. Try to refresh?✨