noleak
Content-addressed dataset IDs and train/eval leakage checks for AI/ML.
Published numbers are only as honest as the split behind them. noleak gives every corpus a stable fingerprint (like a Docker image ID) and measures how much of your eval set already appeared in train — exact copies, GPT-3-style word n-grams, and MinHash near-duplicates.
Zero runtime dependencies. Stdlib only.
from noleak import check, fingerprint
train = ["the model was trained on Wikipedia dumps and licensed books"]
eval_set = ["The model was trained on Wikipedia dumps and licensed books"]
print(fingerprint(eval_set))
# noleak-fp-v1:a1b2c3d4e5f6
report = check(train, eval_set)
print(report)
# exact 1/1 (100.00%) status FAIL
Why this library
Influential AIML libraries are usually one primitive done well (einops, safetensors, tqdm). The primitive here:
- Identity — an order-independent hash of unique normalized examples, so a paper can write
eval id noleak-fp-v1:…and a reviewer can recompute it. - Leakage — exact overlap, 13-gram contamination (Brown et al., GPT-3), and character-shingle MinHash for paraphrases.
This does not replace scikit-learn Pipeline leakage tools such as splitguard (runtime fit() hooks). It answers a different question: did this text eval set leak from the train corpus?
Install
pip install noleak
Requires Python 3.10+. No extra packages.
For local development from this repo:
python3 -m pip install -e ".[dev]"
API
from noleak import check, exact_overlap, fingerprint, near_duplicates, ngram_overlap
fp = fingerprint(eval_texts) # Fingerprint
report = check(train_texts, eval_texts) # CheckReport
report.contaminated # bool (CI-friendly)
report.to_dict() # JSON-serializable
exact_overlap(train, eval_set) # identical after normalize
ngram_overlap(train, eval_set, n=13) # shared word n-grams
near_duplicates(train, threshold=0.8) # pairs inside one corpus
Records may be strings or dicts. Dicts use the first present of text, content, prompt, question, input, output.
CLI
noleak fingerprint eval.jsonl
noleak check --train train.jsonl --eval eval.jsonl
noleak check --train train.jsonl --eval eval.jsonl --json
echo $? # 1 if contaminated, 0 if clean
JSONL, JSON lists, and plain text (one example per line) are supported. Use --field name when objects store the example under a custom key.
Fingerprint scheme (noleak-fp-v1)
- Normalize each example (
noleak-norm-v1): Unicode NFKC, strip, collapse whitespace, casefold. - SHA-256 the UTF-8 bytes of that string.
- Sort unique example hashes.
- SHA-256
noleak-fp-v1\nplus those hashes, one per line.
Row order and duplicate rows do not change the digest; n_examples vs n_unique still records multiplicity.
Leakage methods
| Method | Detects | Default gate |
|---|---|---|
exact |
Same text after normalization | any hit fails |
ngram |
Shared word n-gram (default n=13) | rate ≥ 1% fails |
near |
MinHash Jaccard ≥ 0.8 on char 5-grams | rate ≥ 5% fails |
Short eval lines (fewer than n tokens) are hashed as a single gram so they are not skipped.
What this will not do
- Catch target leakage (a feature derived from the label).
- Catch preprocessing fitted on the full matrix (use a
Pipelineor a runtime hook). - Prove a model never saw an eval item during pretraining of a closed corpus you cannot hash.
- Replace embedding-based semantic dedup (
sentence-transformers). MinHash is deterministic and model-free; that is the point.
Development
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -e ".[dev]"
pytest
python -m build
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file noleak-0.1.0.tar.gz.
File metadata
- Download URL: noleak-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2804f2ffbc88fad9f5edccb7ee1a099448dde5a04701eadc27c28e48fc9eea97
|
|
| MD5 |
34817b368a3ba81b59ba762d77455858
|
|
| BLAKE2b-256 |
70cd8f2ef852a4c38af4811e14d5593c4dc796b2a3f75f0ce4daefcaa15cd4fd
|
File details
Details for the file noleak-0.1.0-py3-none-any.whl.
File metadata
- Download URL: noleak-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dcf7d5778d8f0acc9a03bb04830bf9e6764df813e18386f4d7e0ac53606e973
|
|
| MD5 |
2028b8a92445535382145ae5906927e4
|
|
| BLAKE2b-256 |
216a2fd55fcd2d6714dd7ea305459b4d024b4c7a60e43fba9030f5033b1ad4f9
|