Introduction
Neural program synthesizers often fail to generalize to complex tasks that require combining known coding concepts in new ways. This paper introduces ExeDec (Execution Decomposition), a novel approach that breaks down programming tasks by predicting intermediate execution states (subgoals) before writing the code, mimicking human problem-solving. ExeDec drastically improves compositional generalization in both custom-trained Transformers and Large Language Models (LLMs).
The Challenge of Compositional Generalization
Imagine teaching a student how to use a for loop and how to use an if statement. A human programmer can easily combine these two concepts to filter a list, even if they've never seen them used together. This ability is known as compositional generalization.
Neural networks, however, are notoriously bad at this. In Programming by Example (PBE)—where an AI writes code based on input/output examples—models tend to overfit to the exact combinations of operations seen during training. If a model only saw operations A and B separately, it usually fails when asked to combine them, switch their order, or write a program longer than its training examples.
To systematically measure this, the authors designed a meta-benchmark defining five distinct types of compositional generalization:
- Length Generalization
- Compose Different Concepts
- Switch Concept Order
- Compose New Operation
- Add Operation Functionality
ExeDec: Execution Decomposition
To solve these generalization challenges, the authors introduce ExeDec. Instead of predicting a program token-by-token in a single pass, ExeDec plans step-by-step in the execution space:
- SubgoalModel: Looks at the input/output examples and predicts the intermediate state (the desired output of the very next line of code).
- SynthesizerModel: Takes that intermediate state and writes the actual code snippet to achieve it.
- Execution & Search: The predicted code is executed, the program state is updated, and the process repeats using a beam search to explore different solution paths.
Predicting what the code should do (the execution state) before how to do it (the syntax) shields the model from overfitting to spurious structural patterns in the training data. It forces the model to learn robust, independent sub-tasks.
The authors also adapt this logic to few-shot prompting for LLMs. Instead of asking an LLM to just output the final code, they prompt it to predict the execution result of step 1, then the code for step 1, and so on. Forcing the model to commit to a subgoal first significantly improves its reasoning.
Experimental Setup
The authors instantiated their meta-benchmark on two popular program synthesis domains, creating new, rigorous train/test splits for each:
- RobustFill: A domain for string manipulation tasks (similar to Excel's Flash Fill).
- DeepCoder: A domain for integer list manipulation using line-by-line functional programming (e.g.,
Map,Filter,Sort).
Key Results
ExeDec demonstrated massive improvements over standard approaches across both custom-trained models and LLMs.
- Transformers Trained from Scratch: ExeDec significantly outperformed standard Transformer baselines. It achieved +44% higher average accuracy on RobustFill's generalization tasks. On the much harder DeepCoder dataset, it achieved an 18% absolute improvement, which translates to a 4.4x higher success rate.
- Ablation Success: ExeDec also beat a "no-subgoal" ablation (which predicts code step-by-step but skips predicting the intermediate state). This proves that explicitly predicting the execution subgoal is the primary driver of the performance boost.
- LLM Prompting: Even massive, state-of-the-art LLMs (like PaLM 2 Unicorn) struggle to generalize compositionally in few-shot PBE settings, relying heavily on the exact patterns shown in the prompt. However, using the ExeDec-style prompt on a Pythonic version of DeepCoder allowed the LLM to solve 40% to 75% more tasks compared to standard step-by-step or baseline prompting.
Limitations and Future Work
While highly effective, ExeDec has a few limitations that pave the way for future research:
- Data Hungry: Training ExeDec from scratch requires datasets that include ground-truth, step-by-step decompositions. These are easy to generate synthetically but harder to source for real-world, general-purpose code.
- Granularity: ExeDec currently decomposes programs line-by-line. Human programmers often think in larger chunks or hierarchical structures (e.g., "first I'll write the helper function, then the main loop"). Extending ExeDec to support hierarchical decomposition is a natural next step.
- Scalability of States: The
SubgoalModelpredicts exact tokenized representations of intermediate objects. While this works for short strings and lists, it would struggle with massive, complex data structures (like a large database state). Future iterations might need to predict abstractions of states rather than literal values.
Summary updated