Deep networks learn to parse uniform-depth context-free languages from local statistics

Jack T. Parley, Francesco Cagnetta, Matthieu Wyart

Abstract

Understanding how the structure of language can be learned from sentences alone is a central question in both cognitive science and machine learning. Studies of the internal representations of Large Language Models (LLMs) support their ability to parse text when predicting the next word, while representing semantic notions independently of surface form. Yet, which data statistics make these feats possible, and how much data is required, remain largely unknown. Probabilistic context-free grammars (PCFGs) provide a tractable testbed for studying these questions. However, prior work has focused either on the post-hoc characterization of the parsing-like algorithms used by trained networks; or on the learnability of PCFGs with fixed syntax, where parsing is unnecessary. Here, we (i) introduce a tunable class of PCFGs in which both the degree of ambiguity and the correlation structure across scales can be controlled; (ii) provide a learning mechanism -- an inference algorithm inspired by the structure of deep convolutional networks -- that links learnability and sample complexity to specific language statistics; and (iii) validate our predictions empirically across deep convolutional and transformer-based architectures. Overall, we propose a unifying framework where correlations at different scales lift local ambiguities, enabling the emergence of hierarchical representations of the data.

Introduction: The Challenge of Learning Structure

A fundamental debate in linguistics concerns how hierarchical language structure is acquired from linear text. While Large Language Models (LLMs) demonstrate an impressive ability to internalize syntax and semantics, the underlying statistical drivers and the precise data requirements (sample complexity) for this learning remain poorly understood.

Previous research often utilized Probabilistic Context-Free Grammars (PCFGs) with fixed syntax, where the tree structure is predetermined, bypassing the core challenge of parsing: resolving ambiguity. This paper addresses the more realistic scenario where grammar allows for varying tree structures, creating local and global ambiguities that a network must navigate to correctly interpret a string.

Ambiguity in natural language (left) and the synthetic Random Hierarchy Model (right).

Methods: The Varying-tree Random Hierarchy Model

To study this, the authors developed the Varying-tree Random Hierarchy Model (RHM), a tunable class of PCFGs. Unlike fixed models, the RHM uses production rules that generate strings of varying lengths (binary and ternary), introducing syntactic ambiguity.

The researchers proposed an iterative learning algorithm based on the "method of moments." This algorithm operates layer-by-layer, analyzing covariances between the root label and adjacent tokens to deduce hidden grammar rules. This theoretical framework was then validated using Convolutional Neural Networks (CNNs), Transformers, and a specialized "Inside Neural Network" (INN) architecture.

Key Insights: Resolving Ambiguity through Correlation

The study reveals several critical mechanisms in grammar learning:

  • Ambiguity Phase Transition: A sharp threshold exists ($f_c = 3/8$) for the fraction of active rules. Below this, the language is globally unambiguous; above it, sentences become unclassifiable due to multiple valid root meanings.
  • Hierarchical Correlation: Networks learn by identifying token groups that correlate with the final task. By measuring these correlations, the network builds hierarchical latent variables.
  • Whitening for Disambiguation: To isolate complex ternary rules from overlapping binary ones, networks effectively "whiten" the data, subtracting spurious signals from simpler structures.
  • The "Easiest Branch" Bottleneck: Sample complexity is determined by the path from root to leaves with the fewest ternary rules, representing the hardest-to-measure covariance.

Results: A Universal Scaling Law for Sample Complexity

The most significant finding is a precise theoretical formula for sample complexity: $P^* \sim v m_2^{L-1} m_3$, where $v$ is vocabulary size, and $m_2, m_3$ are the counts of binary and ternary rules.

Test loss vs. training samples (a) and rescaled samples (b), showing the universal scaling law collapse.

As shown in the figure above, when test loss is plotted against the number of training samples rescaled by this formula, the learning curves for CNNs, INNs, and Transformers collapse onto a single trajectory. This confirms that the derived scaling law is a fundamental property of how these architectures learn hierarchical structures. While the custom INN is the most sample-efficient, all architectures follow the same underlying statistical logic.

Conclusion and Future Directions

This work provides a unifying framework for understanding how deep networks exploit local statistics to build hierarchical representations. While currently limited to uniform-depth grammars, future research aims to extend these findings to recursive syntax and more complex structures, further bridging the gap between synthetic models and the complexities of natural language.

Summary updated

BibTeX
@inproceedings{parley2026deep,
  author = {Jack T. Parley and Francesco Cagnetta and Matthieu Wyart},
  title = {{Deep networks learn to parse uniform-depth context-free languages from local statistics}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=mJgkPAFdiK},
}
Figure