PICARD: Parsing Incrementally for Constrained Auto-Regressive Decoding from Language Models

TL;DR

PICARD constrains autoregressive decoding via incremental parsing, significantly improving SQL accuracy with 75.5% exact match on Spider.

cs.CL πŸ”΄ Advanced 2021-09-11 42 views
Torsten Scholak Nathan Schucher Dzmitry Bahdanau
NLP semantic parsing code generation constrained decoding deep learning

Key Findings

Methodology

The proposed PICARD method employs incremental parsing to enforce validity constraints during each decoding step. It integrates four modes: lexing, parsing without guards, parsing with guards, and final validation. Using monadic combinators, it performs fast incremental validation of partial SQL outputs, rejecting invalid tokens early. Compatible with any pre-trained autoregressive model, PICARD filters candidate tokens based on schema and syntax rules, reducing invalid SQL generation. This approach allows seamless integration at inference time without architectural modifications, leading to more reliable code generation.

Key Results

  • On the Spider dataset, T5-3B with PICARD achieved 75.5% exact match accuracy, surpassing the baseline's 70.0%. Execution accuracy reached 79.3%, and invalid SQL predictions dropped from 12% to 2%. These improvements outperformed prior state-of-the-art methods such as LGESQL + ELECTRA. Similar gains were observed on CoSQL, with question and interaction match accuracy reaching new bests.
  • Different decoding strategies (greedy, beam search) combined with PICARD showed consistent performance gains, especially at larger beam sizes. Incremental validation during decoding outperformed final-only validation, confirming the effectiveness of stepwise constraints.
  • Ablation studies indicated lexing alone provided modest improvements, while parsing with guards delivered the strongest results, validating the incremental parsing approach.

Significance

This work addresses a critical challenge in deploying large pre-trained language models for formal language generation, such as SQL, by providing a general, architecture-agnostic decoding constraint mechanism. It reduces invalid outputs, enhances accuracy, and maintains model flexibility, thus bridging the gap between powerful language models and rigorous formal language applications. The method's simplicity and effectiveness open new avenues for constrained generation tasks across NLP and code synthesis domains, with potential impacts on enterprise data interfaces, conversational AI, and automated programming.

Technical Contribution

PICARD introduces a novel incremental parsing-based decoding framework that enforces syntactic and semantic constraints during autoregressive generation. It leverages monadic parser combinators for fast, stepwise validation, enabling real-time filtering of candidate tokens. The approach is model-agnostic, does not require special vocabularies or architecture modifications, and integrates seamlessly with existing beam search algorithms. It provides theoretical guarantees of validity and demonstrates empirical superiority over existing filtering or constrained decoding methods.

Novelty

This is the first application of incremental parsing techniques to constrain large-scale pre-trained language models during decoding, combining syntax-aware validation with efficient, model-agnostic filtering. Unlike prior approaches relying on custom vocabularies or architecture changes, PICARD offers a universal, plug-and-play solution that significantly improves output validity and accuracy in formal language generation tasks.

Limitations

  • The incremental parsing process introduces additional computational overhead, especially for complex queries, which may impact decoding speed in real-time applications.
  • The current implementation mainly targets SQL-like languages; extending to more complex or less structured languages requires further development.
  • Early-stage prediction errors may propagate, affecting the final output if not properly mitigated.

Future Work

Future directions include optimizing parsing efficiency, integrating learned guards for semantic validation, and extending the framework to other formal languages such as logical expressions or programming languages. Additionally, combining PICARD with reinforcement learning or active learning strategies could further improve robustness and generalization in complex scenarios.

AI Executive Summary

In recent years, large pre-trained language models have revolutionized natural language processing, enabling remarkable advances in tasks like translation, summarization, and question answering. However, their unconstrained output spaces pose significant challenges when generating formal languages such as SQL, where syntactic and semantic correctness are critical. Existing solutions often rely on custom vocabularies or post-hoc filtering, which either limit model flexibility or incur high computational costs. This paper introduces PICARD, a novel decoding framework that employs incremental parsing to enforce validity constraints during autoregressive generation.

The core idea behind PICARD is to integrate a fast, monadic parser-based validation mechanism directly into the decoding process. At each step, it filters candidate tokens based on schema and syntactic rules, rejecting invalid options early. This incremental approach ensures that only valid partial outputs are extended, drastically reducing the generation of invalid SQL queries. The framework supports multiple modes, including lexing, parsing without guards, and parsing with semantic guards, providing a flexible trade-off between speed and rigor.

Empirical results on the Spider and CoSQL datasets demonstrate that PICARD significantly boosts model performance. For instance, a T5-3B model with PICARD achieves 75.5% exact match accuracy on Spider, surpassing previous state-of-the-art methods. It also reduces invalid SQL predictions from 12% to 2%, highlighting its effectiveness in enforcing correctness. The method's compatibility with existing models and decoding algorithms makes it a practical and scalable solution for real-world applications.

Overall, PICARD offers a powerful, architecture-agnostic approach to constrained decoding, bridging the gap between the flexibility of large language models and the strict requirements of formal language generation. Its success paves the way for broader adoption of semantic parsing and code synthesis in enterprise and research settings. Future work aims to optimize parsing efficiency, extend applicability to other languages, and incorporate semantic guards for more complex reasoning tasks, promising a new horizon in controlled natural language generation.

Deep Dive

Abstract

Large pre-trained language models for textual data have an unconstrained output space; at each decoding step, they can produce any of 10,000s of sub-word tokens. When fine-tuned to target constrained formal languages like SQL, these models often generate invalid code, rendering it unusable. We propose PICARD (code and trained models available at https://github.com/ElementAI/picard), a method for constraining auto-regressive decoders of language models through incremental parsing. PICARD helps to find valid output sequences by rejecting inadmissible tokens at each decoding step. On the challenging Spider and CoSQL text-to-SQL translation tasks, we show that PICARD transforms fine-tuned T5 models with passable performance into state-of-the-art solutions.

cs.CL cs.PL