fill-in-the-middle
Fill-in-the-middle (FIM) generates code for a middle section given surrounding context, enabling intelligent code insertion. **Problem**: Standard language models generate left-to-right, but coding often requires inserting code between existing code. **FIM training**: Rearrange code sequences: PREFIX + SUFFIX leads to MIDDLE. Model learns to generate appropriate middle given surrounding context. **Format**: Special tokens mark sections: prefix code, suffix code, then model generates middle. **Why it helps**: Better function body completion (given signature and usage), infilling documentation, implementing interface methods, completing partial code. **Model support**: CodeLlama, StarCoder, DeepSeek-Coder, Codestral trained with FIM objective. Some models need specific FIM fine-tuning. **IDE integration**: Copilot-style completions that consider code after cursor, not just before. More natural insertions. **Evaluation**: Different from standard left-to-right, measure exact match and functional correctness for FIM tasks. **Related techniques**: Infilling for text, span corruption (T5), prefix-suffix-middle variants. **Impact**: Significantly improves code completion quality in real editing scenarios. Standard feature in modern code models.