Toward Code Generation: A Survey and Lessons from Semantic Parsing

Celine Lee, Justin Gottschlich, Dan RotharXiv 2021

Introduction

The central challenge in modern software engineering is bridging the "intention gap"—the conceptual distance between a human's high-level goals and the rigid, formal code required to execute them. This survey explores the evolution of semantic parsing, the process of translating natural language (NL) into structured logical forms, as a foundational step toward fully automated "Machine Programming." While historical semantic parsing focused on narrow domains like SQL queries, the field is now pivoting toward general-purpose code generation in languages like Python and C++.

The Three Pillars of Machine Programming

The authors frame the broader landscape of machine programming through three interconnected pillars: Intention, Invention, and Adaptation.

The Three Pillars of Machine Programming: Intention, Invention, and Adaptation.
  • Intention: Discovering the programmer's intent and lifting meaning from software. Semantic parsing serves as the primary bridge for this pillar.
  • Invention: Creating new algorithms and data structures to solve the identified problem.
  • Adaptation: Evolving and optimizing the solution within a changing hardware and software ecosystem.

Methodological Evolution

The survey categorizes the development of semantic parsing into three distinct eras:

  1. Rules-based (1970s–1980s): These early systems relied on hand-crafted syntactic patterns. While precise, they were brittle and failed when users deviated from expected phrasing.
  2. Statistical/Grammar Induction (1990s–2000s): Researchers began using data to learn rules, employing formalisms like Combinatory Categorial Grammar (CCG) to map sentences to lambda calculus.
  3. Neural Models (Modern Era): The current state-of-the-art utilizes Encoder-Decoder (Seq2Seq) frameworks, typically leveraging LSTMs or Transformers equipped with Attention mechanisms.
Neural architecture for semantic parsing using an encoder-decoder framework with attention.

To improve the reliability of neural models, several novel approaches have emerged:

  • Grammar-Constrained Decoding: Using Abstract Syntax Trees (ASTs) to restrict the model’s output to only syntactically valid code.
  • Sketching: A "coarse-to-fine" method where the model first generates a logical "blueprint" before filling in specific arguments.
  • Copy Mechanisms: Pointer networks that allow models to handle out-of-vocabulary terms by copying variable names directly from the input.

Datasets and Benchmarks

The paper reviews landmark datasets that have shaped the field:

  • Classic Semantic Parsing: Geo880 (geography), Jobs640 (job listings), and ATIS (flight reservations).
  • Code-Specific Benchmarks: SQL datasets (like Spider), If-This-Then-That (IFTTT) recipes, and SPoC (Python from pseudocode).

Key Insights and Results

A fundamental realization in semantic parsing is the need to "lift" semantics from syntax; disparate sentences (e.g., "The boy cannot go" vs. "It is not possible for the boy to go") must map to the same logical form.

Qualitatively, the field has seen significant shifts:

  • Generalization: Neural models handle "out-of-distribution" tasks far better than rule-based predecessors.
  • Structural Integrity: By using AST-based constraints, models have moved from generating "text that looks like code" to generating functional, runnable programs.
  • Supervision by Denotation: Training models using binary feedback (whether the code produced the correct answer) reduces the need for expensive, manually labeled logical forms.

Future Directions

Despite progress, several hurdles remain. Current metrics like BLEU are inadequate for code, as they fail to account for functional equivalence. Future work must focus on semantic reasoning evaluators and universal representations that are language-agnostic. Furthermore, as human intent is often ambiguous, future systems should move toward a conversational paradigm, seeking clarification rather than relying on guesswork for complex, large-scale program generation.

Summary updated

BibTeX
@misc{lee2021toward,
  author = {Celine Lee and Justin Gottschlich and Dan Roth},
  title = {{Toward Code Generation: A Survey and Lessons from Semantic Parsing}},
  year = {2021},
  eprint = {2105.03317},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.03317},
}
Figure