Watermark-based detection shows strong potential for identifying machine-generated content, but applying it to code generation is still hard due to low entropy and strict structure, which limit flexibility and cause a trade-off between quality and detectability. Existing methods like SWEET use fixed entropy thresholds. They cannot adjust to different levels of token uncertainty across coding contexts. To overcome this limitation, we propose Entropy-Aware Watermarking (EAW), a framework that dynamically modulates watermark embedding strength based on local entropy signals. Specifically, EAW amplifies the greenlist bias in high-entropy regions, such as variable names or comments, while reducing interference in low-entropy, syntax-critical parts to maintain the functional correctness of the code. This adaptive mechanism enables EAW to maintain code naturalness without sacrificing detection robustness. Extensive experiments across multiple benchmarks demonstrate that EAW consistently outperforms prior baselines in both watermark detectability and code quality retention, establishing a better trade-off between transparency and reliability in code watermarking.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Entropy-Aware Watermarking for Code Generation Models

  • Ying Shi,
  • Siyuan Bao,
  • Hanzhou Wu,
  • Jingyu Ye,
  • Xinpeng Zhang

摘要

Watermark-based detection shows strong potential for identifying machine-generated content, but applying it to code generation is still hard due to low entropy and strict structure, which limit flexibility and cause a trade-off between quality and detectability. Existing methods like SWEET use fixed entropy thresholds. They cannot adjust to different levels of token uncertainty across coding contexts. To overcome this limitation, we propose Entropy-Aware Watermarking (EAW), a framework that dynamically modulates watermark embedding strength based on local entropy signals. Specifically, EAW amplifies the greenlist bias in high-entropy regions, such as variable names or comments, while reducing interference in low-entropy, syntax-critical parts to maintain the functional correctness of the code. This adaptive mechanism enables EAW to maintain code naturalness without sacrificing detection robustness. Extensive experiments across multiple benchmarks demonstrate that EAW consistently outperforms prior baselines in both watermark detectability and code quality retention, establishing a better trade-off between transparency and reliability in code watermarking.