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