[Paper Review] Formal Language Theory Meets Modern NLP
This paper bridges formal language theory and modern NLP by analyzing neural network architectures—particularly transformers—through the lens of automata theory and the Chomsky hierarchy. It establishes that saturated transformers can recognize regular and context-free languages, while bounded-attention variants cannot, and introduces random feature attention as a scalable alternative to standard self-attention with theoretical guarantees.
NLP is deeply intertwined with the formal study of language, both conceptually and historically. Arguably, this connection goes all the way back to Chomsky's Syntactic Structures in 1957. It also still holds true today, with a strand of recent works building formal analysis of modern neural networks methods in terms of formal languages. In this document, I aim to explain background about formal languages as they relate to this recent work. I will by necessity ignore large parts of the rich history of this field, instead focusing on concepts connecting to modern deep learning-based NLP.
Motivation & Objective
- To connect classical formal language theory with contemporary deep learning-based NLP architectures.
- To investigate the representational capacity of neural networks such as transformers using automata-theoretic frameworks.
- To analyze the limitations of attention mechanisms in recognizing complex linguistic patterns like Dyck languages or parity.
- To propose scalable alternatives to self-attention, such as random feature attention, with theoretical justification.
- To guide future research on interpretability, inductive biases, and robustness in NLP models using formal language theory.
Proposed method
- Uses finite-state automata and weighted finite-state automata (WFAs) to model regular and context-sensitive language recognition.
- Applies Hankel matrix theory to analyze learning and identifiability of WFAs from string samples.
- Models saturated transformers as finite automata with bounded memory, showing they can recognize context-free languages.
- Analyzes attention mechanisms via circuit complexity, proving that hard-attention transformers cannot recognize parity or Dyck languages.
- Employs random feature approximation (Rahimi & Recht, 2008) to derive random feature attention (RFA), reducing attention complexity from O(MN) to O(M+N).
- Uses theoretical analysis of positional encodings to show their necessity for detecting relative position dependencies in transformers.
Experimental results
Research questions
- RQ1What is the formal language capacity of transformer networks, particularly in terms of recognizing context-free and non-context-free languages?
- RQ2How do attention mechanisms with bounded receptive fields constrain the linguistic patterns a model can learn?
- RQ3Can random feature attention preserve the representational power of self-attention while enabling linear-time inference?
- RQ4To what extent can formal language theory help distinguish between robust linguistic generalization and dataset artifacts in NLP models?
- RQ5Can we develop a non-trivial complexity theory for linguistic patterns that accounts for bounded-length strings, beyond the Chomsky hierarchy?
Key findings
- Saturated transformers can recognize all regular and some context-free languages, including Dyck languages, due to their unbounded memory and symmetric attention patterns.
- Hard-attention transformers with bounded receptive fields cannot recognize the parity language or Dyck languages, as shown via circuit complexity arguments.
- Random feature attention (RFA) approximates the self-attention mechanism with a theoretical guarantee that its inner product approximates an RBF kernel, enabling O(M+N) computation time.
- Positional encodings are essential for transformers to detect relative position dependencies; without them, even simple regular languages like a*b cannot be recognized.
- Weighted finite-state automata (WFAs) can be learned from string samples using Hankel matrix methods, providing a formal basis for learning latent linguistic structures.
- Theoretical analysis reveals that standard transformers have strong inductive biases toward certain language classes, suggesting formal language theory can inform architectural design and interpretability.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.