Prefix Parsing is Just Parsing
Clemente Pasti, Andreas Opedal, Timothy J. O'Donnell, Ryan Cotterell, Tim Vieira

TL;DR
This paper introduces a novel, efficient method for prefix parsing by transforming grammars, enabling the use of standard parsing algorithms for prefix and weighted prefix parsing tasks.
Contribution
The authors present the prefix grammar transformation, allowing prefix parsing to be performed with ordinary parsers, and develop a strategy for efficiently computing prefix weights.
Findings
The transformed grammar is only a small factor larger than the original.
Any optimized parser can be used directly on the transformed grammar.
The framework enables efficient prediction of next tokens in language modeling.
Abstract
Prefix parsing asks whether an input prefix can be extended to a complete string generated by a given grammar. In the weighted setting, it also provides prefix probabilities, which are central to context-free language modeling, psycholinguistic analysis, and syntactically constrained generation from large language models. We introduce the prefix grammar transformation, an efficient reduction of prefix parsing to ordinary parsing. Given a grammar, our method constructs another grammar that generates exactly the prefixes of its original strings. Prefix parsing is then solved by applying any ordinary parsing algorithm on the transformed grammar without modification. The reduction is both elegant and practical: the transformed grammar is only a small factor larger than the input, and any optimized implementation can be used directly, eliminating the need for bespoke prefix-parsing…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
