arXiv:2504.04351cs.SEcs.AI2025-04被引 3

用扩散模型自动优化代码生成提示词,提升生成质量。

DDPT: Diffusion-Driven Prompt Tuning for Large Language Model Code Generation

  • 通过扩散模型从噪声生成最优提示嵌入向量。
  • 在代码生成损失引导下,学习最优提示分布,提升生成准确率。
  • 适合需要自动化提示工程的代码生成研究者与开发者。

大型语言模型(LLMs)在代码生成方面展现出卓越能力,但生成质量高度依赖提示词的结构与组成。高质量提示词的构建需丰富的提示工程知识与技能。为推进基于LLM的代码生成中提示工程的自动化,我们提出一种新方法——扩散驱动的提示调优(DDPT),该方法从高斯噪声中学习生成最优提示嵌入,实现代码生成提示工程的自动化。我们验证了基于扩散的优化可行性,并将最优提示嵌入抽象为指向最优嵌入的方向向量。利用LLM给出的代码生成损失,扩散模型在训练过程中捕捉最优提示嵌入的分布。训练后的扩散模型可在采样阶段从噪声分布生成通往最优分布的路径。实验结果表明,DDPT能有效提升代码生成中的提示优化效果。

原文摘要 · Abstract (English)

Large Language Models (LLMs) have demonstrated remarkable capabilities in code generation. However, the quality of the generated code is heavily dependent on the structure and composition of the prompts used. Crafting high-quality prompts is a challenging task that requires significant knowledge and skills of prompt engineering. To advance the automation support for the prompt engineering for LLM-based code generation, we propose a novel solution Diffusion-Driven Prompt Tuning (DDPT) that learns how to generate optimal prompt embedding from Gaussian Noise to automate the prompt engineering for code generation. We evaluate the feasibility of diffusion-based optimization and abstract the optimal prompt embedding as a directional vector toward the optimal embedding. We use the code generation loss given by the LLMs to help the diffusion model capture the distribution of optimal prompt embedding during training. The trained diffusion model can build a path from the noise distribution to the optimal distribution at the sampling phrase, the evaluation result demonstrates that DDPT helps improve the prompt optimization for code generation.

代码生成扩散模型提示工程

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。