How Much Information Can We Fit inside a Transformer?
Organizations: Purdue University
Abstract
How efficiently can transformers store factual knowledge? The answer to this question has implications for both model design and understanding the limits of transformer-based systems. Prior studies observe a linear relationship between the number of facts memorized and the number of model parameters required, substantially worse than what theoretical analyses predict is achievable. We re-examine empirical scaling: through rigorous and systematic experiments, including extensive hyperparameter search via Bayesian optimization, we determine the smallest model that can perfectly memorize a given set of facts, and measure how this minimum size scales with the number of facts. On synthetic datasets of random, independent (subject, relation, object) triples---e.g., (Paris, capital_of, France) ---drawn at random with no exploitable structure, we find that memorization capacity, the size of the largest dataset that a model memorizes completely, grows exponentially with the transformer dimension. Equivalently, the minimum transformer dimension required to memorize facts grows logarithmically in . Across 11 dataset sizes spanning to , a lack-of-fit F-test does not reject the logarithmic fit (with an offset), but it does reject all other tested alternatives including power-law. Along the depth axis, however, at fixed width, the maximum memorizable dataset size grows sublinearly with the number of layers over the measured range. We further extend our exploration to structured data containing symmetric relations or two-hop composition. In this setting, we find that transformers exploit these regularities to further improve capacity. All code to reproduce our results is available at https://github.com/Magronox/transformer_information_capacity.
Figures & tables
| Functional form | Best fit | Lack-of-fit -value | |
|---|---|---|---|
| Logarithmic + offset | |||
| Logarithmic | |||
| Power-law + offset | |||
| Power-law | |||
| Linear |
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Parameter | Search space | Notes |
|---|---|---|
| Learning rate | (log) | depth: |
| Use weight decay | gate; if False, | |
| Weight decay | (log) | only sampled when gate is True |
| Min-LR ratio | (log) | |
| Schedule-shape: | ||
| Decay end step | step (after warmup) where decay ends | |
| Entities ( ) | Facts ( ) | Information (Bits) | Seeds (10 / 20 / 30) | Mean | Best |
|---|---|---|---|---|---|
| 15 | 45 | 176 | 2 / 2 / 2 | 2.00 | 2 |
| 30 | 90 | 442 | 3 / 4 / 2 | 3.00 | 2 |
| 60 | 180 | 1,063 | 3 / 3 / 3 | 3.00 | 3 |
| 120 | 360 | 2,486 | 4 / 4 / 4 | 4.00 | 4 |
| 260 | 780 | 6,257 | 4 / 4 / 5 | 4.33 | 4 |
| 520 | 1,560 | 14,075 | 5 / 5 / 5 | 5.00 | 5 |
| Body % | ||||
|---|---|---|---|---|
| 45 | 3.33 | 75% | 1.0 | 0.72 |
| 90 | 4.00 | 66% | 1.8 | 1.15 |
| 180 | 5.00 | 54% | 2.8 | 1.54 |
| 360 | 6.67 | 44% | 3.9 | 1.71 |
| 780 | 9.00 | 32% | 5.7 | 1.80 |
| 1,560 | 10.33 | 21% | 9.8 | 2.06 |
| Functional form | Best fit | Lack-of-fit | |
|---|---|---|---|
| Linear without intercept | |||
| Linear with intercept | |||
| Power-law, exponent | |||
| Exponential | |||
| Logarithmic | |||
| Power-law |
| 45 | 90 | 180 | 360 | 780 | 1,560 | 3,120 | 6,240 | |
|---|---|---|---|---|---|---|---|---|
| OLMo-3 | 2.00 | 3.00 | 3.00 | 4.00 | 4.33 | 5.00 | 6.00 | 6.00 |
| GPT-2 | 3.33 | 4.00 | 5.00 | 6.67 | 9.00 | 10.33 | 12.67 | 14.33 |
| layers | 1 | 2 | 4 | 6 | 8 | 12 | 16 |
|---|---|---|---|---|---|---|---|
| max (mean) | 730 | 1,580 | 2,560 | 3,010 | 3,290 | 4,160 | 4,850 |
| smallest seed | 720 | 990 | 2,310 | 2,940 | 3,180 | 3,990 | 4,530 |
| largest seed | 750 | 2,010 | 2,760 | 3,060 | 3,420 | 4,320 | 5,010 |
| width | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 13 | 14 | 16 |
| (measured) | 34 | 89 | 214 | 452 | 704 | 918 | 1,584 | 4,433 | 7,379 | 10,129 |
| (Table 1 fit) | 35 | 85 | 158 | 413 | 628 | 939 | 1,384 | 4,270 | 6,173 | 12,841 |
| difference |
| Functional form | Best fit | Lack-of-fit | |
|---|---|---|---|
| Logarithmic + offset | |||
| Logarithmic | |||
| Power-law + offset | |||
| Power-law | |||
| Linear |
| entities | 9216 | 4608 | 3072 | 2304 | 1152 | 576 | 288 | 144 | 96 |
| relations | 1 | 2 | 3 | 4 | 8 | 16 | 32 | 64 | 96 |
| min. dimension to memorize all facts | 6.00 | 10.67 | 15.33 | 19.00 | 29.33 | 38.00 | 44.00 | 46.33 | 45.00 |
Memorization in Language Models
Memorization in language models studies how training examples and facts are stored, recalled, generalized, and exposed by model parameters.
See all 117 papers