CATMark: A Context-Aware Thresholding Framework for Robust Cross-Task Watermarking in Large Language Models

Yu Zhang, Shuliang Liu, Xu Yang, Xuming Hu · DOI

Abstract

CATMark is a dynamic watermarking framework for Large Language Models (LLMs) that automatically adjusts its intensity based on the semantic context of the generated text. By using real-time logit clustering and adaptive entropy thresholds, it successfully embeds robust watermarks in mixed-modality outputs—such as code interleaved with natural language—without compromising functional correctness or text quality.

Introduction

The proliferation of Large Language Models (LLMs) has made the ability to distinguish machine-generated text from human writing critical for preventing misinformation and academic dishonesty. The current state-of-the-art approach is statistical watermarking, which involves subtly biasing the model’s output toward a specific set of "green" tokens.

However, existing methods face a significant "quality vs. detectability" trade-off. In high-entropy scenarios, such as creative writing, biasing the model is relatively harmless. Conversely, in low-entropy scenarios like code generation or mathematical problem-solving, the model's choices are deterministic; forcing a watermark in these regions often breaks logic or accuracy. Previous solutions utilized static entropy thresholds, but these require manual tuning and fail when a single response switches between content types (e.g., a code snippet followed by an explanatory comment).

Methodology

The authors introduce CATMark (Context-Aware Thresholding), an automated framework that replaces "one-size-fits-all" thresholds with a dynamic three-step process.

The CATMark framework overview, illustrating the pipeline from dynamic token clustering to context-aware thresholding and final watermark embedding.
  1. Dynamic Token Clustering: As the model generates text, CATMark categorizes the "generation state" in real-time. It uses Kullback-Leibler (KL) divergence to compare the current probability distribution (logits) against learned prototypes, distinguishing between states like "code-writing" and "narrative-explanation."
  2. Adaptive Entropy Thresholding: Rather than a fixed value, CATMark calculates a tailored entropy threshold for each cluster. It analyzes the historical distribution of entropy within a specific semantic context and uses a quantile-based function to determine safe watermark embedding regions.
  3. Weighted Detection: During verification, the system employs an entropy-weighted z-score, giving more weight to tokens in high-entropy regions where the watermark was most likely to be successfully embedded.

Experimental Setup

CATMark was evaluated across several challenging cross-task benchmarks to test its adaptability:

  • HumanEval & MBPP: Python code generation requiring line-by-line natural language comments.
  • MATH-500: Complex mathematical problems requiring step-by-step reasoning and structured formulas.
  • StackEval: 925 questions from Stack Overflow covering debugging and conceptual explanations across multiple programming languages.

Results and Discussion

CATMark consistently outperformed established baselines such as KGW, SWEET, and EWD across multiple dimensions.

Comparison of CATMark's adaptive thresholding against fixed thresholds across different tasks, demonstrating how the framework adjusts to varying entropy levels in code and narrative text.
  • Functional Correctness: On HumanEval, CATMark achieved an 82.3% pass@1 score, matching the quality of unwatermarked models, whereas older methods often saw significant performance drops.
  • Detection Accuracy: The framework achieved a near-perfect 100% AUROC on the StackEval benchmark, effectively eliminating false positives.
  • Efficiency: Computational overhead is minimal, with generation speed decreasing by only approximately 5.4% (33.1 tokens/sec vs. ~35-36 for baselines).

A key insight of this work is that context-awareness allows entropy to be treated as a relative measure rather than an absolute one. By eliminating the "tuning tax" associated with manual threshold calibration, CATMark offers a practical solution for real-world deployment. Furthermore, the method demonstrates resilience to "scrubbing" attacks, such as back-translation and paraphrasing.

Conclusion

While CATMark represents a significant advancement, challenges remain. Potential vulnerabilities include redundancy injection attacks, where attackers inject high-entropy noise to dilute the watermark signal. Future work will focus on extending context-aware watermarking to multimodal models and addressing the evolution of adversarial "scrubbing" tools.

Summary updated

Abstract

Watermarking algorithms for Large Language Models (LLMs) effectively identify machine-generated content by embedding and detecting hidden statistical features in text. However, such embedding leads to a decline in text quality, especially in low-entropy scenarios where performance needs improvement. Existing methods that rely on entropy thresholds often require significant computational resources for tuning and demonstrate poor adaptability to unknown or cross-task generation scenarios. We propose $\textbf{C}$ontext-$\textbf{A}$ware $\textbf{T}$hreshold watermarking (CATMark), a novel framework that dynamically adjusts watermarking intensity based on real-time semantic context. CATMark partitions text generation into semantic states using logits clustering, establishing context-aware entropy thresholds that preserve fidelity in structured content while embedding robust watermarks. Crucially, it requires no pre-defined thresholds or task-specific tuning. Experiments show CATMark improves text quality in cross-tasks without sacrificing detection accuracy.
BibTeX
@misc{zhang2025catmark,
  author = {Yu Zhang and Shuliang Liu and Xu Yang and Xuming Hu},
  title = {{CATMark: A Context-Aware Thresholding Framework for Robust Cross-Task Watermarking in Large Language Models}},
  year = {2025},
  eprint = {2510.02342},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.02342},
}
Figure