Abstract
Masaru Tomita introduces an "extended LR" parsing algorithm designed specifically for the "Goldilocks" complexity of natural languages—harder than programming languages but easier than general context-free grammars. By utilizing a graph-structured stack (GSS) and a shared-packed forest representation, the algorithm achieves speeds 5 to 10 times faster than the then-standard Earley’s algorithm while handling the inherent ambiguities of human speech.
Introduction: The Complexity of Natural Language
In the mid-1980s, parsing algorithms fell into two camps. On one side were LR parsers, used for programming languages; they were incredibly fast and deterministic but couldn't handle the ambiguity found in natural language (NL). On the other side were general algorithms like Earley’s or CYK, which could handle any context-free grammar but were often too slow for practical use because they didn't take advantage of the "mostly deterministic" structure of many languages.
Tomita recognized that natural language grammars are "close" to LR grammars. He sought a middle ground: an algorithm that maintains the efficiency of LR parsing for the easy parts of a sentence but can gracefully handle non-deterministic "splits" when ambiguity arises.
Methods: The Evolution of the LR Stack
The paper builds the algorithm through a series of refinements to the standard LR stack. A standard LR parser uses a single stack and a precomputed table to decide whether to "shift" a word or "reduce" a rule. However, natural language grammars often result in tables with multiple possible actions for a single state (conflicts), as seen in the grammar and table below.
To address these conflicts, Tomita evolved the stack structure:
- Stack List: When a conflict occurs, the parser clones itself, maintaining a list of independent stacks. This breadth-first approach leads to exponential growth.
- Tree-Structured Stack: Stacks with the same "top" state are merged to save work. If they need to be popped, they split back apart.
- Graph-Structured Stack (GSS): The final innovation merges stacks not just at the top, but also at the bottom. This allows the parser to process a segment of a sentence once and share that result across multiple potential parsing paths.
Representing Ambiguity: Shared-Packed Forests
To store the results efficiently, Tomita uses a Shared-Packed Forest:
- Sub-tree Sharing: If two different parses share the same sub-phrase (e.g., a noun phrase), that sub-tree is stored only once.
- Local Ambiguity Packing: If a fragment of a sentence can be reduced to the same non-terminal symbol in multiple ways, those nodes are "packed" into a single node for the higher-level parser to treat as one unit.
Key Insights and Results
The core "aha moment" is that natural language isn't purely chaotic; it is "close" to being deterministic. By using LR tables, we can precompute much of the grammar's logic, leaving only the ambiguities to be handled at runtime. Tomita also identifies a defect in Earley’s forest representation, demonstrating that for certain grammars (like $S \to SS$), Earley’s method can represent invalid trees.
Experimental results showed the algorithm is 5 to 10 times faster than Earley’s algorithm for natural language processing tasks. While the primitive version of this algorithm was exponential, the GSS version runs in polynomial time and produces all possible parses in a highly compressed format, preventing the "exponential explosion" of trees in long, ambiguous sentences.
Limitations and Future Work
Tomita acknowledges that if a grammar is "densely" ambiguous, the algorithm could theoretically take more than $O(n^3)$ time, though this is rare in real-world usage. Additionally, the algorithm cannot handle "cyclic" grammars (e.g., $A \to B$ and $B \to A$). Future extensions discussed in Tomita's dissertation include handling unknown words and interactive disambiguation techniques.
Summary updated