[论文解读] A Prompt Learning Framework for Source Code Summarization
本文提出 PromptCS,一种提示学习框架,通过训练一个连续提示代理来为大型语言模型(LLMs)生成有效的提示,用于源代码摘要任务,从而无需手动进行提示工程。该方法在性能上达到当前最先进水平,与微调相当,同时显著降低训练成本并提高效率,尤其在更大规模的 LLM 上表现更优。
(Source) code summarization is the task of automatically generating natural language summaries (also called comments) for given code snippets. Recently, with the successful application of large language models (LLMs) in numerous fields, software engineering researchers have also attempted to adapt LLMs to solve code summarization tasks. The main adaptation schemes include instruction prompting, task-oriented (full-parameter) fine-tuning, and parameter-efficient fine-tuning (PEFT). However, instruction prompting involves designing crafted prompts and requires users to have professional domain knowledge, while task-oriented fine-tuning requires high training costs, and effective, tailored PEFT methods for code summarization are still lacking. This paper proposes an effective prompt learning framework for code summarization called PromptCS. It no longer requires users to rack their brains to design effective prompts. Instead, PromptCS trains a prompt agent that can generate continuous prompts to unleash the potential for LLMs in code summarization. Compared to the human-written discrete prompt, the continuous prompts are produced under the guidance of LLMs and are therefore easier to understand by LLMs. PromptCS is non-invasive to LLMs and freezes the parameters of LLMs when training the prompt agent, which can greatly reduce the requirements for training resources. Our comprehensive experimental results show that PromptCS significantly outperforms instruction prompting schemes (including zero-shot learning and few-shot learning) on all four widely used metrics, and is comparable to the task-oriented fine-tuning scheme. In some base LLMs, e.g., StarCoderBase-1B and -3B, PromptCS even outperforms the task-oriented fine-tuning scheme. More importantly, the training efficiency of PromptCS is faster than the task-oriented fine-tuning scheme, with a more pronounced advantage on larger LLMs.
研究动机与目标
- 为解决在使用大型语言模型(LLMs)进行代码摘要时,手动提示工程所面临的挑战,该挑战需要专家知识且耗时较长。
- 降低在代码摘要任务中,面向特定任务的微调对 LLM 所带来的高计算成本。
- 开发一种非侵入式、无需微调参数的方法,使 LLM 能够在不重新训练模型的前提下实现有效的提示生成。
- 通过生成与 LLM 理解能力更匹配的提示,提升代码摘要的质量与相关性。
- 证明连续提示学习在某些情况下可超越零样本/少样本指令提示法,甚至优于微调。
提出的方法
- 训练一个提示代理来生成连续提示,而非离散的、人工设计的提示,从而更好地与 LLM 的内部表征对齐。
- 在训练过程中保持 LLM 参数冻结,使其具有非侵入性,并显著降低资源需求。
- 通过基于生成摘要质量的损失函数,利用 LLM 自身输出进行端到端优化。
- 通过基于梯度的更新方式优化连续提示,使模型能够自动学习有效的提示模式。
- 在 CodeSearchNet 数据集上对多种编程语言进行评估,使用 BLEU、METEOR、ROUGE-L 和 SentenceBERT 等标准指标。
- 开展人工评估,以对比基线方法,评估生成摘要的质量与相关性。
实验结果
研究问题
- RQ1可训练的提示代理能否生成连续提示,使其在代码摘要任务中优于人工设计的离散提示?
- RQ2在 LLM 冻结的前提下进行提示学习,其性能是否可与面向特定任务的微调相媲美?
- RQ3PromptCS 在不同基础 LLM 上的表现如何,尤其是在训练效率与可扩展性方面?
- RQ4与零样本或少样本指令提示法相比,连续提示能否提升代码摘要的质量?
- RQ5在人工评估中,该框架表现如何?是否能生成更自然、更准确的摘要?
主要发现
- 在 BLEU、METEOR、ROUGE-L 和 SentenceBERT 四项指标上,PromptCS 显著优于零样本和少样本指令提示法。
- 在 CodeGen-Multi-2B 和 StarCoderBase-1B 及 -3B 等基础 LLM 上,PromptCS 的性能甚至超过面向特定任务的微调。
- PromptCS 的训练效率高于微调,且在更大规模 LLM 上优势更为明显,这得益于参数冻结机制。
- 人工评估确认,PromptCS 生成的摘要质量高于基线方法,其相关性与自然度均更优。
- 提示代理能够生成与 LLM 兼容的连续提示,这是该框架成功的关键因素。
- 该框架在 CodeSearchNet 基准上展现出在多种编程语言上的强大泛化能力。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。