Disjoint Processing Mechanisms of Hierarchical and Linear Grammars in Large Language Models

Aruna Sankaranarayanan, Dylan Hadfield-Menell, Aaron Mueller

TL;DR

Large Language Models (LLMs) trained purely on web-scale text develop distinct, localizable internal mechanisms for processing hierarchical versus linear grammars, closely mirroring the functional specialization observed in the human brain. Crucially, this structural sensitivity is highly abstract and independent of semantic meaning, remaining active even when processing "Jabberwocky" sentences made entirely of nonsense words.

What Problem Does This Paper Address?

Human language is fundamentally hierarchical—we organize sentences using nested structures (like relative clauses) rather than flat, sequential chains of words. Neuroimaging studies show that the human brain has specialized, biologically coded regions (like Broca's area) that process these hierarchical structures while completely ignoring artificial, purely linear rules (such as "insert a negation word at exactly position 5").

However, modern LLMs are built on the Transformer architecture, which lacks any explicit human-like biological bias toward hierarchy. They are trained simply to predict the next token in a sequence. This paper addresses a fundamental question in mechanistic interpretability: Does exposure to large-scale natural language data alone force LLMs to develop specialized, disjoint internal circuits for hierarchical processing, or do they treat linear and hierarchical structures the same way?

Methods

The authors investigate this by setting up a series of metalinguistic grammaticality judgment tasks using an in-context learning framework (few-shot prompting). To look under the hood of the models, they employ two primary techniques:

  1. Attribution Patching: A computationally efficient, first-order Taylor approximation of activation patching. It allows the researchers to calculate the indirect effect of individual neurons (specifically the outputs of MLP and attention submodules across all layers) to identify which components are causally responsible for distinguishing grammatical from ungrammatical sentences.
  2. Causal Ablation Experiments: Once the top 1% of hierarchy-sensitive ($H$) and linearity-sensitive ($L$) neurons are identified, the authors systematically "knock them out" (replacing their activations with mean values) to observe the causal impact on the model's accuracy across different grammar types.

Datasets

The authors created a synthetic dataset inspired by human neuroimaging experiments (Musso et al., 2003), spanning 18 different grammars across three natural languages and one artificial variant:

  • Natural Languages: English (EN), Italian (IT), and Japanese (JP).
  • Grammar Types: For each language, they generated sentences following Hierarchical rules (e.g., Declarative, Subordinate clauses, Passive voice) and artificial Linear rules (e.g., fixed-position negation, word inversion, fixed-position Wh-words).
  • Jabberwocky Dataset (ZZ): To decouple structure from meaning, they created a nonsense dataset by applying a bijective mapping from English words to meaningless "nonce" words (e.g., converting "a woman reads a chapter" into "a wug ungos the snorfle"), while strictly preserving the underlying grammatical rules.

Key Insights and Ideas

  • Emergent Modularity: Functional specialization does not require a biological brain or hardcoded architectural constraints; it can emerge purely as an optimal solution for modeling natural language distributions.
  • Disjoint Internal Circuits: The neural components handling natural hierarchical syntax have remarkably low overlap with the components tasked with tracking artificial linear rules. The model effectively segregates these tasks.
  • Abstract Structural Sensitivity: The hierarchy-selective circuits are not merely memorizing familiar word combinations or relying on semantic context. Because these same circuits are causally required to solve the task for nonsense "Jabberwocky" sentences, the model's understanding of hierarchy is shown to be deeply abstract.

Key Results

  • Behavioral Superiority on Hierarchy: Across almost all tested models (including Llama 2, Llama 3.1, Qwen-2, and Mistral), the models were significantly more accurate at identifying grammatical sentences under hierarchical rules than linear ones.
Figure 1: Few-shot accuracy on the grammaticality judgment task on hierarchical and linear inputs. On average, all models are better at the grammaticality judgment task on hierarchical inputs as compared to linear inputs. On hierarchical grammars, models are best at processing English inputs followed by Italian and Japanese. Model-wise accuracy on this task is shown in Figure 5 in App. B.1. Grammar-wise accuracy is shown in Table 5 in App. B.1.
  • Low Mechanistic Overlap: Attribution patching revealed that the top 1% of neurons active for hierarchical tasks highly overlapped with other hierarchical tasks, but showed minimal overlap with linear tasks.
Figure 2: Mean pairwise overlap percentage of the top 1% of neurons from hierarchical (H) or linear (L) gram- mars. We show means across models (error bars are standard errors); see Figure 7a in App. B.2 for model- wise results. Overlaps are significantly (p < 0.001, Table 8) different between hierarchical-hierarchical pairs and linear-linear pairs, and between hierarchical- hierarchical pairs and hierarchical-linear pairs.
  • Causal Verification via Ablation: Knocking out the hierarchy-sensitive ($H$) neurons caused a massive drop in accuracy on hierarchical grammars, while leaving performance on linear grammars relatively unscathed. Conversely, ablating linear ($L$) neurons selectively degraded linear grammar performance.
Figure 3: Mean relative change in accuracy across mod- els (error bars are standard errors) after ablating the top 1% of neurons from hierarchical (H) or linear (L) gram- mars. We compare to a random ablation baseline. For model-wise ablations, see Figure 12a in App. B.3.
  • Generalization to Jabberwocky: When tested on nonsense words, the performance gap narrowed but persisted. Crucially, ablating the English hierarchical neurons caused a selective performance drop on Jabberwocky hierarchical sentences, proving these circuits are truly tracking abstract structure.
Figure 4: Results on Jabberwocky grammars. We show grammaticality judgment task performance (a), mean neuron overlap percentages between Jabberwocky hierarchical and linear grammars (b), neuron overlaps between English and Jabberwocky grammars (c), and the mean relative changes in accuracy as measured on Jabberwocky grammars after ablating top 1% of neurons corresponding to English grammars (d). See App. B.4 for model-wise results.

Limitations and Future Work

  • Polysemanticity: The authors analyze individual neurons and submodule outputs, which are notoriously polysemantic (i.e., a single neuron might perform multiple unrelated tasks in different contexts).
  • Unordered Circuits: The study identifies which neurons are important but does not map out the exact step-by-step sequential graph (the circuit topology) of how information flows between them.
  • Downstream Impact: The experiments are restricted to few-shot grammaticality judgments. Future work is needed to determine if these exact same hierarchy-sensitive subnetworks are vital for broader downstream NLP tasks like summarization, translation, or reasoning.

Summary updated

Abstract

All natural languages are structured hierarchically. In humans, this structural restriction is neurologically coded: when two grammars are presented with identical vocabularies, brain areas responsible for language processing are only sensitive to hierarchical grammars. Using large language models (LLMs), we investigate whether such functionally distinct hierarchical processing regions can arise solely from exposure to large-scale language distributions. We generate inputs using English, Italian, Japanese, or nonce words, varying the underlying grammars to conform to either hierarchical or linear/positional rules. Using these grammars, we first observe that language models show distinct behaviors on hierarchical versus linearly structured inputs. Then, we find that the components responsible for processing hierarchical grammars are distinct from those that process linear grammars; we causally verify this in ablation experiments. Finally, we observe that hierarchy-selective components are also active on nonce grammars; this suggests that hierarchy sensitivity is not tied to meaning, nor in-distribution inputs.
BibTeX
@inproceedings{sankaranarayanan2024disjoint,
  author = {Aruna Sankaranarayanan and Dylan Hadfield-Menell and Aaron Mueller},
  title = {{Disjoint Processing Mechanisms of Hierarchical and Linear Grammars in Large Language Models}},
  booktitle = {LLMs and Cognition @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=qg2TJ3eKOr},
}
Figure