Abstract
While large language models (LLMs) now excel at code generation, a key aspectof software development is the art of refactoring: consolidating code intolibraries of reusable and readable programs. In this paper, we introduce LILO,a neurosymbolic framework that iteratively synthesizes, compresses, anddocuments code to build libraries tailored to particular problem domains. LILOcombines LLM-guided program synthesis with recent algorithmic advances inautomated refactoring from Stitch: a symbolic compression system thatefficiently identifies optimal lambda abstractions across large code corpora.To make these abstractions interpretable, we introduce an auto-documentation(AutoDoc) procedure that infers natural language names and docstrings based oncontextual examples of usage. In addition to improving human readability, wefind that AutoDoc boosts performance by helping LILO's synthesizer to interpretand deploy learned abstractions. We evaluate LILO on three inductive programsynthesis benchmarks for string editing, scene reasoning, and graphicscomposition. Compared to existing neural and symbolic methods - including thestate-of-the-art library learning algorithm DreamCoder - LILO solves morecomplex tasks and learns richer libraries that are grounded in linguisticknowledge.