This project explores watermarking for language model outputs by building on Andrej Karpathy's microgpt. It introduces a method for generating watermarked text that remains statistically detectable without altering the underlying probabilities. The implementation is minimal, relying solely on Python's standard library.
The gpt-watermark project is a cutting-edge experiment in watermarking generated text, developed on the foundation of Andrej Karpathy's minimal microgpt. This innovative approach demonstrates how a secret-keyed sampler can create a statistically detectable watermark within the text, without altering the model's inherent token probabilities.
In the realm of large language models (LLMs), text generation involves sampling the next token based on a probability distribution. There are two modes of generation:
GPT → probabilities → random sampling → next tokenGPT → same probabilities → keyed Gumbel sampling → next tokenThe watermark does not manifest itself as a visible marker in the text. Instead, it emerges statistically through numerous token selections and can be detected with the corresponding secret key.
To experiment with the watermarking functionality, clone the repository and run the script:
git clone https://github.com/berba-q/gpt-watermark
cd gpt-watermark
python3 microgpt_watermark.py
Both text generation methods yield outputs that appear equally natural:
Normal samples: | Watermarked samples:
--------------------|--------------------
yuh | yuha | yuhan
xav | xavinn | xavia
jua | juan | juale
However, when subjected to detection, the watermark's significance is evident:
Normal n=308 mean=0.962 p=7.459e-01
Watermarked n=322 mean=2.105 p=6.844e-53
Wrong key n=322 mean=0.984 p=6.094e-01
The watermarked text produces a p-value of approximately ~6.8×10⁻⁵³, demonstrating a significant difference from ordinary text, which scores around p≈0.6-0.75, indistinguishable from random chance.
For a comprehensive explanation, refer to Watermarking a tiny GPT: 91 lines, NO Frameworks.
This project exists thanks to the foundational work of Andrej Karpathy's microgpt and is inspired by Scott Aaronson's research on keyed Gumbel sampling for LLM output watermarking.
No comments yet.
Sign in to be the first to comment.