Samuel J. Gershman
Author directory2026
A circuit for predicting hierarchical structure in-context in Large Language Models
Tankred Saanum | Can Demircan | Samuel J. Gershman | Eric Schulz
Proceedings of the 9th BlackboxNLP Workshop: Analyzing and Interpreting Neural Networks for NLP
Tankred Saanum | Can Demircan | Samuel J. Gershman | Eric Schulz
Proceedings of the 9th BlackboxNLP Workshop: Analyzing and Interpreting Neural Networks for NLP
Large Language Models (LLMs) rely on induction heads for in-context learning, yet how they manage complex hierarchical structures and contextual dependencies remains unclear. By evaluating a range of LLMs on synthetic tasks and natural language analogues, we identify adaptive induction heads in later layers that learn to attend to successor tokens based on hierarchical cues rather than simple bi-gram statistics. These heads are supported by a circuit of context matching heads that uncover latent transition relationships by routing information from distant past tokens to the current query. Controlled ablation experiments across model families confirm that this circuit is essential for accurate hierarchical predictions in context. Finally, we show that this mechanism is used in natural language to resolve ambiguities where single tokens have multiple potential successors. Our findings provide a mechanistic account of how LLMs learn to predict higher-order repetitive patterns in-context.