arXiv:2509.25247cs.SEcs.AI2025-09被引 1

通过原型采样提升大模型代码生成的可解释性与性能

Protocode: Prototype-Driven Interpretability for Code Generation in LLMs

  • 基于语法树分析筛选优质上下文示范样本
  • 优质示范使代码通过率(pass@10)提升,差示范则下降
  • 适合关注代码安全与可维护性的开发者和研究者

自大语言模型(LLMs)问世以来,其在文本摘要、问答、语音转写等任务中广泛应用。近年来,利用LLMs进行代码生成受到重视,工具如Cursor和Windsurf已能分析大规模代码库并推荐修改。科技巨头也日益依赖LLMs在代码库中自动生成代码。尽管显著提升了开发效率,但自动化生成也带来次优解和安全隐患风险。本文提出自动采样上下文学习(ICL)示范的方法,以提升模型性能与生成代码的可解释性。通过对MBPP测试集输出进行基于抽象语法树(AST)的分析,识别出受示范影响最明显的代码区域。实验表明,高质量的ICL示范不仅使输出更易理解,还提升了pass@10指标;而低质量示范则导致性能低于基础模型。结果凸显了高效示范采样策略对模型表现的关键影响。

原文摘要 · Abstract (English)

Since the introduction of Large Language Models (LLMs), they have been widely adopted for various tasks such as text summarization, question answering, speech-to-text translation, and more. In recent times, the use of LLMs for code generation has gained significant attention, with tools such as Cursor and Windsurf demonstrating the ability to analyze massive code repositories and recommend relevant changes. Big tech companies have also acknowledged the growing reliance on LLMs for code generation within their codebases. Although these advances significantly improve developer productivity, increasing reliance on automated code generation can proportionally increase the risk of suboptimal solutions and insecure code. Our work focuses on automatically sampling In-Context Learning (ICL) demonstrations which can improve model performance and enhance the interpretability of the generated code. Using AST-based analysis on outputs from the MBPP test set, we identify regions of code most influenced by the chosen demonstrations. In our experiments, we show that high-quality ICL demonstrations not only make outputs easier to interpret but also yield a positive performance improvement on the pass@10 metric. Conversely, poorly chosen ICL demonstrations affected the LLM performance on the pass@10 metric negatively compared to the base model. Overall, our approach highlights the importance of efficient sampling strategies for ICL, which can affect the performance of the model on any given task.

代码生成可解释性上下文学习LLM

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