While large language models (LLMs) now excel at code generation, a key aspect of software development is the art of refactoring: consolidating code into libraries of reusable and readable programs. In this paper, we introduce LILO, a neurosymbolic framework that iteratively synthesizes, compresses, and documents code to build libraries tailored to particular problem domains. LILO combines LLM-guided program synthesis with recent algorithmic advances in automated refactoring from Stitch: a symbolic compression system that efficiently 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 on contextual examples of usage. In addition to improving human readability, we find that AutoDoc boosts performance by helping LILO's synthesizer to interpret and deploy learned abstractions. We evaluate LILO on three inductive program synthesis benchmarks for string editing, scene reasoning, and graphics composition. Compared to existing neural and symbolic methods - including the state-of-the-art library learning algorithm DreamCoder - LILO solves more complex tasks and learns richer libraries that are grounded in linguistic knowledge.
翻译:尽管大型语言模型(LLMs)在代码生成方面表现卓越,但软件开发的关键环节在于重构的艺术:将代码整合为可复用、可读的程序库。本文提出LILO——一种神经符号框架,能够迭代式地合成、压缩并文档化代码,从而构建专属于特定问题领域的库。LILO将LLM引导的程序合成与Stitch(一种符号压缩系统)的最新算法进展相结合:该系统可在大型代码库中高效识别最优lambda抽象。为增强这些抽象的可解释性,我们引入自动文档化(AutoDoc)方法,通过分析代码使用上下文中的示例,自动推断自然语言名称与文档字符串。除提升人类可读性外,本文发现AutoDoc能帮助LILO的合成器更有效地解释和部署已习得的抽象,从而提升模型性能。我们在字符串编辑、场景推理与图形合成三个归纳式程序合成基准上评估LILO。与现有神经及符号方法(包括最先进的库学习算法DreamCoder)相比,LILO能解决更复杂的任务,并学习到更丰富、基于语言知识构建的库。