让代码摘要更符合工业需求,提升可读性和实用性
Precision in Practice: Knowledge Guided Code Summarizing Grounded in Industrial Expectations
- 基于开发预期设计新方法,融合领域知识与约束提示
- 在鸿蒙项目中使摘要质量提升26.71%(BLEU-4)
- 适合需要高质量代码文档的工业级研发团队
代码摘要对理解代码功能、降低维护与协作成本至关重要。尽管大语言模型(LLMs)在自动代码摘要方面取得进展,但其在工业场景中的实际效用仍不充分。与鸿蒙项目文档专家合作开展问卷调研发现,超过57.4%的现有方法生成摘要因违反开发者对工业文档的期望而被拒绝。开发者不仅关注语义相似性,还强调使用恰当领域术语、明确函数分类、避免冗余实现细节。为此,我们提出ExpSum,一种面向开发预期的代码摘要方法,整合函数元数据抽象、信息性元数据过滤、上下文感知领域知识检索及约束驱动提示,引导LLM生成结构化且符合预期的摘要。在鸿蒙项目及常用基准上评估显示,ExpSum持续优于所有基线,在鸿蒙项目上BLEU-4提升达26.71%,ROUGE-L提升20.10%。此外,基于LLM的评估表明,ExpSum生成摘要在其他项目中也更契合开发者预期,验证了其在工业代码文档中的有效性。
原文摘要 · Abstract (English)
Code summaries are essential for helping developers understand code functionality and reducing maintenance and collaboration costs. Although recent advances in large language models (LLMs) have significantly improved automatic code summarization, the practical usefulness of generated summaries in industrial settings remains insufficiently explored. In collaboration with documentation experts from the industrial HarmonyOS project, we conducted a questionnaire study showing that over 57.4% of code summaries produced by state-of-the-art approaches were rejected due to violations of developers' expectations for industrial documentation. Beyond semantic similarity to reference summaries, developers emphasize additional requirements, including the use of appropriate domain terminology, explicit function categorization, and the avoidance of redundant implementation details. To address these expectations, we propose ExpSum, an expectation-aware code summarization approach that integrates function metadata abstraction, informative metadata filtering, context-aware domain knowledge retrieval, and constraint-driven prompting to guide LLMs in generating structured, expectation-aligned summaries. We evaluate ExpSum on the HarmonyOS project and widely used code summarization benchmarks. Experimental results show that ExpSum consistently outperforms all baselines, achieving improvements of up to 26.71% in BLEU-4 and 20.10% in ROUGE-L on HarmonyOS. Furthermore, LLM-based evaluations indicate that ExpSum-generated summaries better align with developer expectations across other projects, demonstrating its effectiveness for industrial code documentation.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。