verascan 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+ cover/
51
+
52
+ # Jupyter Notebook
53
+ .ipynb_checkpoints
54
+
55
+ # Environments
56
+ .env
57
+ .venv
58
+ env/
59
+ venv/
60
+ ENV/
61
+ env.bak/
62
+ venv.bak/
63
+
64
+ # mypy
65
+ .mypy_cache/
66
+ .dmypy.json
67
+ dmypy.json
68
+
69
+ # Ruff
70
+ .ruff_cache/
71
+
72
+ # IDEs and Editors
73
+ .vscode/
74
+ .idea/
75
+ *.swp
76
+ *.swo
77
+ *~
78
+ .DS_Store
79
+
80
+ # User generated outputs & scratch reports
81
+ *.html
82
+ *.json
83
+ !pyproject.toml
84
+ quickstart_report.html
85
+ quickstart_report.json
86
+ report.html
87
+ report.json
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to **Verascan** will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [0.1.0] - 2026-08-22
11
+
12
+ ### Added
13
+ - **Core Detection Engines**:
14
+ - `exact`: Ultra-fast SHA-256 hash-based matching with case and whitespace normalisation.
15
+ - `fuzzy`: Near-duplicate detection using MinHash and Locality-Sensitive Hashing (LSH) via `datasketch`.
16
+ - `semantic`: Embedding-based semantic similarity search with `sentence-transformers` and FAISS vector indexing.
17
+ - **Unified Data Loading**:
18
+ - Direct support for Python `list[str]`, `pandas.DataFrame`, `JSONL`, `CSV`, and HuggingFace `datasets.Dataset`.
19
+ - Custom column selection for tabular and nested datasets.
20
+ - **Reporting & Visualization**:
21
+ - `ContaminationReport` class with query helpers (`flagged()`, `contamination_rate`, method breakdown metrics).
22
+ - Modern, self-contained, responsive HTML reports with interactive filters, search, word-level diffs, and health indicators.
23
+ - Machine-readable JSON export (`to_json()`) and dictionary conversion (`to_dict()`).
24
+ - **Command-Line Interface (CLI)**:
25
+ - `verascan check` command with multi-method selection, threshold configuration, and output path options.
26
+ - `--fail-above` CI gate flag to exit with non-zero status when contamination exceeds acceptable limits.
27
+ - **Quiet & Clean Runtime**:
28
+ - Automatic environment configuration to silence noisy backend C++/oneDNN and framework deprecation warnings.
29
+ - Zero startup latency for core exact/fuzzy operations.
verascan-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Verascan Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,319 @@
1
+ Metadata-Version: 2.5
2
+ Name: verascan
3
+ Version: 0.1.0
4
+ Summary: Detect data contamination between training and evaluation sets — exact, fuzzy, and semantic matching.
5
+ Project-URL: Homepage, https://github.com/balamuruganpg/verascan
6
+ Project-URL: Documentation, https://github.com/balamuruganpg/verascan#readme
7
+ Project-URL: Repository, https://github.com/balamuruganpg/verascan
8
+ Project-URL: Issues, https://github.com/balamuruganpg/verascan/issues
9
+ Author: Verascan Contributors
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: contamination,data-quality,deduplication,evaluation,llm,machine-learning,rag,synthetic-data
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: datasketch>=1.6
27
+ Requires-Dist: jinja2>=3.1
28
+ Requires-Dist: pandas>=1.5
29
+ Requires-Dist: tqdm>=4.60
30
+ Requires-Dist: typer[all]>=0.9
31
+ Provides-Extra: all
32
+ Requires-Dist: datasets>=2.0; extra == 'all'
33
+ Requires-Dist: faiss-cpu>=1.7; extra == 'all'
34
+ Requires-Dist: sentence-transformers>=3.0; extra == 'all'
35
+ Provides-Extra: dev
36
+ Requires-Dist: mypy>=1.5; extra == 'dev'
37
+ Requires-Dist: pandas-stubs; extra == 'dev'
38
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
39
+ Requires-Dist: pytest>=7.0; extra == 'dev'
40
+ Requires-Dist: ruff>=0.4; extra == 'dev'
41
+ Provides-Extra: hf
42
+ Requires-Dist: datasets>=2.0; extra == 'hf'
43
+ Provides-Extra: semantic
44
+ Requires-Dist: faiss-cpu>=1.7; extra == 'semantic'
45
+ Requires-Dist: sentence-transformers>=3.0; extra == 'semantic'
46
+ Description-Content-Type: text/markdown
47
+
48
+ <div align="center">
49
+
50
+ # Verascan
51
+
52
+ **Data Contamination & Leakage Detection for AI / ML Workflows**
53
+
54
+ [![PyPI Version](https://img.shields.io/badge/pypi-v0.1.0-blue.svg)](https://pypi.org/project/verascan/)
55
+ [![Python Versions](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg)](https://pypi.org/project/verascan/)
56
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/balamuruganpg/verascan/blob/main/LICENSE)
57
+ [![Tests](https://img.shields.io/badge/Tests-71%20passed-brightgreen.svg)](https://github.com/balamuruganpg/verascan/actions)
58
+ [![Type Checking](https://img.shields.io/badge/Typing-Strict-blue.svg)](https://mypy-lang.org/)
59
+ [![Code Style](https://img.shields.io/badge/Code%20Style-Ruff-000000.svg)](https://github.com/astral-sh/ruff)
60
+
61
+ <br>
62
+
63
+ <p align="center">
64
+ <strong>Detect exact, fuzzy, and semantic data leakage between training and evaluation datasets.</strong><br>
65
+ Built for LLM fine-tuning, benchmark validation, RAG pipelines, and synthetic data auditing.
66
+ </p>
67
+
68
+ </div>
69
+
70
+ ---
71
+
72
+ ## Overview
73
+
74
+ Data contamination occurs when evaluation or benchmark examples leak into a model's training data. This compromises evaluation validity, inflates benchmark scores, and masks real-world model degradation.
75
+
76
+ **Verascan** provides a multi-tier contamination detection pipeline:
77
+ 1. **Exact match** — $O(N)$ hash-based verbatim duplicate detection with normalisation.
78
+ 2. **Fuzzy match** — MinHash + Locality-Sensitive Hashing (LSH) for near-duplicates and minor edits.
79
+ 3. **Semantic match** — Dense embedding similarity search (`sentence-transformers` + FAISS) for paraphrased content.
80
+
81
+ ---
82
+
83
+ ## Features
84
+
85
+ - **Multi-Tier Detection**: Run exact, fuzzy, and semantic algorithms independently or in a cascaded pipeline.
86
+ - **Cross-Method Deduplication**: Matches identified by exact hashing are automatically excluded from fuzzy/semantic passes to prevent double-counting.
87
+ - **Multi-Format Ingestion**: Natively accepts `pandas.DataFrame`, `JSONL`, `CSV`, Hugging Face `datasets.Dataset`, and Python `list[str]`.
88
+ - **Interactive HTML Reports**: Generates self-contained, offline-ready HTML reports featuring search, method filtering, and word-level diffs.
89
+ - **CI/CD Integration**: CLI includes `--fail-above` to fail builds if contamination exceeds an allowed threshold.
90
+ - **Lightweight Core**: Installs cleanly with minimal dependencies; heavy ML dependencies (`sentence-transformers`, `faiss-cpu`) are optional extras.
91
+ - **Noise-Free Execution**: Built-in log suppression prevents noisy C++/oneDNN and framework deprecation logs from polluting `stderr`.
92
+
93
+ ---
94
+
95
+ ## Detection Engines
96
+
97
+ | Method | Algorithm | Complexity / Speed | Best For |
98
+ |---|---|---|---|
99
+ | **`exact`** | SHA-256 Content Hashing (normalised) | $O(N + M)$ &bull; *Microseconds* | Verbatim duplicates, casing/whitespace variations |
100
+ | **`fuzzy`** | MinHash + LSH (`datasketch`) | $O(N + M)$ &bull; *Milliseconds* | Minor edits, word insertions/deletions, truncations |
101
+ | **`semantic`** | Dense Vector Cosine Similarity (FAISS) | $O(M \cdot d)$ &bull; *Seconds* | Paraphrased sentences, reworded questions, synonyms |
102
+
103
+ ---
104
+
105
+ ## Installation
106
+
107
+ ```bash
108
+ # Core installation (exact + fuzzy matching)
109
+ pip install verascan
110
+
111
+ # With semantic similarity matching (sentence-transformers + FAISS)
112
+ pip install "verascan[semantic]"
113
+
114
+ # With Hugging Face datasets support
115
+ pip install "verascan[hf]"
116
+
117
+ # Complete installation with all optional extras
118
+ pip install "verascan[all]"
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Quickstart
124
+
125
+ ### Python API
126
+
127
+ ```python
128
+ import verascan
129
+
130
+ # Run contamination audit across training and evaluation splits
131
+ report = verascan.check(
132
+ train="data/train.jsonl",
133
+ eval="data/eval.jsonl",
134
+ methods=["exact", "fuzzy"],
135
+ threshold=0.85,
136
+ )
137
+
138
+ # Print terminal summary
139
+ report.summary()
140
+
141
+ # Inspect metrics
142
+ print(f"Contamination Rate: {report.contamination_rate:.1%}")
143
+ print(f"Flagged Pairs : {report.total_matches}")
144
+
145
+ # Query high-confidence matches
146
+ for match in report.flagged(min_score=0.90):
147
+ print(
148
+ f"[{match.method}] Eval #{match.eval_index} <-> Train #{match.train_index} (Score: {match.score:.3f})"
149
+ )
150
+ print(f" Eval : {match.eval_text}")
151
+ print(f" Train: {match.train_text}")
152
+
153
+ # Export reports
154
+ report.to_html("contamination_report.html")
155
+ report.to_json("contamination_report.json")
156
+ ```
157
+
158
+ ### Terminal Output
159
+
160
+ ```text
161
+ ===============================================
162
+ Verascan Contamination Report
163
+ ===============================================
164
+ Train size : 50,000
165
+ Eval size : 1,000
166
+ Methods : exact, fuzzy
167
+ Threshold : 0.85
168
+ -----------------------------------------------
169
+ Total matches : 14
170
+ Contaminated : 12 / 1,000 eval samples (1.2%)
171
+ Exact matches : 4
172
+ Fuzzy matches : 10
173
+ ===============================================
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Supported Input Formats
179
+
180
+ Verascan normalises inputs into clean text sequences automatically:
181
+
182
+ ```python
183
+ import pandas as pd
184
+ import verascan
185
+
186
+ # 1. Plain String Lists
187
+ report = verascan.check(
188
+ train=["The quick brown fox.", "Artificial intelligence."],
189
+ eval=["The quick brown fox."],
190
+ )
191
+
192
+ # 2. File Paths (CSV or JSONL)
193
+ report = verascan.check(
194
+ train="data/train.jsonl",
195
+ eval="data/eval.csv",
196
+ column="text",
197
+ )
198
+
199
+ # 3. Pandas DataFrames
200
+ train_df = pd.DataFrame({"prompt": ["Translate to French...", "Summarize..."]})
201
+ eval_df = pd.DataFrame({"prompt": ["Translate to French..."]})
202
+ report = verascan.check(train=train_df, eval=eval_df, column="prompt")
203
+
204
+ # 4. Hugging Face Datasets
205
+ from datasets import load_dataset
206
+
207
+ train_ds = load_dataset("imdb", split="train")
208
+ eval_ds = load_dataset("imdb", split="test")
209
+ report = verascan.check(train=train_ds, eval=eval_ds, column="text")
210
+ ```
211
+
212
+ ---
213
+
214
+ ## CLI Usage
215
+
216
+ The `verascan` command-line interface enables automated checks in terminal workflows and CI/CD pipelines:
217
+
218
+ ```bash
219
+ # Basic contamination check
220
+ verascan check --train train.jsonl --eval eval.jsonl
221
+
222
+ # Specify custom column, methods, and threshold
223
+ verascan check \
224
+ --train data/train.csv \
225
+ --eval data/eval.csv \
226
+ --methods exact,fuzzy \
227
+ --threshold 0.80 \
228
+ --column instruction \
229
+ --output report.html
230
+
231
+ # CI/CD Gate: Fail build if contamination rate exceeds 1%
232
+ verascan check \
233
+ --train train.jsonl \
234
+ --eval eval.jsonl \
235
+ --fail-above 0.01
236
+ ```
237
+
238
+ ---
239
+
240
+ ## Interactive HTML Reports
241
+
242
+ The HTML report generated via `report.to_html("report.html")` is **100% self-contained** (no external fonts, CDNs, or scripts required):
243
+
244
+ - **Health Status Banner**: Visual indicator (`Clean`, `Low Risk`, `High Risk`) with contamination percentage and progress meter.
245
+ - **Method Breakdown**: Color-coded badges for exact (Rose), fuzzy (Amber), and semantic (Indigo) detections.
246
+ - **Live Search & Filtering**: Instant client-side search across text samples and index numbers.
247
+ - **Word-Level Diffs**: Color-coded `<del>` and `<ins>` tags illustrating textual overlap.
248
+ - **Responsive Layout**: Designed for seamless viewing across desktop monitors and mobile devices.
249
+
250
+ ---
251
+
252
+ ## ContaminationReport API
253
+
254
+ ```python
255
+ report = verascan.check(train, eval)
256
+
257
+ # Properties
258
+ report.contamination_rate # float: Fraction of eval examples found in train (0.0 to 1.0)
259
+ report.total_matches # int: Total flagged pairs
260
+ report.exact_count # int: Exact duplicate count
261
+ report.fuzzy_count # int: Fuzzy / near-duplicate count
262
+ report.semantic_count # int: Semantic match count
263
+ report.train_size # int: Size of training corpus
264
+ report.eval_size # int: Size of evaluation corpus
265
+
266
+ # Methods
267
+ report.flagged(min_score=0.9) # Returns list of MatchRecord objects >= min_score
268
+ report.summary() # Prints ASCII summary to stdout
269
+ report.to_dict() # Serialises report to a Python dict
270
+ report.to_json("report.json") # Exports JSON file
271
+ report.to_html("report.html") # Exports self-contained interactive HTML report
272
+ ```
273
+
274
+ ### `MatchRecord` Structure
275
+
276
+ Each match in `report.matches` contains:
277
+ - `eval_index: int` — Index of the sample in the evaluation dataset.
278
+ - `train_index: int` — Index of the sample in the training dataset.
279
+ - `eval_text: str` — Evaluation sample text.
280
+ - `train_text: str` — Matching training sample text.
281
+ - `score: float` — Similarity metric (`1.0` for exact matches, Jaccard for fuzzy, cosine for semantic).
282
+ - `method: str` — Engine that produced the match (`"exact"`, `"fuzzy"`, `"semantic"`).
283
+
284
+ ---
285
+
286
+ ## Limitations
287
+
288
+ - **Large-Scale Semantic Search**: While FAISS provides fast approximate search, semantic matching encodes all samples using transformer models, which is compute-intensive on CPU for corpora with millions of rows. For very large datasets, start with `methods=["exact", "fuzzy"]`.
289
+ - **Character N-Gram Sensitivity**: Fuzzy matching relies on character 5-grams by default. Very short texts (fewer than 5 characters) fall back to exact matching.
290
+ - **Cross-Lingual Matching**: The default semantic model (`all-MiniLM-L6-v2`) is optimized for English text. For multilingual evaluation datasets, specify a multilingual model via `model_name="paraphrase-multilingual-MiniLM-L12-v2"`.
291
+
292
+ ---
293
+
294
+ ## Development
295
+
296
+ ```bash
297
+ # Clone repository
298
+ git clone https://github.com/balamuruganpg/verascan.git
299
+ cd verascan
300
+
301
+ # Install development dependencies
302
+ pip install -e ".[all,dev]"
303
+
304
+ # Run test suite
305
+ pytest
306
+
307
+ # Code formatting and linting
308
+ ruff check .
309
+ ruff format --check .
310
+
311
+ # Type checking
312
+ mypy src/
313
+ ```
314
+
315
+ ---
316
+
317
+ ## License
318
+
319
+ Distributed under the [MIT License](https://github.com/balamuruganpg/verascan/blob/main/LICENSE).