Large language models for code have recently shown remarkable performance in generating executable code. However, this rapid advancement has been accompanied by many legal and ethical concerns, such as code licensing issues, code plagiarism, and malware generation, making watermarking machine-generated code a very timely problem. Despite such imminent needs, we discover that existing watermarking and machine-generated text detection methods for LLMs fail to function with code generation tasks properly. Hence, in this work, we propose a new watermarking method, SWEET, that significantly improves upon previous approaches when watermarking machine-generated code. Our proposed method selectively applies watermarking to the tokens with high enough entropy, surpassing a defined threshold. The experiments on code generation benchmarks show that our watermarked code has superior quality compared to code produced by the previous state-of-the-art LLM watermarking method. Furthermore, our watermark method also outperforms DetectGPT for the task of machine-generated code detection.
翻译:用于代码的大型语言模型近期在生成可执行代码方面展现了卓越性能。然而,这一快速进展伴随着诸多法律和伦理问题,例如代码许可争议、代码抄袭和恶意软件生成,使得对机器生成代码添加水印成为一项非常紧迫的课题。尽管需求迫切,我们发现现有的面向大型语言模型的水印技术和机器生成文本检测方法无法有效适用于代码生成任务。为此,本文提出一种新型水印方法——SWEET,该方法在机器生成代码的水印处理上显著优于先前方案。我们提出的方法选择性地对熵值超过设定阈值的令牌施加水印。基于代码生成基准的实验结果表明,与先前最先进的大型语言模型水印方法相比,我们的水印代码具有更优质量。此外,在机器生成代码检测任务中,我们的水印方法也优于DetectGPT。