Title: Learning Context-free Languages with Nondeterministic Stack RNNs
Abstract
Traditional stack-augmented Recurrent Neural Networks (RNNs) are typically deterministic, limiting their ability to model inherently ambiguous context-free languages (CFLs). This paper introduces the Nondeterministic Stack RNN (NS-RNN), which utilizes a differentiable stack data structure capable of tracking an exponential number of possible stack states simultaneously. By reformulating classic automata theory into differentiable tensor operations, the NS-RNN achieves superior performance on complex CFL tasks and demonstrates improved training stability compared to deterministic baselines.
Introduction
Human language is characterized by hierarchical structures and frequent ambiguity. Processing such language requires the ability to maintain multiple syntactic interpretations until disambiguating information is encountered. In computer science, this is the domain of Pushdown Automata (PDAs) and Context-Free Languages (CFLs). While previous "stack-augmented" RNNs provided neural networks with stack-based memory, they were largely deterministic, representing only a single stack state at any given time. This determinism limits expressivity for "inherently nondeterministic" languages and often leads to training difficulties as models get stuck in local minima. The NS-RNN addresses these challenges by implementing a nondeterministic stack.
Methods
The core innovation of the NS-RNN is the replacement of a standard deterministic stack with a nondeterministic one based on Bernard Lang’s 1974 algorithm.
The Stack as a Graph: Instead of a linear list, the stack is represented as a Weighted Finite Automaton (WFA). This allows the model to tractably encode an exponential number of possible stack configurations within a single data structure.
Differentiable Operations: To integrate this with deep learning, the authors reformulated Lang’s logic into differentiable tensor operations. Using an efficient einsum implementation and the log semiring, the model performs three primary operations at each step: Push, Pop, and Replace.
The Controller: An LSTM acts as the central controller, emitting weights for the Push, Pop, and Replace operations at each time step. The overall algorithm maintains a complexity of $O(n^3)$ time and $O(n^2)$ space relative to the input length $n$.
Experimental Setup
The NS-RNN was evaluated on several synthetic formal language tasks generated via Probabilistic Context-Free Grammars (PCFGs):
- Marked Reversal ($w\#w^R$): A deterministic task with a clear middle marker.
- Unmarked Reversal ($ww^R$): A nondeterministic task requiring the model to identify the string's center without a marker.
- Padded Reversal: A variant of unmarked reversal with long stretches of repeated symbols to test long-range dependencies.
- Dyck Language: The classic balanced parentheses problem.
- Hardest CFL: A highly complex language (Greibach, 1973) designed such that parsing it implies the ability to parse any CFL.
Results and Analysis
The NS-RNN demonstrated significant improvements in both accuracy and reliability. On the "Hardest CFL" and Unmarked Reversal tasks, it achieved substantially lower cross-entropy than standard LSTMs or deterministic stack-RNNs.
A key insight is that nondeterminism acts as a regularizer. Even on deterministic tasks like Marked Reversal, the NS-RNN converged faster and more consistently. By considering all possible paths during training, the model receives a richer gradient signal. Furthermore, the model employs "late marginalization," delaying decisions about the stack's top until a prediction is required, which is crucial for handling ambiguity.
Discussion and Limitations
Despite its strengths, the NS-RNN faces challenges with long-distance signals, as seen in the Padded Reversal task where the LSTM controller struggled to maintain logic over long sequences of noise. Additionally, while the model performs nearly perfectly on training lengths (up to 80 symbols), its performance can degrade on longer, unseen strings (up to 100), suggesting a degree of overfitting to length distributions. Finally, the $O(n^3)$ time complexity remains a significant scaling bottleneck for very long sequences in real-world NLP applications.
Conclusion
The NS-RNN successfully bridges formal language theory and modern deep learning. By "neuralizing" classic automata concepts, the authors have created a model with the structural power to handle complex context-free languages that were previously beyond the reach of neural architectures.
Summary updated