Simple Algorithm
Deep Learning · Emergence · 28 min

Memorization Capacity

How many parameters it takes to fit any n labels, and why that is fewer than you think.

Fitting nn arbitrary labels sounds like it needs about nn parameters, one per label, and with one hidden layer it does. With depth, about n\sqrt n parameters suffice, provided each of them carries about n\sqrt n bits. Counting arguments show that both numbers are optimal, and they reveal where the information actually lives.

What you’ll learn

  • Prove that a one-hidden-layer ReLU network with 2n+d2n+d weights fits any labels on nn distinct points in Rd\R^d, and state the matching lower bounds for one and two hidden layers.
  • Derive the Ω~(n)\tilde\Omega(\sqrt n) lower bound on parameters from the VC dimension of piecewise-linear networks, and the bit-counting bound WB≥nWB\ge n.
  • State the optimal O~(n)\tilde O(\sqrt n) construction of Vardi, Yehudai and Shamir with its separation assumption and its cost in precision, and sketch how it stores labels in weights and reads them out with depth.
  • Relate capacity to practice: interpolation by overparameterized gradient descent, random-label experiments, and the measured knowledge capacity of language models.

Fitting n labels with n units

A single linear threshold unit in Rd\R^d realizes about half of all labelings of 2d2d points in general position, about two patterns per weight (Cover, 1965). One hidden layer gives capacity linear in its size: ⌈n/d⌉\lceil n/d\rceil threshold units memorize any binary labels on nn points in general position (Baum, 1988); nn units of any bounded nonlinear activation with a limit at +∞+\infty or −∞-\infty fit nn distinct points with arbitrary real labels (Huang & Babri, 1998); 4⌈n/d⌉4\lceil n/d\rceil ReLUs fit real labels on points in general position (Bubeck, Eldan, Lee & Mikulincer, 2020). Each of these units has dd incoming weights, so the parameter count stays of order nn. The cleanest statement is for ReLUs and arbitrary distinct points.

DerivationProof
  1. zi=a⊤xi,z1<z2<⋯<znz_i=\mathbf a^\top\mathbf x_i,\qquad z_1<z_2<\cdots<z_n

    All hidden units share one direction a∈Rd\mathbf a\in\R^d. Each difference xi−xj\mathbf x_i-\mathbf x_j is nonzero, so the directions orthogonal to it form a hyperplane; any a\mathbf a off these finitely many hyperplanes (almost every a\mathbf a) gives distinct projections. Relabel the points so the projections increase:

  2. b1<z1<b2<z2<⋯<bn<zn⟹Aij=ReLU⁡(zi−bj)={zi−bj>0j≤i,0j>i.b_1<z_1<b_2<z_2<\cdots<b_n<z_n\quad\Longrightarrow\quad A_{ij}=\operatorname{ReLU}(z_i-b_j)=\begin{cases}z_i-b_j>0 & j\le i,\\ 0 & j>i.\end{cases}

    Interleave the thresholds with the sorted projections. Unit jj is then active on point ii exactly when bj<zib_j<z_i, that is, when j≤ij\le i:

  3. c(xi)=∑j=1nAijwj=yi  (i=1,…,n)⟺Aw=y,w=A−1yc(\mathbf x_i)=\sum_{j=1}^nA_{ij}w_j=y_i\ \ (i=1,\dots,n)\quad\Longleftrightarrow\quad A\mathbf w=\mathbf y,\qquad \mathbf w=A^{-1}\mathbf y

    So AA is lower triangular with a positive diagonal Aii=zi−biA_{ii}=z_i-b_i, hence invertible, and the output weights solve a triangular system by forward substitution, whatever the labels:

  4. d⏟a+n⏟b+n⏟w=2n+d\underbrace{d}_{\mathbf a}+\underbrace{n}_{\mathbf b}+\underbrace{n}_{\mathbf w}=2n+d

    The parameters are a\mathbf a, the thresholds b\mathbf b and the output weights w\mathbf w. The same idea trades width for depth: split the sorted projections into groups, fit one group per layer and add a small subnetwork that selects the right group's output. For every k≥2k\ge2 this gives depth kk, width O(n/k)\order{n/k} and still O(n+d)\order{n+d} weights (Zhang et al., 2017, Corollary 1).

Predict before you look

How many weights does this construction need to fit arbitrary real labels on n=1000n=1000 distinct images of 28×2828\times28 pixels (d=784d=784)?

Show the answer

2784 weights

2n+d=2000+784=27842n+d=2000+784=2784. A small 784–256–10 classifier has over 200,000 parameters, seventy times more. Fitting arbitrary labels on a dataset of this size is cheap in parameters; what such a fit is worth is another question (The Generalization Puzzle).

For one hidden layer this is essentially optimal. Yun, Sra & Jadbabaie (2019) counted linear pieces of the network along a line: a one-hidden-layer ReLU network with mm units fails to fit some dataset of nn distinct points with labels in [−1,1][-1,1] whenever m+2<nm+2<n, and a network with two hidden layers of widths d1,d2d_1,d_2 fails whenever 2d1d2+d2+2<n2d_1d_2+d_2+2<n. Conversely, two hidden layers of width 2n2\sqrt n fit any such dataset. Hidden units can thus drop to about 4n4\sqrt n, but the d1d2≈4nd_1d_2\approx4n weights between the two layers keep the parameter count linear.

Lower bounds: shattering and bits

A network that memorizes every labeling of nn points shatters them, so its class has VC dimension at least nn. For ReLU networks, and for any piecewise-linear activation, the VC dimension is known almost exactly (Bartlett, Harvey, Liaw & Mehrabian, 2019). With WW weights in LL layers:

VCdim⁡=O(W Llog⁡W),and some networks reach  Ω(W Llog⁡(W/L))\operatorname{VCdim}=\order{W\,L\log W},\qquad\text{and some networks reach }\ \Omega\big(W\,L\log(W/L)\big)
Depth enters linearly. For piecewise-constant activations such as threshold units the VC dimension does not grow with depth, and for piecewise-polynomial ones it grows at most quadratically. Earlier, Goldberg and Jerrum (1995) had bounded it by O(W2)\order{W^2} for networks with piecewise-polynomial activations.
DerivationTwo counting bounds
  1. n≤C W Llog⁡W≤C W2log⁡W ⟹ W ≥ cnlog⁡n;n≤C′W2 ⟹ W ≥ c′nn\le C\,W\,L\log W\le C\,W^2\log W\ \Longrightarrow\ W\ \ge\ c\sqrt{\frac{n}{\log n}};\qquad n\le C'W^2\ \Longrightarrow\ W\ \ge\ c'\sqrt n

    Shattering. Memorizing all labelings of nn points needs VCdim⁡≥n\operatorname{VCdim}\ge n. Every layer contains at least one weight, so L≤WL\le W, and the upper bound gives the first bound below. Goldberg and Jerrum's bound VCdim⁡=O(W2)\operatorname{VCdim}=\order{W^2}, which holds at any depth, removes the logarithm:

  2. W=Ω(nLlog⁡n)(depth L)W=\Omega\Big(\frac{n}{L\log n}\Big)\qquad(\text{depth }L)

    At a fixed depth LL the same bound reads W≥n/(CLlog⁡W)W\ge n/(CL\log W). Shallow networks therefore need nearly linear parameter counts; only depth that grows with nn can bring the count down to n\sqrt n.

  3. 2WB ≥ 2n⟹W B ≥ n2^{WB}\ \ge\ 2^n\quad\Longrightarrow\quad W\,B\ \ge\ n

    Bits. Count functions instead of points. If each of the WW weights is stored in BB bits, a fixed architecture has at most 2WB2^{WB} settings, hence at most 2WB2^{WB} distinct functions. The 2n2^n binary labelings of nn points need 2n2^n distinct functions:

  4. W≈n⟹B ≳ n  bits per weightW\approx\sqrt n\quad\Longrightarrow\quad B\ \gtrsim\ \sqrt n\ \text{ bits per weight}

    So a network with n\sqrt n weights must give each of them about n\sqrt n bits. Vardi, Yehudai & Shamir (2022) prove the refined bound VCdim⁡=O(WB+Wlog⁡W)\operatorname{VCdim}=\order{WB+W\log W} and show that Θ~(n)\tilde\Theta(\sqrt n) bits per weight are both necessary and sufficient for memorization with Θ~(n)\tilde\Theta(\sqrt n) weights. Precision is the hidden currency of memorization.

Predict before you look

A float32 network (32 bits per weight) must realize every one of the 2n2^n binary labelings of n=106n=10^6 fixed points. By the bit-counting bound, how many weights does it need at the very least?

Show the answer

31250 weights

WB≥nWB\ge n with B=32B=32 gives W≥106/32=31,250W\ge10^6/32=31{,}250. At standard precision memorization is linear in nn again, at best one weight per 32 labels. The sublinear constructions below need weights far more precise than any hardware stores.

Square-root memorization with depth

Between the O(n)\order n constructions and the Ω~(n)\tilde\Omega(\sqrt n) lower bound, depth closes the gap in stages:

ResultHidden unitsParametersDepthAssumption on the inputs
Zhang et al. (2017)nn2n+d2n+done hidden layerdistinct
Yun, Sra & Jadbabaie (2019)≈4n\approx4\sqrt nΘ(n)\Theta(n)two hidden layersdistinct; labels in [−1,1][-1,1]
Park, Lee, Yun & Shin (2021)—O(n2/3+log⁡(1/δ))\order{n^{2/3}+\log(1/\delta)} for constant ddgrows with nnδ\delta-separated
Vardi, Yehudai & Shamir (2022)width 12O~(d+n)\tilde O(d+\sqrt n)O~(n)\tilde O(\sqrt n)δ\delta-separated, in a ball of radius rr
Hidden units fall to about n\sqrt n with just two hidden layers, but the weights do not. Sublinear parameter counts need depth that grows with nn, an assumption that keeps the points apart, and very precise weights.
DerivationHow the construction stores labels in its weights
  1. ∣u⊤(xi−xj)∣ ≥ 8πd ∥xi−xj∥n2(i≠j)\abs{\mathbf u^\top(\mathbf x_i-\mathbf x_j)}\ \ge\ \sqrt{\frac{8}{\pi d}}\ \frac{\norm{\mathbf x_i-\mathbf x_j}}{n^2}\qquad(i\ne j)

    Project. One unit projects the data onto a well-chosen unit vector u\mathbf u that shrinks no pairwise distance too much. After shifting and scaling, the projections are distinct numbers at least 2 apart in [0,R][0,R]:

  2. uj=[ ⌊x(1)⌋ ∣ ⌊x(2)⌋ ∣ ⋯ ]2,wj=[ y(1) ∣ y(2) ∣ ⋯ ]2u_j=\big[\,\lfloor x_{(1)}\rfloor\ \big|\ \lfloor x_{(2)}\rfloor\ \big|\ \cdots\,\big]_2,\qquad w_j=\big[\,y_{(1)}\ \big|\ y_{(2)}\ \big|\ \cdots\,\big]_2

    Pack. Sort the projections and cut them into nlog⁡n\sqrt{n\log n} intervals of n/log⁡n\sqrt{n/\log n} consecutive points. For interval jj, write the rounded positions of its points side by side in the binary expansion of one integer uju_j (log⁡R\log R bits each) and their labels side by side in another integer wjw_j (log⁡C\log C bits each). These integers become weights, each of O~(n)\tilde O(\sqrt n) bits.

  3. F2(x)=(x, wj(x), uj(x))F_2(x)=\big(x,\ w_{j(x)},\ u_{j(x)}\big)

    Find the interval. A constant-width subnetwork compares the input xx with the interval boundaries and outputs the integers of the interval it falls in:

  4. width=12,depth=O~(n),parameters=O~(n),bits per weight=O~(n)\text{width}=12,\qquad\text{depth}=\tilde O(\sqrt n),\qquad\text{parameters}=\tilde O(\sqrt n),\qquad\text{bits per weight}=\tilde O(\sqrt n)

    Extract. A deep subnetwork reads uju_j one block of log⁡R\log R bits at a time, using compositions of Telgarsky's triangle function to peel off binary digits, the same tent map that built the sawtooth in What Networks Can Represent. When a block matches xx to within 1, which by the separation happens for exactly one point, it extracts the matching log⁡C\log C bits of wjw_j and outputs them. Each digit costs a few layers of constant width, so the depth grows with the number of bits in one interval:

Check your understanding

The square-root construction memorizes any nn points that are δ\delta-separated. Yet for standard activations, networks with fewer than about n/2n/2 parameters cannot shatter every set of nn points in general position (Sontag, 1997). Why is there no contradiction?

  1. Sontag's bound concerns only networks with a single hidden layer
  2. The construction memorizes only binary labels, while the bound concerns real-valued labels
  3. The lower bound may use points packed arbitrarily close together, while the construction assumes a separation δ\delta and its size grows with log⁡(1/δ)\log(1/\delta)
  4. The construction is randomized, so it memorizes only most datasets, not all of them
Show the answer

C. The lower bound may use points packed arbitrarily close together, while the construction assumes a separation δ\delta and its size grows with log⁡(1/δ)\log(1/\delta)

Sublinear memorization needs some assumption, and separation is the one used: δ\delta enters the depth through log⁡R\log R, with R∝n2/δR\propto n^2/\delta. For a fixed parameter budget, sets packed tightly enough are out of reach, so the two results describe different families of inputs.

What training does with capacity

The constructions place weights by hand. Three threads connect them to networks trained by gradient descent.

Gradient descent finds interpolants. With enough width, gradient descent from random initialization drives the training loss of a two-layer ReLU network to zero on any inputs of which no two are parallel, at a linear rate (Du, Zhai, Póczos & Singh, 2019), and similar results hold for deep networks (Allen-Zhu, Li & Song, 2019). The widths these proofs need are large polynomials in nn, far above the constructions; the mechanism, a nearly fixed kernel, is the subject of Loss Landscapes. How fast labels are fitted depends on how they align with that kernel's top eigenvectors: true labels align well and random labels do not, so gradient descent fits random labels more slowly (Arora, Du, Hu, Li & Wang, 2019). Spectral Bias & Fourier Features develops this frequency picture.

Real networks memorize far below the bit budget. Zhang et al. (2017) trained an Inception-style network with 1.65 million parameters to 100% training accuracy on CIFAR-10's 50,000 images with random labels, taking only a small constant factor longer than with the true labels. Those labels carry 50,000×log⁡210≈166,00050{,}000\times\log_210\approx166{,}000 bits: about 0.1 bit per parameter, against the 32 bits a float32 weight can hold.

Knowledge capacity. Allen-Zhu & Li (2025) trained language models on synthetic biographies and measured the stored facts in bits. They found about 2 bits per parameter, provided each fact appeared about 1,000 times in training; 8-bit quantization preserved this, while 4-bit quantization cut it by more than half. It is an empirical regularity on controlled data, not a theorem, but it places trained networks within a factor of 16 of the float32 counting bound, and very far from the n\sqrt n-bit weights of the optimal constructions.

Capacity results say what a network can memorize. Whether memorizing hurts, and why fitting rare examples can be necessary for good accuracy, are questions about the data distribution, taken up in The Generalization Puzzle and Memorization & the Long Tail.

Key takeaways

  • With one hidden layer, 2n+d2n+d weights fit any labels on nn distinct points (project, sort, interleave the thresholds, solve a triangular system), and about nn units are also necessary.
  • The VC dimension O(WLlog⁡W)\order{WL\log W} of ReLU networks forces W=Ω~(n)W=\tilde\Omega(\sqrt n) for memorization, and Ω~(n/L)\tilde\Omega(n/L) at depth LL; counting bits forces WB≥nWB\ge n.
  • With depth O~(n)\tilde O(\sqrt n), width 12 and weights of O~(n)\tilde O(\sqrt n) bits, O~(n)\tilde O(\sqrt n) parameters memorize any δ\delta-separated points (Vardi, Yehudai & Shamir, 2022). It is optimal up to logarithms, and possible only because each weight stores many labels.
  • Trained networks use far less: overparameterized gradient descent interpolates readily, random labels on CIFAR-10 cost about 0.1 bit per parameter, and language models store about 2 bits of knowledge per parameter in controlled experiments.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

In the 2n+d2n+d construction, what guarantees that the output weights can fit any labels?

  1. The projection direction is chosen by gradient descent to separate the labels
  2. Each hidden unit is active on exactly one data point
  3. Interleaving the thresholds with the sorted projections makes Aij=ReLU⁡(zi−bj)A_{ij}=\operatorname{ReLU}(z_i-b_j) lower triangular with a positive diagonal, so AA is invertible
  4. The number of weights exceeds the number of labels, so a solution always exists
Show the answer

C. Interleaving the thresholds with the sorted projections makes Aij=ReLU⁡(zi−bj)A_{ij}=\operatorname{ReLU}(z_i-b_j) lower triangular with a positive diagonal, so AA is invertible

Unit jj is active exactly on the points with zi>bjz_i>b_j, that is, on points j,…,nj,\dots,n. The resulting triangular system Aw=yA\mathbf w=\mathbf y has a unique solution for every y\mathbf y.

Question 2

ReLU networks with WW weights and depth LL have VC dimension O(WLlog⁡W)\order{WL\log W}. What does this imply for networks that memorize every labeling of nn points?

  1. They need at least about n/log⁡n\sqrt{n/\log n} weights, and about n/(Llog⁡n)n/(L\log n) at fixed depth LL
  2. They need at least nn weights, whatever their depth
  3. They need at least nlog⁡nn\log n weights
  4. Nothing, because VC dimension is about generalization rather than fitting
Show the answer

A. They need at least about n/log⁡n\sqrt{n/\log n} weights, and about n/(Llog⁡n)n/(L\log n) at fixed depth LL

Memorization requires VCdim⁡≥n\operatorname{VCdim}\ge n. With L≤WL\le W, n≤CW2log⁡Wn\le CW^2\log W gives W=Ω(n/log⁡n)W=\Omega(\sqrt{n/\log n}); at fixed depth, W=Ω(n/(Llog⁡n))W=\Omega(n/(L\log n)). Goldberg and Jerrum's O(W2)\order{W^2} sharpens the first to Ω(n)\Omega(\sqrt n), which Vardi et al. (2022) match up to a log⁡n\sqrt{\log n} factor.

Question 3

Why can't a float32 network with n\sqrt n weights memorize arbitrary binary labels on n=106n=10^6 points?

  1. Its VC dimension is exactly n\sqrt n
  2. Float32 cannot represent the separation between the points
  3. A network with n\sqrt n weights would need depth n\sqrt n, and its gradients would vanish
  4. Its weights hold 32n=32,00032\sqrt n=32{,}000 bits, but distinguishing all 2n2^n labelings takes n=106n=10^6 bits
Show the answer

D. Its weights hold 32n=32,00032\sqrt n=32{,}000 bits, but distinguishing all 2n2^n labelings takes n=106n=10^6 bits

A fixed architecture with WW weights of BB bits computes at most 2WB2^{WB} functions, so WB≥nWB\ge n is necessary. With W=1000W=1000 and B=32B=32 that is 32,000 bits against 10610^6 needed. The square-root constructions escape only by using weights of about n\sqrt n bits each.

Question 4

Zhang et al. (2017) fitted CIFAR-10's 50,000 training images with random labels using a network of 1.65 million parameters. About how many bits of label information is that per parameter?

  1. about 3.3
  2. about 0.1
  3. about 2
  4. about 32
Show the answer

B. about 0.1

Each random label among 10 classes carries log⁡210≈3.32\log_210\approx3.32 bits, so the dataset holds about 166,000166{,}000 bits, or 166,000/1,650,000≈0.1166{,}000/1{,}650{,}000\approx0.1 bit per parameter. The network used only a sliver of its storage.

Further reading

  • C. Zhang, S. Bengio, M. Hardt, B. Recht & O. Vinyals, "Understanding deep learning requires rethinking generalization," ICLR (2017).
  • C. Yun, S. Sra & A. Jadbabaie, "Small ReLU networks are powerful memorizers: a tight analysis of memorization capacity," NeurIPS (2019).
  • G. Vardi, G. Yehudai & O. Shamir, "On the optimal memorization power of ReLU neural networks," ICLR (2022).
  • P. L. Bartlett, N. Harvey, C. Liaw & A. Mehrabian, "Nearly-tight VC-dimension and pseudodimension bounds for piecewise linear neural networks," JMLR 20 (2019).
  • Z. Allen-Zhu & Y. Li, "Physics of language models: Part 3.3, knowledge capacity scaling laws," ICLR (2025).