Characterizing Pattern Matching and Its Limits on Compositional Task Structures

Hoyeon Chang, Jinho Park, Hanseul Cho, Sohee Yang, Miyoung Ko, Hyeonbin Hwang, Seungpil Won, Dohaeng Lee, Youbin Ahn, Minjoon Seo

Large Language Models (LLMs) are frequently criticized as being "just pattern matchers," a term often used as a vague pejorative rather than a precise technical description. This lack of formalization makes it difficult to predict when an LLM will successfully generalize to a new task versus when it will fail spectacularly on out-of-distribution (OOD) data.

This paper addresses the ambiguity of LLM generalization in compositional tasks—tasks where multiple steps must be combined to reach an answer. The authors provide a formal, data-centric definition of pattern matching, establish the mathematical limits of what it can achieve, and explain why models fail on certain task structures regardless of scale or training data.

Formalizing Pattern Matching

To move beyond vague definitions, the researchers propose a new framework based on Functional Equivalence.

Under this definition, two input fragments are considered "functionally equivalent" if they consistently produce the same result when placed in the same context. By observing these equivalences, the model can build a dataset representation known as a Substitution Graph. In this graph, edges connect inputs that differ only by functionally equivalent parts.

Functional Equivalence and Substitution Graphs

This framework introduces the concept of $k$-coverage, which defines the "boundary" of pattern matching. If a test case can be reached from a training case through a chain of safe substitutions—supported by at least $k$ witnessing examples in the training data—it falls within the model's reach via pattern matching.

To validate this theory, the authors employed mechanistic interpretability tools, including Causal Tracing, Logit Lens, and the Intra-Inter Cosine Gap (IICG), to measure how tightly the model clusters representations of equivalent inputs in its latent space.

Isolating Compositional Structures

To precisely test these mechanisms, the authors moved away from messy natural language and utilized controlled synthetic tasks that isolate specific reasoning structures.

Controlled Synthetic Task Structures

These structures include:

  • 2-HOP / 3-HOP: Linear chains of functions (e.g., $f_2(f_1(x_1, x_2), x_3)$).
  • PARALLEL 2-HOP: Two independent functions whose results are subsequently combined.
  • NON-TREE: A complex structure where a single variable influences the final output through multiple computational paths.

These tasks were evaluated on GPT-2 models (ranging from 68M to 1.5B parameters) and Mamba architectures to ensure the findings were fundamental rather than architecture-specific.

Key Findings: The Limits of Pattern Matching

The application of this formal framework yielded several predictive and quantitative insights into LLM behavior:

1. Generalization is a "Strength in Numbers" Game A model's success on a specific instance is highly predictable based on the number of "witnessing contexts" ($k$) it saw during training. The authors proved and empirically verified a tight sample complexity bound: for a 2-hop task, the data required scales as $n^{2.5 - 0.5/k}$ (where $n$ is the token set size). If the model only saw a few examples of two fragments being equivalent, it struggles to generalize.

2. The Structural Barrier of Path Ambiguity The most striking finding is that pattern matching fundamentally fails on NON-TREE structures. When a variable affects the output through multiple computational paths, the model fails to form a unified intermediate representation. Instead, it creates context-dependent representations that do not generalize to new combinations. In these path-ambiguous tasks, standard interpretability tools like the Logit Lens fail because the model never forms a clear, human-readable intermediate state.

3. Scaling Doesn't Fix Structure Increasing model size by 20x (from GPT-2 Small to XL) improved overall data efficiency but did not resolve the failure on path-ambiguous tasks. This strongly suggests that the limitation is a structural flaw in how these models process information, not simply a matter of insufficient parameters.

4. Chain-of-Thought is a "Flattener" Chain-of-Thought (CoT) supervision makes models more data-efficient by effectively "flattening" a multi-hop task into a series of single-hop tasks. However, while it reduces data requirements, even CoT does not fully solve the underlying path ambiguity problem.

Limitations and Future Directions

While this study provides a rigorous boundary for pattern matching, it relies on fixed-length synthetic sequences. Real-world language contains semantic "priors" that might alter how these mechanisms manifest. Furthermore, the study focuses on decoder-only models, leaving the behavior of encoder-decoder architectures as an open question.

Ultimately, the authors suggest that to move beyond the "coverage boundary" of pattern matching, models will need entirely different mechanisms. Future breakthroughs may require architectures capable of property-based generalization (understanding global rules like commutativity) or shared-operator generalization, moving beyond mere functional equivalence.

Summary updated

BibTeX
@inproceedings{chang2026characterizing,
  author = {Hoyeon Chang and Jinho Park and Hanseul Cho and Sohee Yang and Miyoung Ko and Hyeonbin Hwang and Seungpil Won and Dohaeng Lee and Youbin Ahn and Minjoon Seo},
  title = {{Characterizing Pattern Matching and Its Limits on Compositional Task Structures}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=VCjlm003WL},
}
Figure