PerplexityMemorizationDetector<T>
Models & Types · AiDotNet.Safety.Text
Detects potential training data memorization by estimating text perplexity. Low perplexity (highly predictable) text may indicate verbatim memorized content.
Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → TextSafetyModuleBase<T> → PerplexityMemorizationDetector<T>
For Beginners
If an AI can predict every next word perfectly, it’s probably reciting something it memorized during training. Normal text has some unpredictability. This module measures how predictable the text is — too predictable means it might be a memorized passage from training data.
How It Works
Memorized training data typically has unusually low perplexity — the model is very “confident” about every next token because it has seen the exact sequence before. This detector computes a lightweight character-level perplexity proxy using n-gram statistics and flags outputs that are suspiciously predictable compared to natural text.
Detection approach:
- Build character-level n-gram frequency table from the text itself
- Compute conditional entropy at each position using n-gram context
- Average entropy = proxy for perplexity
- Very low entropy indicates memorized/formulaic text
- Additional checks: token repetition patterns, entropy variance
References:
- Detecting pre-training data via perplexity comparison (Carlini et al., 2023)
- Min-K%/Min-K%++ membership inference (2024, arxiv:2404.02936)
- BookMIA: Book-level membership inference (2024, arxiv:2401.15588)
- Scalable extraction of training data from LLMs (2023, arxiv:2311.17035)
Constructors
| Constructor | Summary |
|---|---|
PerplexityMemorizationDetector(double lowPerplexityThreshold, double highRepetitionThreshold, int ngramOrder) |
Initializes a new perplexity-based memorization detector. |
Properties
| Property | Summary |
|---|---|
string ModuleName { get; } |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<SafetyFinding> EvaluateText(string text) |