Grammar Sparsity Sets How Transformers Learn Random Languages

Edgar Andres Hernandez Moreno, Francesco CagnettaarXiv 2026

TL;DR

Why do some concepts take forever for an AI to learn while others seem to "click" instantly? This paper reveals that it’s not just the complexity of a language's structure that matters, but its sparsity—how many choices the rules allow at each step. Dense, choice-heavy grammars force Transformers into a slow, staged learning process with long plateaus, while sparse, predictable grammars are mastered all at once at lightning speed.

What Problem Does This Paper Address?

We know that Large Language Models (LLMs) are remarkably good at picking up the hierarchical structure of language—understanding how a subject at the start of a sentence governs a verb ten words later. However, the "learning schedule" of these models remains a bit of a mystery. Do they learn local patterns before global ones? How does the size of the vocabulary ($V$) affect the time it takes to "discover" these hidden structures?

Because natural language is fixed and messy, you can't easily experiment with it. You can't ask, "What if English had 10x more words but 10x fewer grammatical rules?" To solve this, the authors used a synthetic "Random Language Model" (RLM). This sandbox allows them to precisely control the grammar's sparsity using a single parameter ($\beta$), letting them observe exactly how a Transformer's learning dynamics change as the "predictability" of the language is dialed up or down.

Methods

The researchers trained deep Transformers (specifically, 2-layer decoder-only models) on 4-token sequences generated by a hierarchical tree.

The Random Language Model (RLM) generates sequences by expanding a root symbol into latent variables, which then become observed tokens.

The key experimental lever was the sparsity parameter, $\beta$:

  • Low $\beta$ (Dense): Each word can be followed by many different pairs of words. The "rule book" is thick and full of options.
  • High $\beta$ (Sparse): Each word has very few valid followers. The "rule book" is thin and highly specific.

They measured the "crossing times"—the specific training steps where the model successfully learned local correlations (siblings) versus the full hierarchical context (cousins)—and analyzed how these times scaled as they increased the vocabulary size from 12 to 512.

Datasets

The study used purely synthetic data generated on-the-fly from the RLM. By drawing fresh batches at every training step, the authors ensured the model was learning the underlying grammar rather than just memorizing a fixed dataset. This "infinite data" regime allowed them to isolate the effect of vocabulary size ($V$) on learning speed without worrying about overfitting.

Key Insights and Ideas

  • The "Plateau of Doom": In dense grammars, learning happens in distinct stages. The model first masters local "sibling" relationships (e.g., word 3 predicts word 4). It then hits a long, flat plateau where performance doesn't improve for a long time. Only much later does it "discover" the deeper hierarchical rules.
  • Sparse is Fast and Fluid: In sparse grammars, the plateau disappears. The model learns local and global structures simultaneously.
  • Scaling Laws: The time complexity of learning is vastly different between the two regimes. In dense grammars, the second stage of learning scales as $V^3$. If you double the vocabulary, that stage takes 8 times longer! In sparse grammars, the whole thing scales as $\sqrt{V}$, meaning doubling the vocabulary only increases training time by about 40%.
  • Adam’s Hidden Superpower: The researchers found that the $\sqrt{V}$ scaling in sparse regimes is a direct result of the Adam optimizer. In sparse settings, the "signal" for a specific rule is rare, but Adam’s gradient normalization helps the model "zoom in" on that rare signal much faster than standard SGD would.
Learning dynamics for dense (blue) vs. sparse (red) grammars. Note the long plateau in the dense case and the rapid, single-step drop in the sparse case.

Key Results

  • Dense Regime ($\beta=1.2$): The first learning stage scales linearly with vocabulary size ($t \propto V$), while the second stage scales cubically ($t \propto V^3$). This explains why complex, dense structures are so much harder to scale.
  • Sparse Regime ($\beta=6.0$): The model masters the entire grammar in a single step that scales as $t \propto \sqrt{V}$.
  • Sparsity Control: Figure 2 shows how the parameter $\beta$ effectively "freezes" the grammar, concentrating the probability onto just a few rules per symbol.
Heatmaps showing how increasing $\beta$ condenses the rule matrix from many active rules (dense) to just a few (sparse).

Limitations and Future Work

The authors acknowledge a few key areas for further exploration:

  • Depth: This study focused on depth-2 trees. Real-world language is a deep, recursive forest. It remains to be seen if these scaling laws hold for much deeper hierarchies.
  • The "Discovery" Mechanism: While the paper mathematically explains the first stage of learning, the exact mechanism by which the model eventually "breaks" the plateau in the dense regime is still partially heuristic.
  • Latent Variables: The paper touches on how depth helps in the dense regime (a second attention layer is often needed to reach the performance floor), but the precise way latent variables are "represented" internally is a topic for future research.

Summary updated

Abstract

We study language acquisition by transformers trained on the Random Language Model: a synthetic hierarchical grammar with random production rules, whose sparsity is controlled by a single parameter and whose conditional entropies are known exactly. On depth-two grammars, we find that sparsity sets both the order and the speed of learning. Dense grammars are learnt one level at a time: a token is predicted from its sibling after $t\propto V$ steps and from the full context only after $t\propto V^{3}$, so the two stages are separated by a plateau that widens with $V$. Sparse grammars are learnt all at once, at $t\propto\sqrt V$, with a smaller exponent than even the first stage of a dense one. The exponents $1$ and $1/2$ already appear at depth one, where we derive them for a linear model trained with Adam.
BibTeX
@misc{moreno2026grammar,
  author = {Edgar Andres Hernandez Moreno and Francesco Cagnetta},
  title = {{Grammar Sparsity Sets How Transformers Learn Random Languages}},
  year = {2026},
  eprint = {2611.29692},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.29692},
}
Figure