Learning to Infer Program Sketches: A Neuro-Symbolic Approach
SketchAdapt is a neuro-symbolic program synthesis system that learns to "delegate" difficult coding tasks. By generating a partial program (a "sketch") with holes, it allows a neural network to handle familiar patterns while a symbolic search engine fills in the complex logic. This hybrid approach achieves state-of-the-art results on English-to-code benchmarks by combining the intuition of neural networks with the rigor of symbolic logic.
The Problem: Neural vs. Symbolic Synthesis
Writing code automatically from high-level specifications—such as natural language instructions or input-output examples—is a holy grail of AI. Currently, two main approaches dominate, each with distinct trade-offs:
- Neural Synthesis: These models are fast and excel at recognizing patterns. However, they are brittle. If a target program deviates slightly from the training data, neural models often "hallucinate" incorrect code.
- Symbolic Search: These engines are robust and precise, but notoriously slow. They suffer from a "combinatorial explosion"—as the program gets longer, the number of possible code combinations becomes too vast to search efficiently.
The authors address the gap between these two paradigms: how can a system automatically decide which parts of a program are easy enough to "guess" (neural) and which parts require rigorous "thinking" (symbolic search)?
Methods: Introducing SketchAdapt
To solve this, the authors introduce SketchAdapt, a system comprising two main components working in tandem.
- The Sketch Generator (Neural): A sequence-to-sequence Recurrent Neural Network (RNN) with attention. Instead of attempting to write the entire program, it outputs a sketch—a program tree where difficult or unfamiliar sub-trees are replaced by a special
<HOLE>token. - The Program Synthesizer (Symbolic): An enumerative search engine that takes the generated sketch and systematically tries to fill the holes with valid code that satisfies the original specification.
The "Aha!" Moment in Training: Typically, training such a system would require a massive dataset of "correct sketches," which does not exist. To overcome this, the authors developed a self-supervised training objective. They train the neural generator to maximize the probability of producing a sketch that the symbolic searcher can successfully complete within a specific time budget.
By varying this time budget during training, the model learns a "division of labor." It learns to provide more detail for easy tasks (saving search time) and leave more holes for difficult, unfamiliar tasks (relying on the searcher's precision).
Key Insights
- Dynamic Specificity: Unlike previous work that relied on hand-designed, static sketches, SketchAdapt learns exactly how much detail to provide dynamically. For "easy" tasks, the sketch is nearly a full program. For "hard" tasks, it acts as a broad structural outline.
- Generalization through Abstraction: Purely neural models often fail on "out-of-sample" data, such as being asked to write a program longer than any seen in training. SketchAdapt handles this by leaving holes in the parts it doesn't recognize, allowing the symbolic searcher to find the correct logic regardless of length.
- Search Time as a Training Signal: Treating the "synthesizability" of a sketch as the primary reward mimics human programming behavior: writing a "skeleton" of a function first, then focusing mental energy on the trickiest lines of logic.
Key Results
The model was evaluated across three distinct domains: List Processing, String Transformations, and AlgoLisp (a complex dataset of English-to-code problems).
- Out-of-Distribution Success: When trained on list programs of length 3 and tested on length 4, SketchAdapt maintained high performance, whereas the "Generator-only" neural baseline saw its accuracy plummet.
- AlgoLisp SOTA and Data Efficiency: SketchAdapt achieved 90.0% accuracy on the AlgoLisp test set, outperforming the previous state-of-the-art (85.8%) and significantly beating "Synthesizer-only" (7.3%) and "Generator-only" (88.6%) baselines.
Furthermore, as shown above, SketchAdapt reached high accuracy with significantly fewer training examples than pure neural models. This proves that the symbolic search component acts as a powerful inductive bias, making the model highly data-efficient.
Limitations and Future Work
While powerful, SketchAdapt has limitations. It still requires a Domain Specific Language (DSL) and a predefined grammar; it cannot yet write arbitrary Python or C++ code in an unconstrained environment. Additionally, if the <HOLE> covers a logic block that is too large, the symbolic searcher will still hit a combinatorial wall.
Future directions suggest applying this neuro-symbolic delegation to other complex AI tasks beyond coding, such as high-level planning or sophisticated question answering, where a mix of fast "intuition" and slow "reasoning" is required.
Summary updated