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能解决更复杂任务,并学习到更丰富、植根于语言知识的程序库。