A Law of Next-Token Prediction in Large Language Models

Hangfeng He, Weijie J. Su · OpenReview

Abstract

Large language models (LLMs) have been widely employed across various application domains, yet their black-box nature poses significant challenges to understanding how these models process input data internally to make predictions. In this paper, we introduce a precise and quantitative law that governs the learning of contextualized token embeddings through intermediate layers in pre-trained LLMs for next-token prediction. Our findings reveal that each layer contributes equally to enhancing prediction accuracy, from the lowest to the highest layer -- a universal phenomenon observed across a diverse array of open-source LLMs, built on architectures such as Transformer, RWKV, and Mamba. We demonstrate that this law offers new perspectives and insights to inform and guide practices in LLM development and applications, including model scaling, pre-training tasks, and information flow. Overall, our law enables more fine-grained approaches to the design, training, and interpretation of LLMs through scrutinizing their internal data processing mechanisms.

Introduction

Despite their transformative capabilities, Large Language Models (LLMs) remain largely "black boxes." While the inputs and outputs are well-defined, the internal transformation of data across dozens of layers has been difficult to quantify. This paper identifies the "Law of Equi-learning": a universal principle where every layer in an LLM contributes an equal multiplicative factor toward improving next-token prediction. This quantitative law holds true across diverse architectures, suggesting that the internal processing of AI follows a much more disciplined rhythm than previously understood.

Methodology: The Prediction Residual

To measure internal learning, the researchers introduce the Prediction Residual (PR). At every layer of a pre-trained model, they freeze the embeddings and attempt to predict the next token using a simple linear probe. The PR represents the "fraction of variance unexplained" (statistically, $1 - R^2$). A high PR indicates the layer's embeddings are relatively uninformed about the next word, while a low PR shows they have captured the necessary features for prediction.

By plotting the PR of each layer on a logarithmic scale, the authors discovered a remarkably straight line, leading to the mathematical formulation: $$PR_l \approx \rho^{l-1} \times PR_1$$ where $l$ is the layer index and $\rho$ is a constant decay ratio. In essence, each layer reduces the remaining uncertainty by the same percentage.

Experimental Results and Universality

The study tested this law against a comprehensive suite of models, including GPT-1/2, Llama 1/2/3, Mistral, and phi-1.5/2/3. Crucially, the law is architecture-agnostic, holding for state-space models like Mamba and linear transformers like RWKV just as well as standard Transformers.

Linear decay of the Prediction Residual in Llama-1-13B, demonstrating the Law of Equi-learning.

Across almost all modern LLMs, the Pearson correlation between the layer index and the log of the Prediction Residual was stronger than -0.99. This suggests that the hierarchical feature learning process is exceptionally consistent across the model's depth.

The law holds for non-Transformer architectures like RWKV-14B, showing its fundamental nature.

Key Insights

  • Equi-learning: Feature learning is neither front-loaded nor back-loaded; every layer is equally important. The midpoint of a model typically achieves exactly half of the total predictive capability.
  • NTP Specificity: The law is uniquely clean for Next-Token Prediction (NTP). Models trained on different objectives, such as Masked Language Modeling (BERT), exhibit much noisier patterns, suggesting NTP is a uniquely "natural" objective for hierarchical learning.
  • Information Forgetting: As data moves through layers, the model actively "forgets" the past. While PR for the next token decreases, the PR for predicting the previous token actually increases in higher layers, showing a focus shift toward future prediction.

Discussion and Limitations

While the paper empirically proves the existence of this law, a full formal derivation from first principles remains an open challenge. Additionally, the law is most apparent using the PR metric; other metrics do not always show the pattern as clearly, indicating that token indices carry structural information that is not yet fully understood. Future applications may include using this law to optimize training schedules or improve model pruning and transfer learning.

Paper Citation: He, H., & Su, W. J. (2024). A Law of Next-Token Prediction in Large Language Models. arXiv:2408.13442v3.

Summary updated

BibTeX
@article{he2025law,
  author = {Hangfeng He and Weijie J. Su},
  title = {{A Law of Next-Token Prediction in Large Language Models}},
  journal = {Physical Review E},
  year = {2025},
  url = {https://openreview.net/forum?id=1LhlVI8xZb},
}
Figure