Context-free Recognition with Transformers
Selim Jerad, Anej Svete, Sophie Hao, Ryan Cotterell, William Merrill
摘要
Transformers excel empirically on tasks that process well-formed inputs according to some grammar, such as natural language and code. However, it remains unclear how they can process grammatical syntax. In fact, under standard complexity conjectures, standard transformers cannot recognize context-free languages (CFLs), a canonical formalism to describe syntax, or even regular languages, a subclass of CFLs. Past work has shown that looping layers (w.r.t. input length ) allow transformers to recognize regular languages, but the question of context-free recognition with looped transformers remained open. In this work, we show that looped transformers with looping layers and padding symbols can recognize all CFLs. However, training and inference with padding symbols is potentially impractical. Fortunately, we show that, for natural subclasses such as unambiguous CFLs, the recognition problem on transformers becomes more tractable, requiring padding. Empirically, looped and padded transformers perform better than fixed-depth transformers in recognizing CFLs. Overall, our results shed light on the intricacy of CFL recognition by transformers: while general recognition may require an intractable amount of padding, natural constraints such as unambiguity yield efficient recognition algorithms.
问问这篇 Paper
智能体会读完全文。
Lune 把这篇 Paper 索引到了每一个公式,引用它的顶会 Paper 也一样。你提问,回答直接引用原文。
引用它的顶会 Paper2
- Revisiting Padded Transformer Expressivity: Which Architectural Choices Matter and Which Don'tAnej Svete, William Merrill, Ryan Cotterell, Ashish SabharwalICML 2026 · 被引用 3 次
- How Transformers Represent Hierarchies: A Local-to-Global MechanismZhiling Zhou, Tianhao Wang, Zhuoran YangICML 2026
它引用的顶会 Paper18
- The Expressive Power of Transformers with Chain of ThoughtWilliam Merrill, Ashish SabharwalICLR 2024 · 被引用 243 次
- A Logic for Expressing Log-Precision TransformersWilliam Merrill, Ashish SabharwalNeurIPS 2023 · 被引用 87 次
- A Little Depth Goes a Long Way: The Expressive Power of Log-Depth TransformersWilliam Merrill, Ashish SabharwalNeurIPS 2025 · 被引用 62 次
- Logical Languages Accepted by Transformer Encoders with Hard AttentionPablo Barceló, Alexander Kozachinskiy, Anthony Widjaja Lin, Vladimir V. PodolskiiICLR 2024 · 被引用 36 次
- We're Afraid Language Models Aren't Modeling AmbiguityAlisa Liu, Zhaofeng Wu, Julian Michael, Alane Suhr 等EMNLP 2023 · 被引用 35 次
相关 Paper
- Stack Attention: Improving the Ability of Transformers to Model Hierarchical PatternsBrian DuSell, David ChiangICLR 2024 · 被引用 15 次
- Exact Expressive Power of Transformers with PaddingWilliam Merrill, Ashish SabharwalNeurIPS 2025 · 被引用 21 次
- Unraveling Syntax: Language Modeling and the Substructure of GrammarsLaura Ying Schulz, Daniel Mitropolsky, Tomaso A PoggioICML 2026 · 被引用 5 次
- On the Ability and Limitations of Transformers to Recognize Formal LanguagesSatwik Bhattamishra, Kabir Ahuja, Navin GoyalEMNLP 2020 · 被引用 7 次
- Learning Bounded Context-Free-Grammar via LSTM and the Transformer: Difference and the ExplanationsHui Shi, Sicun Gao, Yuandong Tian, Xinyun Chen 等AAAI 2022 · 被引用 24 次
