Towards a theory of how the structure of language is acquired by deep neural networks

Francesco Cagnetta, Matthieu Wyart

Abstract

How much data is required to learn the structure of a language via next-token prediction? We study this question for synthetic datasets generated via a Probabilistic Context-Free Grammar (PCFG) -- a tree-like generative model that captures many of the hierarchical structures found in natural languages. We determine token-token correlations analytically in our model and show that they can be used to build a representation of the grammar's hidden variables, the longer the range the deeper the variable. In addition, a finite training set limits the resolution of correlations to an effective range, whose size grows with that of the training set. As a result, a Language Model trained with increasingly many examples can build a deeper representation of the grammar's structure, thus reaching good performance despite the high dimensionality of the problem. We conjecture that the relationship between training set size and effective range of correlations holds beyond our synthetic datasets. In particular, our conjecture predicts how the scaling law for the test loss behaviour with training set size depends on the length of the context window, which we confirm empirically in Shakespeare's plays and Wikipedia articles.

Introduction

Large Language Models (LLMs) have demonstrated an uncanny ability to master complex linguistic structures through simple next-token prediction. However, the underlying mechanism—how these models transition from learning simple word associations to grasping deep hierarchical syntax—remains largely a "black box." This research, presented at NeurIPS 2024, addresses this gap by proposing a theoretical framework that links the statistical properties of training data to the empirical scaling laws observed in deep learning.

A central debate in linguistics is the "poverty of the stimulus," which suggests that the data available to human learners is insufficient to learn grammar from scratch. LLMs challenge this notion by training on massive corpora. This paper seeks to quantify exactly how much data is needed to resolve specific levels of linguistic hierarchy and how the context window length limits this learning process.

The Random Hierarchy Model (RHM)

To study these questions rigorously, the authors employ the Random Hierarchy Model (RHM), a type of Probabilistic Context-Free Grammar (PCFG). In this model, language is generated through a tree structure: a root symbol produces hidden intermediate symbols, which eventually branch out into the terminal tokens (words) we observe.

The key insight is that the "depth" of a linguistic feature in the tree is encoded in the "range" of the correlations between tokens. Tokens sharing a common ancestor deep in the tree exhibit faint, long-range statistical dependencies.

The Random Hierarchy Model (left) generates tokens via a tree structure. As the training set size $P$ increases (right), the model can resolve correlations at increasingly larger token distances $t$, effectively lowering the "noise floor."

Data as a Microscope: Resolving the Noise Floor

The theory posits that a finite training set size ($P$) introduces a "noise floor" due to sampling error. A neural network can only learn a dependency if the correlation signal is stronger than this noise. As $P$ increases, the noise floor drops, acting like a higher-resolution microscope that allows the model to "see" more subtle, long-range correlations.

This leads to the concept of an effective context window ($t^*$). Even if a model has a large physical context window, it can only utilize information within a range $t^*$ that is supported by the available data. As $P$ grows, $t^*$ expands, "unlocking" deeper levels of the grammatical hierarchy. This explains why certain emergent abilities, such as complex reasoning or sophisticated grammar, only appear after the model has processed a specific threshold of data.

Empirical Scaling Laws and Step-wise Learning

The authors' theory predicts that learning occurs in distinct stages. In synthetic RHM experiments, the test cross-entropy drops in "steps," where each step corresponds to the model successfully resolving a new, deeper layer of the generative tree.

Furthermore, the research derives a context-dependent scaling law: $$\mathcal{L}(P, t) = t^{-\alpha z} f(P/t^z)$$ This formula predicts how test loss behaves when both dataset size ($P$) and context length ($t$) are varied. Crucially, it shows that if the context window is limited, performance will eventually saturate; the model cannot learn the deeper hierarchical structures required for further improvement because it cannot "see" the necessary long-range signals.

Test cross-entropy as a function of training set size $P$ for different context lengths $t$. The curves show characteristic "steps" as deeper levels of hierarchy are resolved, and saturation occurs when the context window $t$ is too small to capture longer-range dependencies.

These predictions were empirically confirmed not only on synthetic data but also on natural language datasets like Tiny Shakespeare and English Wikipedia. The "scaling exponent" of the model was found to be directly tied to the power-law decay of token correlations in the underlying text.

Conclusion and Future Directions

This work provides a foundational step toward a theory of language acquisition in neural networks. By treating data as a resolution-limiting factor, it explains the emergence of hierarchical understanding and the origin of scaling laws.

Future work may extend this framework to context-sensitive grammars, which more accurately reflect the fluidity of natural language. Additionally, exploring the interaction between dataset size ($P$) and the number of model parameters ($N$) remains a key challenge for a complete theory of LLM scaling.

Summary updated

Abstract

How much data is required to learn the structure of a language via next-token prediction? We study this question for synthetic datasets generated via a Probabilistic Context-Free Grammar (PCFG) -- a tree-like generative model that captures many of the hierarchical structures found in natural languages. We determine token-token correlations analytically in our model and show that they can be used to build a representation of the grammar's hidden variables, the longer the range the deeper the variable. In addition, a finite training set limits the resolution of correlations to an effective range, whose size grows with that of the training set. As a result, a Language Model trained with increasingly many examples can build a deeper representation of the grammar's structure, thus reaching good performance despite the high dimensionality of the problem. We conjecture that the relationship between training set size and effective range of correlations holds beyond our synthetic datasets. In particular, our conjecture predicts how the scaling law for the test loss behaviour with training set size depends on the length of the context window, which we confirm empirically in Shakespeare's plays and Wikipedia articles.
BibTeX
@inproceedings{cagnetta2024towards,
  author = {Francesco Cagnetta and Matthieu Wyart},
  title = {{Towards a theory of how the structure of language is acquired by deep neural networks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=NaCXcUKihH},
}
Figure