Multi-modal program inference: a marriage of pre-trained language models and component-based synthesis

Kia Rahmani, Mohammad Raza, Sumit Gulwani, Vu Le, Daniel Morris, Arjun Radhakrishna, Gustavo Soares, Ashish Tiwari

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 approach significantly improves program synthesis accuracy, particularly in domains where natural language alone is ambiguous.

What Problem Does This Paper Address?

Synthesizing programs from natural language (NL) descriptions is a long-standing challenge in computer science. While PTMs like GPT-3 excel at understanding ambiguous NL, they often struggle to generate syntactically and semantically precise code. Conversely, traditional program synthesis techniques can produce precise code from examples but fail to handle the ambiguity inherent in NL. This paper addresses the gap by proposing a multi-modal approach that leverages both NL descriptions and input-output examples to overcome the limitations of each modality. The goal is to create a more robust and accurate program synthesis system that can handle real-world, often imprecise, user specifications.

Methods

The core of the proposed solution, NLX, is a domain-agnostic algorithm that orchestrates the interaction between a PTM and a component-based synthesis (CBS) engine.

  • PTM Integration: A PTM (specifically GPT-3) is used to generate a set of candidate programs from the NL description. This is achieved through a few-shot learning approach where the PTM is provided with a carefully crafted prompt containing a task description and sample question-answer pairs.
  • Component-Based Synthesis (CBS): The PTM's candidate programs are then used to guide a CBS process. This guidance is applied at three key stages:
  • Initialization: The PTM candidates provide a rich set of "maximal components" (frequently occurring, large sub-expressions) to seed the CBS search, avoiding the need to start from basic atomic elements.
  • Expansion: The CBS engine iteratively builds larger programs by combining existing components. The PTM's output is used to bias this expansion, favoring operator usage patterns observed in the PTM candidates.
  • Ranking: The final synthesized programs are ranked based on their similarity to the PTM candidates, ensuring structural closeness to what the PTM initially suggested.

This approach aims to leverage the PTM's ability to identify relevant components and operator patterns while using CBS to ensure the generated program precisely matches the provided examples.

Datasets

The authors evaluated their approach on two primary domains:

  • Regular Expressions (Regex):
    • DeepRegex Dataset: A benchmark set of 200 synthesis tasks sampled from the DeepRegex dataset, which consists of paraphrased natural language descriptions and automatically generated regular expressions.
  • StackOverflow Dataset: A curated set of 25 tasks derived from StackOverflow posts, involving natural language descriptions, faulty regexes, and accepted answers.
  • CSS Selectors:
    • A dataset of 19 tasks collected from StackOverflow questions related to CSS selectors. For evaluation, they synthetically created sample webpages with positive and negative examples.

Key Insights and Ideas

  • Synergy of PTMs and CBS: The paper demonstrates that combining the broad understanding of PTMs with the precise search capabilities of CBS is more effective than using either technique in isolation. PTMs provide crucial guidance for the CBS search, while CBS ensures the generated programs are correct and meet example-based specifications.
  • Maximal Components for Initialization: Instead of starting CBS with atomic components, using "maximal components" (frequently occurring, large sub-expressions) derived from PTM outputs significantly improves efficiency and effectiveness. This leverages the PTM's ability to identify meaningful building blocks.
  • PTM-Guided Operator Distribution: Biasing the CBS expansion phase based on the operator frequency distribution observed in PTM candidates helps steer the search towards more likely correct programs.
  • Domain-Agnostic Generality: The core NLX algorithm is designed to be domain-agnostic, showcasing its applicability to diverse programming domains like regular expressions and CSS selectors. This suggests a broader potential for the framework.
  • Prompt Engineering Matters: The quality of the PTM's output is highly sensitive to the prompt design. The authors highlight the importance of carefully crafting prompts with relevant question-answer pairs to elicit useful candidate programs.

Key Results

The proposed NLX system, when instantiated as NLX-REG for regular expressions, achieved state-of-the-art performance:

  • Regular Expressions: NLX-REG achieved 80% accuracy across both DeepRegex and StackOverflow datasets, outperforming specialized systems like REGEL (57.5% accuracy) and brute-force baselines (BFS, GPT-3). On the more challenging StackOverflow dataset, NLX-REG achieved 70% accuracy, significantly outperforming baselines.
  • CSS Selectors: NLX-CSS achieved 75% accuracy on a small dataset, outperforming BFS (56%) and GPT-3 (20%).
  • Example Efficiency: NLX-REG required fewer additional examples on average (1.5 rounds) compared to REGEL (2.3 rounds) to converge to the correct program, demonstrating efficient use of user feedback.

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 be hindered.
  • Compositionality Assumption: The theoretical completeness guarantee relies on a compositionality assumption for the DSL, which may not hold for all languages.
  • Manual Equivalence Checking (CSS): For the CSS domain, manual inspection was used for equivalence checking, which is not scalable.
  • Future Work:
    • Exploring other programming domains and more expressive general-purpose languages.
  • Adapting the approach for domains where example-based refinement is difficult, potentially by using other forms of intent specification.
  • Investigating the use of sketches as components.
  • Fine-tuning PTMs for better initial candidate generation.
  • Developing methods for constrained decoding to ensure PTMs generate valid code.
  • Extending the approach to handle larger programs and more complex programming techniques.

Summary updated

BibTeX
@article{rahmani2021multi,
  author = {Kia Rahmani and Mohammad Raza and Sumit Gulwani and Vu Le and Daniel Morris and Arjun Radhakrishna and Gustavo Soares and Ashish Tiwari},
  title = {{Multi-modal program inference: a marriage of pre-trained language models and component-based synthesis}},
  journal = {Proc. ACM Program. Lang.},
  year = {2021},
  doi = {10.1145/3485535},
}
Figure