KeyedSubstitutionWatermarker<T>
Base Classes · AiDotNet.Safety.Watermarking
Base class for post-hoc text watermarks that rewrite substitution sites to a keyed choice: at every occurrence of a phrase from a group of interchangeable phrases, the key and the preceding word select which member of the group the text uses.
Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → TextSafetyModuleBase<T> → TextWatermarkerBase<T> → KeyedSubstitutionWatermarker<T>
Implements: ITextWatermarkEmbedder<T>
Known derived types: LexicalWatermarker<T>, SyntacticWatermarker<T>
For Beginners
some words and phrases can be swapped without changing the meaning (“big” and “large”, “do not” and “don’t”). The watermark picks one of them at every such place using the secret key. Ordinary text agrees with the key’s choice about half the time; marked text agrees every time.
How It Works
Embedding scans the text left to right. At each site, a phrase from one of the groups, the key and the word before the site (as it reads after any earlier substitution) are hashed with HMAC-SHA256 to choose a member of the group, and the phrase is replaced by that member with its capitalisation kept. Text without sites is unchanged, and embedding twice gives the same text.
Detection finds the same sites and counts how many use the keyed choice. Without the watermark each site matches with probability 1/|group|, so the count gives z = (hits - sum p_i) / sqrt(sum p_i (1 - p_i)). Each (group, preceding word) pair is scored once, so a repeated phrase cannot inflate z. With two-member groups a fully marked text reaches z = sqrt(n) for n distinct sites: 36 sites give z = 6, full confidence.
Every site carries the keyed choice, so watermarkStrength does not change the embedding; it is validated
and kept for the shared watermarker API.
Properties
| Property | Summary |
|---|---|
int GroupCount { get; } |
The number of substitution groups. |
Methods
| Method | Summary |
|---|---|
WatermarkResult Detect(string text) |
|
string EmbedWatermark(string text) |