Transformer-Assisted LLM-Based Source Code Summarisation: to Enable More Secure Software Development
作者: Jesse Phillips, Tracy Hall, Paul Rayson, Mo El-Haj
分类: cs.SE, cs.CL
发布日期: 2026-07-23
备注: 10 pages
期刊: NLPAICS 2026
💡 一句话要点
提出Transformer辅助的LLM源代码摘要生成方法以提升软件安全性
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 源代码摘要 大型语言模型 Transformer 软件安全 自然语言生成 提示工程 软件开发生命周期
📋 核心要点
- 现有的源代码摘要生成方法往往缺乏质量,导致软件维护阶段的理解困难。
- 论文提出通过结合Transformer生成的摘要与LLM,利用提示工程提升摘要质量。
- 实验结果显示,使用该方法在BLEU-4指标上提升了7.8%,证明了其有效性。
📝 摘要(中文)
神经源代码摘要生成(NSCS)旨在生成源代码的自然语言摘要,以提高开发者和维护者对代码的理解。在安全软件开发生命周期(SSDLC)的维护阶段,源代码摘要至关重要,因为它们能够帮助维护者更好地理解代码,减少软件系统中的错误和漏洞。然而,许多软件系统中的摘要往往缺失、不完整或过时。现有解决方案通常使用小型任务特定的Transformer模型或代码感知的大型语言模型(LLMs)。虽然任务特定的Transformer生成的摘要在许多自然语言生成(NLG)指标上表现良好,但这些指标往往奖励词汇重叠而非摘要质量。相反,LLMs能够捕捉语义并生成高质量摘要,提供了一个令人兴奋的解决方案。本文提出了一种“Transformer辅助的LLM源代码摘要生成”方法,通过将Transformer生成的摘要用于提示工程,观察到BLEU-4指标提升7.8%。
🔬 方法详解
问题定义:本文旨在解决源代码摘要缺失、不完整或过时的问题。现有方法如小型Transformer模型在NLG指标上表现良好,但往往未能有效捕捉摘要的语义质量。
核心思路:通过结合任务特定的Transformer生成的摘要与LLM,利用提示工程来提升LLM生成的代码摘要质量。这种设计旨在弥补LLM在生成摘要时的抽象性与开发者书写摘要的差异。
技术框架:整体架构包括四个主要模块:任务特定的Transformer模型用于生成初步摘要,四个不同的提示用于引导LLM生成最终摘要。通过这种组合,LLM能够更好地理解和生成高质量的代码摘要。
关键创新:最重要的技术创新在于将Transformer生成的摘要作为提示输入,帮助LLM生成更符合开发者需求的摘要。这一方法的本质区别在于通过提示工程提升了LLM的生成能力。
关键设计:在实验中,使用了四种不同的提示设计,以确保LLM能够在不同上下文中生成高质量的摘要。具体的参数设置和损失函数设计未在摘要中详细说明,需参考原文获取更多技术细节。
🖼️ 关键图片
📊 实验亮点
实验结果表明,采用Transformer辅助的LLM方法在BLEU-4指标上提升了7.8%,显示出显著的性能改进。这一提升不仅验证了方法的有效性,也为源代码摘要生成领域提供了新的思路和方向。
🎯 应用场景
该研究的潜在应用领域包括软件开发和维护,尤其是在安全软件开发生命周期中。通过生成高质量的源代码摘要,开发者和维护者能够更快地理解代码,减少错误和安全漏洞,从而提升软件的整体安全性和可靠性。未来,该方法有望在更多编程语言和开发环境中推广应用。
📄 摘要(原文)
Neural Source Code Summarisation (NSCS) aims to generate natural language summaries of source code to improve developers' and maintainers' understanding of code. Source code summaries are vital during the maintenance phase of the Secure Software Development Lifecycle (SSDLC), as they improve maintainers' understanding of code and help reduce the number of bugs and vulnerabilities in a software system. However, summaries are often missing, incomplete, or outdated in many software systems. Solutions to this problem use small, task-specific Transformer models or code-aware Large Language Models (LLMs). Task-specific Transformer-generated summaries often score well across many natural language generation (NLG) metrics, but these metrics reward lexical overlap rather than summary quality. Conversely, the ability of LLMs to capture semantics and produce high-quality summaries presents an exciting solution to this problem. This is especially relevant given the increased availability of LLMs and improvements in workstation hardware in recent years, which mean that some LLMs can now be run on developers' workstations. However, because of their abstractive nature, LLM-generated code summaries often differ greatly from developer-written summaries in the words and phrases they use, resulting in low scores across NLG metrics. We show how combining these two methods, by using Transformer-generated summaries in prompt engineering, may enable LLMs to create better source code summaries and help software practitioners maintain secure systems. We prompt four LLMs using four different prompts, with a task-specific Transformer used to assist the LLMs within the prompts. We present "Transformer-Assisted LLM-Based Source Code Summarisation", a method through which we observe an improvement of 7.8% in BLEU-4 and 5%.