A Code Generation Watermarking Method Based on Double Threshold
摘要
Due to the rapid development and powerful capabilities demonstrated by large language models, they have attracted extensive attention in the fields of ethics, academia, and law. Embedding watermarks in the content generated by large language models can be used to determine whether a text is generated by a model. Watermarking technology has also become an important means of detecting machine-generated code. However, existing methods have several issues. On one hand, due to the relatively fixed nature of code-generated content, it is difficult to effectively embed watermarks. On the other hand, existing methods adopt simplistic strategies when dealing with code-generated texts. Such a rough approach fails to balance the quality of code generation and the effectiveness of watermark detection. Based on this, we propose a double-threshold watermarking method (DTW). This method fully considers the impact of entropy values on watermarks. During the generation phase, tokens are divided into high, medium, and low entropy intervals. And different watermarking strategies are employed, effectively balancing code quality and watermark embedding. Experimental results show that this method significantly improves watermark detection performance while maintaining code quality. At the same time, it exhibits stronger robustness and adaptability against attacks under different conditions, providing a better solution for watermarking techniques in code generation.