arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2610.27634cs.SE
收藏

标准引导且感知依赖的代码级文档生成

Standards-Guided and Dependency-Aware Code-Level Documentation Generation

Tsinghua University(清华大学)

Tingxu Han, Wei Song, Ziming Li, Yuchen Chen, Weisong Sun, Zhenpeng Chen, Chunrong Fang, Zhenyu Chen, Yang Liu

AI总结:

本文提出标准引导且感知依赖的CODEDOC框架,结合静态分析与LLM评估协议生成代码文档,在10个Python仓库实验中质量优于基线,token消耗更少,与人类判断一致性良好。

摘要:

为软件仓库自动生成高质量文档仍具挑战性:现有方法大多将文档视为无约束的文本生成,缺乏明确的质量规范,严重依赖原始代码的长上下文提示,且对可复现评估的支持有限。本文认为代码级文档生成应是一项标准引导的软件工程任务,即依据权威标准衍生的明确可复用质量要求来生成和评估文档。我们将代码文档定义为按源代码路径组织的仓库函数与类的自然语言描述。本文提出CODEDOC这一标准引导且感知依赖的框架,其通过静态调用图与AST分析识别代码实体间的依赖关系,结合本地代码上下文、仓库路径及来自权威标准与风格指南的文档标准,构建感知依赖的结构化提示。我们还引入交互式LLM作为评估者的协议,该协议提供与标准对齐的反馈,以从正式及实践导向标准的细粒度维度优化生成的文档。对10个开源Python仓库的实验表明,在与标准对齐的评估下,CODEDOC生成的文档质量优于RepoAgent和长上下文基线,相对提升幅度分别为11.6%-17.0%和21.4%-29.6%,且每个文档实体消耗的token数约为长上下文基线的十分之一。一项人类研究证实,基于LLM的判断与人类判断之间存在显著一致性(Spearman's rho=0.72),且相关结果在不同评估LLM中均成立。代码可在该https地址获取。

英文摘要:

Automatically generating high-quality documentation for software repositories remains challenging: existing approaches largely treat documentation as unconstrained text generation, lacking explicit quality specifications, depending heavily on long-context prompts over raw code, and offering limited support for reproducible evaluation. We argue that code-level documentation generation should instead be a standards-guided software engineering task, in which documentation is generated and assessed against explicit, reusable quality requirements derived from authoritative standards. We define code documentation as natural-language descriptions of repository functions and classes, organized by source-code path. We present CODEDOC, a standards-guided and dependency-aware framework that identifies dependencies between code entities via static call-graph and AST analysis and constructs dependency-aware structured prompts combining local code context, repository paths, and documentation criteria drawn from authoritative standards and style guides. We further introduce an interactive LLM-as-a-judge protocol that supplies criterion-aligned feedback to refine generated documentation along fine-grained dimensions from formal and practice-oriented standards. Experiments on ten open-source Python repositories show that CODEDOC produces higher-quality documentation than RepoAgent and a long-context baseline under standards-aligned evaluation, with relative improvements of 11.6%-17.0% and 21.4%-29.6%, respectively, while consuming roughly an order of magnitude fewer tokens per documentation entity than the long-context baseline. A human study confirms substantial alignment between LLM-based and human judgments (Spearman's rho = 0.72), and the relative findings hold across different judge LLMs. Code is available at https://github.com/ControllableModel/CodeDoc.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑