返回
Steer Your Model: Secure Code Generation With Contrastive Decoding
DOI:10.1109/TSE.2025.3650127.png)
摘要
En 中文
专注于代码的大型语言模型(LLMs)已在代码生成等各种编程任务中展现出出色的能力。然而,由于训练数据集存在来自大规模、未过滤开源仓库的固有缺陷,这些模型经常生成存在漏洞的代码。现有的方法如SVEN(前缀微调)和CoSec(监督协同解码)试图解决这些风险,但面临可迁移性差或安全约束不灵活的挑战。为缓解这些问题,我们提出了SCoDE,一种用于安全且功能正确的代码生成的两阶段方法。在初始功能微调阶段后,我们在模型的输出嵌入层集成一个即插即用的安全引导矩阵。该矩阵可在不修改原始权重的情况下跨模型迁移。在推理过程中,我们引入了一种新颖的对比解码机制,能够自适应地平衡基模型的功能性logits与正向和负向安全引导信号。在60个安全场景及两个标准基准(HumanEval、MBPP)上,使用StarCoder、Qwen2.5-Coder和CodeLlama进行的广泛实验表明,SCoDE在保持功能正确性的同时增强了安全性。平均而言,SCoDE相较于原始模型提升安全性28.09%,相较CoSec提升12.07%,相较SVEN提升4.82%。在功能正确性方面,相较于原始模型,在HumanEval上平均提升55.03%,在MBPP上平均提升41.81%。
Keyword:
Large language models
code generation
code security
contrastive decoding
期刊
IF:
5.6
论文数:
2.9K
被引数:
1.1W
机构
引用论文
Nazzal, M., Khalil, I., Khreishah, A., Phan, N., 2024a. Promsec: Prompt optimization for secure generation of functional source code with large language models (LLMs). In: Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security. Association for Computing Machinery, New York, NY, USA, p. 2266–2280. https://doi.org/10.1145/3658644.3690298. 10.1145/3658644.3690298Nazzal, M., Khalil, I., Khreishah, A., Phan, N., 2024a. Promsec: 大型语言模型(LLMs)用于功能性源代码安全生成的提示优化。刊于:2024年ACM SIGSAC计算机与通信安全会议论文集。美国计算机协会,纽约,美国,第2266–2280页。https://doi.org/10.1145/3658644.3690298. 10.1145/3658644.3690298
Li, D., Yan, M., Zhang, Y., Liu, Z., Liu, C., Zhang, X., Chen, T., Lo, D., 2024. Cosec: On-the-fly security hardening of code LLMs via supervised co-decoding. In: Christakis, M., Pradel, M. (Eds.), Proceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis, ISSTA 2024, Vienna, Austria, September 16-20, 2024. ACM, pp. 1428–1439. https://doi.org/10.1145/3650212.3680371. 10.1145/3650212.3680371Li, D., Yan, M., Zhang, Y., Liu, Z., Liu, C., Zhang, X., Chen, T., Lo, D., 2024. Cosec: 通过监督共解码实现代码大语言模型的即时安全加固。载:Christakis, M., Pradel, M.(主编),第33届ACM SIGSOFT国际软件测试与分析 Symposium 会议录,ISSTA 2024,奥地利维也纳,2024年9月16-20日,ACM,第1428-1439页。https://doi.org/10.1145/3650212.3680371. 10.1145/3650212.3680371
Enhancing Contextual Understanding in Large Language Models through Contrastive Decoding通过对比解码增强大型语言模型中的情境理解

