TL;DR
This paper introduces NLX, a novel approach that combines the natural language understanding capabilities of Pre-trained Language Models (PTMs) with the precision of Component-Based Synthesis (CBS) to generate programs from natural language descriptions and examples. This hybrid method significantly improves program synthesis accuracy by leveraging PTM-generated components to guide the CBS search, demonstrating strong performance in domains like regular expressions and CSS selectors.
What Problem Does This Paper Address?
Synthesizing programs from natural language (NL) descriptions is a long-standing challenge. While PTMs like GPT-3 excel at understanding ambiguous NL, they often struggle to produce syntactically correct and precise code. Conversely, traditional program synthesis techniques can generate accurate code from precise specifications (like examples) but falter with the inherent ambiguity of NL. This paper addresses the gap by proposing a "multi-modal" approach that combines the strengths of both: using PTMs to interpret NL and generate candidate program components, and then employing CBS to precisely construct the final program based on user-provided examples. This is particularly relevant for tasks where users might describe what they want in NL but also provide concrete examples to clarify their intent.
Methods
The core of the proposed approach, named NLX, is a domain-agnostic algorithm that integrates PTMs with CBS. The process involves three key phases:
- Initialization: PTMs are used to generate a set of candidate programs from the NL description. The NLX algorithm then extracts "maximal components" from these candidates. These are the largest, most frequent sub-expressions that the PTM identified, which are crucial for guiding the CBS search and avoiding the complexity of starting from atomic components.
- Expansion: A beam search strategy is employed to iteratively construct larger programs by combining existing components. This search is biased by the operator distribution observed in the PTM candidates, ensuring that the synthesis process favors structures similar to what the PTM suggests.
- Ranking: Synthesized programs are ranked based on their similarity to the PTM candidates, using a combination of Euclidean distance of operator vectors and Levenshtein distance for string similarity. This helps in selecting the most plausible program among those that satisfy the given examples.
The novelty lies in how PTM outputs are used to guide all stages of the CBS process, from component initialization to search expansion and final ranking.
Datasets
- Regular Expressions:
- A corpus of 4855 question-answer pairs from the [Cascio et al. 2016] dataset was used for training the PTM prompt selection.
- Test tasks consisted of 115 questions from the same dataset.
- A separate set of tasks was curated from StackOverflow posts related to regular expressions, resulting in 25 tasks with an average of 4.3 positive and 1.4 negative examples per task.
- CSS Selectors:
- A dataset of 19 real-world scenarios collected from StackOverflow questions tagged with "css" and "css-selectors".
- For training the PTM, 3 tasks were used for few-shot examples, and the remaining 16 were used for testing.
Key Insights and Ideas
- PTMs as Component Generators: PTMs, while not perfect at generating complete, precise code, are excellent at identifying relevant program components from NL. This insight is central to the NLX approach.
- Maximal Components for Initialization: Instead of starting CBS with basic atomic components, using "maximal components" (frequently occurring, large sub-expressions identified by PTMs) significantly prunes the search space and accelerates synthesis.
- Operator Distribution as a Guide: The frequency distribution of operators in PTM-generated candidates provides a strong signal for guiding the CBS expansion phase, making the search more efficient and targeted.
- Domain Agnosticism is Achievable: The core NLX framework is designed to be domain-agnostic, demonstrating its applicability across very different programming domains like regular expressions and CSS selectors.
Key Results
- Regular Expressions: NLX-REG achieved 80% accuracy across both DeepRegex and StackOverflow datasets, outperforming baselines like GPT-3 (21% average) and BFS (41% average). It also performed comparably to REGEL (a specialized regex synthesizer), achieving 90% on DeepRegex and significantly higher (70% vs 25%) on StackOverflow.
- CSS Selectors: NLX-CSS achieved 75% accuracy on its test set, outperforming BFS (56%) and GPT-3 (20%).
- Efficiency: NLX-REG required an average of 1.5 rounds of additional examples for successful synthesis, compared to 2.3 rounds for REGEL.
- Prompt Engineering: The study highlighted the significant impact of prompt quality on PTM performance, showing that intelligent selection of question-answer pairs for few-shot learning can substantially improve recall.
Limitations and Future Work
- PTM Dependence: The effectiveness of NLX is inherently tied to the quality of the PTM's output. If the PTM fails to generate relevant components, the synthesis process may struggle.
- Compositionality Assumption: The theoretical completeness guarantee relies on a compositionality assumption for the DSL, which may not hold for all languages.
- Pandas Domain Challenges: Applying NLX to domains like Python's Pandas library presents challenges because assumptions (C) and (D) (user providing examples to refine intent, and subprograms being executable for semantic equivalence) are harder to satisfy.
- Future Work:
- Adapting NLX for domains where compositionality is not easily satisfied, potentially by using types to suggest repairs.
- Generalizing components to include sketches or terms with holes.
- Fine-tuning PTMs for better initial candidate generation.
- Exploring applicability to more expressive general-purpose languages like Python, Java, and C#, possibly by using "traces" of examples over pseudo-code.
- Investigating the use of the APPS benchmark for evaluating NL to code techniques.
Summary updated