Brifing

How to Watermark Your Text in Python to Detect Copying

Protect your writing with invisible digital fingerprints using simple Python scripts.

Towards Data Science4 min

1The Rise of AI Watermarking

Since 2024, major AI systems like Google's Gemini and Anthropic's Claude have implemented text watermarking technologies. These invisible markers, embedded directly into generated text, help identify AI-created content. China mandated such labeling in 2025, while 190 organizations adopted the EU's transparency code. This technology now processes billions of watermarked words daily, creating a new standard for content traceability in the AI era.

2Historical Precedents of Watermarking

Long before digital watermarks, creators used physical variants as copying detectors. Mapmakers inserted fake towns like Agloe, NY (1925), while encyclopedia editors created fictional entries like Lillian Mountweazel. These 'canary traps' revealed plagiarists when copied. Modern versions include Tesla's 2008 space variation technique and Genius's Morse-coded apostrophes in lyrics. These historical methods prove the concept's validity across centuries and media formats.

3Three Text Watermarking Methods

1) Invisible Unicode characters: Simple to implement but easily removed by sanitizers. 2) Keyed word substitutions: Survives light editing but fails against complete rewrites. 3) Meaning-level marks: Most durable against paraphrasing but requires generation-time implementation. Each method represents different trade-offs between detectability and durability, with practical applications varying by use case and expected threats.

4The Genius vs Google Case

Lyrics site Genius implemented two watermark systems: Morse-coded apostrophes (spelling 'REDHANDED') and space-based encodings ('Genius'). Their 2019 lawsuit against Google revealed 116 watermarked songs in search results. While the watermark proved copying, the case failed because Genius didn't own the underlying lyrics. This highlights watermarking's limitation: it proves copying, not ownership rights.

5Statistical Foundations

Watermark reliability comes from probability accumulation. Each binary choice (like word selection) has 50% random match chance. But 30 consecutive matches have 1-in-a-billion odds. This statistical evidence, expressed as p-values, forms the mathematical backbone of detection confidence. The more decisions embedded, the stronger the proof becomes against random coincidence claims.

6Unicode Invisible Characters

Zero-width Unicode characters like U+200B and U+200C create hidden channels in normal text. When assigned binary values (0/1), they form invisible fingerprints that persist through copying. First described in 2017, this technique lets leaked documents carry identifiers unknowingly. While detectable with specialized tools, these marks appear normal to human readers and basic text processors.

7Implementation Toolkit

The experimental setup used Gemma-2-9b-it for watermarking and Qwen2.5-7B-Instruct for attack simulations on NVIDIA GB10 hardware. Test corpus included 50 original and 100 public-domain paragraphs for false-positive checks. All scripts, datasets, and calibration tools are available in the text-watermarking-toolkit repository, enabling full reproducibility of the described techniques and results.

8Word-Choice Watermarking

This method replaces common words with synonyms based on a secret key. For example, consistently choosing 'large' over 'big' creates a detectable pattern. While resistant to minor edits, the signal disappears in thorough rewrites. The technique requires maintaining natural language flow while embedding the keyed decisions, balancing stealth with detectability.

9Meaning-Level Watermarking

The most advanced method rigs language model sampling during text generation. It biases word selection to create durable, meaning-preserving marks that survive paraphrasing. However, each rewrite weakens the signal. This approach mirrors AI companies' current implementations but requires generation-time access, making it unsuitable for existing text.

10Real-World Testing

Experiments tested watermark survival across 12 channels including social media, email, and CMS platforms. Attacks included light editing, full paraphrasing, and Chinese translation. Results showed Unicode marks failed most edits, word-choice survived 60% of light changes, while meaning-level marks persisted through 40% of paraphrasing. Each method showed distinct vulnerability profiles.

11Threat-Based Selection

Choosing the right watermark depends on expected threats: Unicode marks work against naive copiers, word-choice resists aggregators, meaning-level challenges determined plagiarists. Practical guidance suggests layering methods based on content value and adversary sophistication. High-value documents might combine all three, while blog posts may only need basic protection.

12Ownership vs Detection

While watermarks prove copying, they don't establish ownership - as Genius learned. Effective protection requires combining technical markers with legal rights. Future systems might integrate blockchain timestamps or cryptographic signatures. For now, watermarking remains a powerful but incomplete solution in content attribution's evolving landscape.

Original article: Towards Data Science — How to Watermark Your Text in Python to Detect Copying