NoviCode: Generating Programs from Natural Language Utterances by Novices

Asaf Achi Mordechai, Yoav Goldberg, Reut Tsarfaty

This paper introduces NoviCode, a new benchmark and modeling approach designed to bridge the gap between how non-programmers describe tasks and how machines generate complex, executable code. While current LLMs excel at generating code from technical prompts, they often stumble when faced with the "noisy," implicit, and non-sequential language used by everyday people.

TL;DR

NoviCode shifts the code generation paradigm from technical "text-to-code" to "Natural Language Programming" (NLProg), where novices describe complex goals in everyday language. By mapping these descriptions to a hierarchical compact Abstract Syntax Tree (cAST) rather than raw code, the authors significantly improve the ability of LLMs to generate programs with intricate control flows like loops and conditions.

What Problem Does This Paper Address?

Most existing code generation benchmarks (like HumanEval) focus on short snippets or technical instructions written by programmers. These prompts often use jargon ("iterate," "if-else") and follow the logical order of the code.

In contrast, novices describe tasks intuitively. A novice might say, "Check that I received confirmation emails from all advisors in the committee or cancel my meeting with them." This single sentence implicitly requires:

  1. An iteration (looping through all advisors).
  2. A conditional check (did I get the email?).
  3. An API call (cancel meeting).

Furthermore, novices often describe steps out of order or use vague quantifiers like "every day" instead of explicit loop structures. Current models struggle to translate this high-level, "messy" intent into low-level, functionally correct code that adheres to specific, unseen APIs.

Methods

The authors propose a shift from end-to-end text-to-code generation to a structure-aware approach. The centerpiece of their method is the compact Abstract Syntax Tree (cAST).

Instead of training a model to output raw Python code, they train it to output a linearized, bracketed version of the program's logic. This cAST abstracts away boilerplate syntax and focuses on the hierarchical relationship between control flow elements (sequences, loops, and conditions).

Figure 4: An example of the cAST in a bracket notation.

By predicting the cAST first and then deterministically converting it back to Python, the model is forced to "think" about the program's structure before worrying about semicolons or indentation.

Datasets

The researchers curated a multi-part dataset to support this new task:

  • NoviCode Benchmark: 1,200 natural language utterances collected via crowd-sourcing from non-programmers across 9 domains (e.g., messaging, weather, smart home).
  • Human-Crafted Test Suites: 150 of these utterances were paired with rigorous unit tests. Unlike standard metrics that just check if the code looks right (like BLEU), these tests verify if the code works correctly across multiple execution scenarios.
  • Synthesized Training Set: 40,000 NL-code pairs generated using a grammar-based approach to help models learn the underlying API and structural patterns.

The complexity of the novice descriptions is reflected in the frequency of control flow structures found in the dataset:

Table showing the frequency of sequences, conditions, and loops in the crowd-sourced novice utterances.

Key Insights and Ideas

  • Implicit vs. Explicit: The biggest hurdle for LLMs isn't the API itself, but the implicit nature of novice language. Loops are particularly difficult because they are rarely mentioned by name; they are hidden in phrases like "all advisors" or "every Astros game."
  • Structure Over Form: Mapping to a cAST consistently outperforms direct text-to-code. This suggests that for complex programs, the hierarchy of the logic is a more effective "interlingua" than raw programming syntax.
  • Functional Evaluation is Essential: The authors argue that string-matching metrics are useless for this task. A generated program might look nothing like the reference code but still be 100% functionally correct.

Key Results

The authors tested several models, including GPT-4-Turbo, GPT-3.5, and fine-tuned versions of CodeT5+.

  • cAST Advantage: For GPT-4-Turbo, using the cAST representation improved the pass@1 score from 33.8% to 39.0%.
  • Fine-tuning Success: Smaller models saw even more dramatic gains. T5 (220M) failed completely (0%) on raw code but achieved a 9.7% pass@1 score when trained on cAST.
  • The "Loop" Gap: Models were fairly successful at sequences (68% success) but struggled significantly with loops (only 16% success), highlighting a major area for future research in NLProg.

Limitations and Future Work

The primary limitation is the cost of evaluation. Creating high-quality functional test suites is time-intensive, taking an experienced programmer about 9 minutes per test. This limited the current evaluation set to 150 problems.

Future work aims to scale this dataset and explore even more complex nesting of control flows. The authors also suggest that improving how models infer implicit loops from vague natural language quantifiers is a critical next step for making "Natural Language Programming" a reality for non-technical users.

Summary updated

BibTeX
@article{mordechai2024novicode,
  author = {Asaf Achi Mordechai and Yoav Goldberg and Reut Tsarfaty},
  title = {{NoviCode: Generating Programs from Natural Language Utterances by Novices}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2024},
  doi = {10.1162/tacl\_a\_00694},
}
Figure