Transformers are uninterpretable with myopic methods: a case study with bounded Dyck grammars

Kaiyue Wen, Yuchen Li, Bingbin Liu, Andrej Risteski

Abstract

Mechanistic interpretability often relies on the assumption that complex Transformer behaviors can be decomposed into human-understandable "circuits" or specific attention patterns. This paper challenges that assumption by demonstrating that Transformers can solve hierarchical tasks, such as parsing Dyck grammars, using internal configurations that are mathematically sound but visually "messy" or even randomized. By introducing the "balance condition," the authors show that a model's global success depends on the collective cancellation of vectors across layers rather than the presence of intuitive, stack-like attention heads. These findings suggest that "myopic" interpretability—methods focusing on individual components in isolation—may lead to misleading conclusions about how models actually function.

Introduction: The Myopic Interpretability Trap

As Transformer models become the standard for artificial intelligence, researchers have turned to mechanistic interpretability to decode their inner workings. A common strategy involves visualizing attention maps or inspecting weight matrices to identify specific functional units—for example, a head that tracks the depth of nested parentheses. This paper argues that this "myopic" approach is fundamentally limited.

Using Dyck grammars (the language of balanced parentheses) as a controlled sandbox, the authors investigate whether high-performing models necessarily adopt interpretable internal structures. Because Dyck grammars have a clear, canonical algorithmic solution involving a stack, they provide a perfect test case: if a Transformer solves the task, does it have to use a "stack-like" mechanism that a human can recognize?

The Balance Condition and Global Coordination

The researchers propose that instead of relying on specific, structured attention patterns, Transformers solve hierarchical tasks by satisfying a theoretical "balance condition." In a 2-layer Transformer, the model does not require a specific attention head to act as a stack. Instead, it simply needs the contributions from matching brackets to mathematically cancel each other out within the residual stream.

This global coordination allows for a "messy" optimum. The authors prove, using a Lottery Ticket Hypothesis-style approximation, that any Transformer can be approximated by pruning a larger, random network. This implies that individual weight matrices might appear as random noise while still contributing to a perfect global solution. In this framework, interpretability is not a prerequisite for faithfulness; a model can be 99% accurate while its internal components remain indistinguishable from uniform distributions.

Methodology

The study combines rigorous mathematical proofs with empirical experiments on synthetic Dyck languages ($Dyck_{k,D}$), specifically focusing on $Dyck_{2,4}$ (two types of brackets with a maximum nesting depth of 4).

  1. Synthetic Training: 2-layer and 3-layer Transformers were trained on sequences of length less than 28 using varying architectures and initialization seeds.
  2. Contrastive Regularization: To test the importance of the balance condition, the authors introduced a new loss function that forces the model to satisfy this condition during training.
  3. Generalization Testing: Models were evaluated on both in-distribution data and out-of-distribution "length generalization" tests, involving sequences of length 400–500.

Key Results

High Accuracy, Low Interpretability

Models consistently achieved over 97% accuracy on the Dyck task, yet their internal attention patterns varied wildly across different random seeds. Many models solved the task perfectly without ever developing the "interpretable" stack-like patterns suggested by prior literature. The variation in attention patterns between successful models was nearly as high as the variation between completely random matrices, suggesting that the optimization process (SGD) can land on many different, non-intuitive internal configurations.

Solving Length Generalization

Standard training often fails when sequence lengths increase beyond the training distribution. However, by applying contrastive regularization to enforce the balance condition, the authors significantly improved accuracy on long sequences. This suggests that the "balance" of vectors across layers is the functional "secret sauce" for generalization, rather than the specific shape of attention maps.

Discussion and Limitations

The primary takeaway is that researchers cannot "reverse engineer" a Transformer by looking at one part at a time. The set of optimal parameters is qualitatively rich, and the global behavior of the network is often hidden in the collective balance of its parts.

While this study uses a toy synthetic task, it highlights a critical gap in current interpretability research. Dyck grammars capture the core of hierarchical processing, but natural language is significantly more complex. Future work must move away from myopic inspections and toward holistic methods that analyze how information is preserved or cancelled across the entire network circuit. Understanding the inductive biases that nudge models toward or away from interpretable solutions remains a vital frontier for making AI truly transparent.

Summary updated

BibTeX
@inproceedings{wen2023transformers,
  author = {Kaiyue Wen and Yuchen Li and Bingbin Liu and Andrej Risteski},
  title = {{Transformers are uninterpretable with myopic methods: a case study with bounded Dyck grammars}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=OitmaxSAUu},
}
Figure