[Paper Review] InCoder: A Generative Model for Code Infilling and Synthesis
InCoder is a unified 6.7B transformer model trained with a causal masking objective to perform both code synthesis and infilling. It uses bidirectional context to infill arbitrary code regions in zero-shot tasks while preserving left-to-right generation capabilities.
Code is seldom written in a single left-to-right pass and is instead repeatedly edited and refined. We introduce InCoder, a unified generative model that can perform program synthesis (via left-to-right generation) as well as editing (via infilling). InCoder is trained to generate code files from a large corpus of permissively licensed code, where regions of code have been randomly masked and moved to the end of each file, allowing code infilling with bidirectional context. Our model is the first generative model that is able to directly perform zero-shot code infilling, which we evaluate on challenging tasks such as type inference, comment generation, and variable re-naming. We find that the ability to condition on bidirectional context substantially improves performance on these tasks, while still performing comparably on standard program synthesis benchmarks in comparison to left-to-right only models pretrained at similar scale. The InCoder models and code are publicly released. https://sites.google.com/view/incoder-code-models
Motivation & Objective
- Motivate a unified model capable of both program synthesis and code editing (infilling).
- Develop a training objective that enables infilling within arbitrary code spans using bidirectional context.
- Evaluate zero-shot infilling performance on diverse tasks (type inference, docstring generation, variable renaming) and compare to left-to-right generation.
- Demonstrate that bidirectional infilling improves task performance without compromising left-to-right synthesis capabilities.
Proposed method
- Adopt a causal masking objective that randomly masks spans in code and moves them to the end of the sequence, training the model to predict the full sequence.
- Train InCoder-6.7B on a large corpus of permissively licensed code and StackOverflow content across 28 languages, with Python as the primary focus.
- During inference, support both left-to-right generation and infilling by inserting masks at desired locations and generating replacements conditioned on left and right contexts.
- Evaluate zero-shot infilling on tasks such as type inference, comment generation, and variable renaming, comparing causal-masked infilling to left-to-right generation and reranking baselines.
- Compare against masked-language-model approaches and large left-to-right models to show infilling benefits without sacrificing synthesis ability.
- Provide analyses including ablations on model size, data, and objective, and report main results for infilling benchmarks.
Experimental results
Research questions
- RQ1Can causal masking enable zero-shot infilling of arbitrary code spans conditioned on bidirectional context?
- RQ2Does bidirectional context in infilling improve tasks like type inference, docstring generation, and variable renaming compared to left-to-right baselines?
- RQ3Does infilling harm, or at least not significantly harm, standard left-to-right code synthesis performance?
- RQ4What is the impact of model size and training data mix on infilling and synthesis capabilities?
Key findings
- Zero-shot causal-masked infilling substantially improves over left-to-right baselines on infilling tasks (single-line and multi-line).
- Bidirectional context enables strong performance on type inference and return-type prediction, with causal-masked infilling achieving substantial gains over baselines.
- Docstring generation in zero-shot settings approaches the performance of supervised, fine-tuned models.
- InCoder maintains competitive left-to-right synthesis performance on standard benchmarks despite the infilling objective.
- Training with multiple languages and StackOverflow data benefits performance compared to Python-only data, though multi-language data can slightly reduce Python-specific results.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.