TextWatermarker<T>

Models & Types · AiDotNet.Safety.Watermarking

The safety pipeline’s text watermarker: the green-list watermark of SamplingWatermarker (Kirchenbauer et al. 2023) with a z-score reporting threshold.

Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → TextSafetyModuleBase<T> → TextWatermarkerBase<T> → SamplingWatermarker<T> → TextWatermarker<T>

For Beginners

Text watermarking works by subtly biasing which words the AI chooses. When generating text, the system slightly prefers words from a secret list that changes at every position. Later, the system can check whether a piece of text came from it by counting how many listed words appear.

How It Works

Embed by wrapping the generating model with WatermarkModel (or calling BiasLogits in your decode loop); detect with EvaluateText, which re-tokenizes the text with the generator’s tokenizer and reports a finding when the green-token z-score reaches detectionThreshold.

The watermark is derived from the key, never from a random value: two instances built with the same key and settings embed and detect the same mark. Without a key the published Public key is used, whose marks anyone can forge; mark your own text with a secret key.

References:

  • Kirchenbauer et al., A Watermark for Large Language Models (ICML 2023, arxiv:2301.10226)

Constructors

Constructor Summary
TextWatermarker(string key, double greenListFraction, double detectionThreshold, int contextWidth, IGenerationTokenizer tokenizer, double watermarkStrength) Initializes a new text watermarker.

Properties

Property Summary
string ModuleName { get; }