[论文解读] CodeIP: A Grammar-Guided Multi-Bit Watermark for Large Language Models of Code
CodeIP 是一种基于语法引导的多比特水印技术,用于 LLM 生成的代码,通过利用类型预测器引导标记生成,嵌入语义保持不变的水印。它在五种编程语言中实现了平均 0.95 的水印提取率,同时保持了代码的可用性和语义正确性。
Large Language Models (LLMs) have achieved remarkable progress in code generation. It now becomes crucial to identify whether the code is AI-generated and to determine the specific model used, particularly for purposes such as protecting Intellectual Property (IP) in industry and preventing cheating in programming exercises. To this end, several attempts have been made to insert watermarks into machine-generated code. However, existing approaches are limited to inserting only a single bit of information. In this paper, we introduce CodeIP, a novel multi-bit watermarking technique that inserts additional information to preserve crucial provenance details, such as the vendor ID of an LLM, thereby safeguarding the IPs of LLMs in code generation. Furthermore, to ensure the syntactical correctness of the generated code, we propose constraining the sampling process for predicting the next token by training a type predictor. Experiments conducted on a real-world dataset across five programming languages demonstrate the effectiveness of CodeIP in watermarking LLMs for code generation while maintaining the syntactical correctness of code.
研究动机与目标
- 解决当前缺乏灵活、多比特水印解决方案的问题,以保护 LLM 生成代码的语义正确性。
- 通过在代码生成过程中整合语法感知的标记预测,提升水印的鲁棒性和多样性。
- 实现对 AI 生成代码的可靠识别,以支持知识产权保护和学术诚信。
- 克服单比特或硬水印方法易被检测或造成语义破坏的局限性。
- 在保持高代码可用性的前提下,嵌入可验证的多比特信息(如模型供应商 ID)。
提出的方法
- 训练一个类型预测器,用于预测下一个标记的语法类别(如关键字、标识符),以指导水印插入过程。
- 通过基于预定义哈希函数和随机种子操纵候选标记的对数几率概率,在解码过程中嵌入水印位。
- 通过修改采样分布以优先选择符合预测语法类别的标记,强制实施语法约束。
- 在代码生成过程中实时插入水印,最大限度减少对模型输出的干扰。
- 使用软水印策略编码并嵌入多比特消息(如 ASCII 编码的 'GPT'),避免产生可检测的模式。
- 将水印直接集成到 LLM 推理流程中,实现无缝部署。

实验结果
研究问题
- RQ1基于语法引导的方法能否提升 LLM 生成的水印代码的语义正确性?
- RQ2CodeIP 在多种编程语言中保持代码可用性的前提下,提取多比特水印的效率如何?
- RQ3整合语法预测是否能增强水印对常见攻击(如裁剪或混淆)的鲁棒性?
- RQ4与单比特或硬水印方法相比,CodeIP 在提取准确率和语义保真度方面表现如何?
- RQ5CodeIP 是否能可靠地在生成代码中嵌入可识别的模型信息(如供应商 ID),而不会改变其功能?
主要发现
- CodeIP 在五种编程语言中实现了平均 0.95 的水印提取率,表现出高度可靠性。
- 该方法保持了高水平的语义正确性,这在所有评估编程语言中 CodeBLEU 指标的一致表现中得到证实。
- 语法预测的整合显著提升了标记选择的准确性——例如,在关键字上下文中正确预测 'in' 而非 ':'。
- CodeIP 对裁剪攻击表现出强韧性,即使在部分输入截断的情况下仍保持优异的提取性能。
- 在不同长度的消息插入下,水印保持鲁棒性,且在各种消息长度下均保持高提取准确率。
- 该方法在语义保真度和水印提取率方面均优于基线方法,尤其在复杂代码结构中表现更优。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。