datacruxai 0.3.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.
Files changed (41) hide show
  1. datacruxai-0.3.0/.github/workflows/ci.yml +38 -0
  2. datacruxai-0.3.0/.gitignore +22 -0
  3. datacruxai-0.3.0/CHANGELOG.md +25 -0
  4. datacruxai-0.3.0/LICENSE +177 -0
  5. datacruxai-0.3.0/PKG-INFO +332 -0
  6. datacruxai-0.3.0/README.md +290 -0
  7. datacruxai-0.3.0/assets/contamination.svg +123 -0
  8. datacruxai-0.3.0/assets/quality_report.svg +130 -0
  9. datacruxai-0.3.0/examples/hub_download.py +54 -0
  10. datacruxai-0.3.0/examples/language_filter.py +62 -0
  11. datacruxai-0.3.0/examples/pipeline_with_castwright.py +88 -0
  12. datacruxai-0.3.0/examples/scan_dataset.py +70 -0
  13. datacruxai-0.3.0/pyproject.toml +75 -0
  14. datacruxai-0.3.0/scripts/generate_assets.py +73 -0
  15. datacruxai-0.3.0/src/datacruxai/__init__.py +117 -0
  16. datacruxai-0.3.0/src/datacruxai/_types.py +112 -0
  17. datacruxai-0.3.0/src/datacruxai/augment.py +148 -0
  18. datacruxai-0.3.0/src/datacruxai/cli.py +156 -0
  19. datacruxai-0.3.0/src/datacruxai/contamination.py +200 -0
  20. datacruxai-0.3.0/src/datacruxai/dedup.py +197 -0
  21. datacruxai-0.3.0/src/datacruxai/formats.py +223 -0
  22. datacruxai-0.3.0/src/datacruxai/hub.py +169 -0
  23. datacruxai-0.3.0/src/datacruxai/language.py +229 -0
  24. datacruxai-0.3.0/src/datacruxai/pii.py +275 -0
  25. datacruxai-0.3.0/src/datacruxai/py.typed +0 -0
  26. datacruxai-0.3.0/src/datacruxai/quality.py +243 -0
  27. datacruxai-0.3.0/src/datacruxai/schema.py +277 -0
  28. datacruxai-0.3.0/src/datacruxai/stats.py +103 -0
  29. datacruxai-0.3.0/tests/__init__.py +0 -0
  30. datacruxai-0.3.0/tests/conftest.py +84 -0
  31. datacruxai-0.3.0/tests/test_augment.py +179 -0
  32. datacruxai-0.3.0/tests/test_contamination.py +115 -0
  33. datacruxai-0.3.0/tests/test_dedup.py +88 -0
  34. datacruxai-0.3.0/tests/test_formats.py +171 -0
  35. datacruxai-0.3.0/tests/test_hub.py +292 -0
  36. datacruxai-0.3.0/tests/test_language.py +188 -0
  37. datacruxai-0.3.0/tests/test_pii.py +129 -0
  38. datacruxai-0.3.0/tests/test_pii_intl.py +215 -0
  39. datacruxai-0.3.0/tests/test_quality.py +127 -0
  40. datacruxai-0.3.0/tests/test_schema.py +206 -0
  41. datacruxai-0.3.0/tests/test_stats.py +75 -0
@@ -0,0 +1,38 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+
28
+ - name: Install dependencies
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ pip install -e ".[all]"
32
+ pip install pytest ruff
33
+
34
+ - name: Lint with ruff
35
+ run: ruff check src/ tests/
36
+
37
+ - name: Run tests
38
+ run: pytest tests/ -v --tb=short
@@ -0,0 +1,22 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ *.egg
6
+ dist/
7
+ build/
8
+ .eggs/
9
+ *.so
10
+ .venv/
11
+ venv/
12
+ env/
13
+ .env
14
+ .mypy_cache/
15
+ .pytest_cache/
16
+ .ruff_cache/
17
+ htmlcov/
18
+ .coverage
19
+ coverage.xml
20
+ *.log
21
+ .DS_Store
22
+ Thumbs.db
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2025-04-10
9
+
10
+ ### Added
11
+ - Add data augmentation module in `augment.py`
12
+ - Add dataset schema validation via `schema.py`
13
+
14
+ ## [0.2.0] - 2026-04-10
15
+
16
+ ### Added
17
+ - Add HuggingFace datasets hub integration
18
+ - Add language detection for multilingual datasets
19
+ - Add international PII patterns
20
+
21
+ ## [0.1.0] - 2026-04-10
22
+
23
+ ### Added
24
+ - Initial release: CPU-only data quality toolkit for LLM instruction tuning
25
+
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,332 @@
1
+ Metadata-Version: 2.4
2
+ Name: datacruxai
3
+ Version: 0.3.0
4
+ Summary: Lightweight data quality toolkit for LLM instruction tuning. Deduplication, PII detection, contamination checking, and quality scoring — no GPU required.
5
+ Project-URL: Homepage, https://github.com/stef41/datacruxai
6
+ Project-URL: Repository, https://github.com/stef41/datacruxai
7
+ Project-URL: Issues, https://github.com/stef41/datacruxai/issues
8
+ Author: Zacharie B
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: contamination,data-quality,deduplication,fine-tuning,instruction-tuning,llm,pii,rlhf,sft,training-data
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: xxhash>=3.0
26
+ Provides-Extra: all
27
+ Requires-Dist: click>=8.0; extra == 'all'
28
+ Requires-Dist: datasketch>=1.6; extra == 'all'
29
+ Requires-Dist: pyarrow>=12.0; extra == 'all'
30
+ Requires-Dist: rich>=13.0; extra == 'all'
31
+ Provides-Extra: cli
32
+ Requires-Dist: click>=8.0; extra == 'cli'
33
+ Requires-Dist: rich>=13.0; extra == 'cli'
34
+ Provides-Extra: formats
35
+ Requires-Dist: pyarrow>=12.0; extra == 'formats'
36
+ Provides-Extra: fuzzy
37
+ Requires-Dist: datasketch>=1.6; extra == 'fuzzy'
38
+ Provides-Extra: semantic
39
+ Requires-Dist: numpy>=1.21; extra == 'semantic'
40
+ Requires-Dist: sentence-transformers>=2.0; extra == 'semantic'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # datacruxai
44
+
45
+ [![CI](https://github.com/stef41/datacruxaiai/actions/workflows/ci.yml/badge.svg)](https://github.com/stef41/datacruxaiai/actions/workflows/ci.yml)
46
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
47
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
48
+
49
+ **Data quality toolkit for LLM instruction tuning.**
50
+
51
+ Clean your training data before fine-tuning. No GPU needed.
52
+
53
+ <p align="center">
54
+ <img src="assets/quality_report.svg" width="720" alt="datacruxai quality report" />
55
+ </p>
56
+
57
+ ```python
58
+ from datacruxai import load_dataset, exact_dedup, scan_examples, score_dataset
59
+
60
+ # Load any instruction-tuning dataset
61
+ examples = load_dataset("training_data.jsonl")
62
+
63
+ # Remove exact duplicates
64
+ result = exact_dedup(examples)
65
+ print(f"Removed {result.n_duplicates} duplicates")
66
+
67
+ # Scan for PII
68
+ pii_results = scan_examples(result.originals)
69
+ print(f"Found PII in {len(pii_results)} examples")
70
+
71
+ # Score quality
72
+ scores = score_dataset(result.originals, min_score=0.5)
73
+ print(f"{len(scores)} low-quality examples flagged")
74
+ ```
75
+
76
+ ## Why datacruxai?
77
+
78
+ If you're fine-tuning an LLM, your training data quality matters more than quantity. Garbage in, garbage out — except now garbage costs you GPU hours and makes your model worse.
79
+
80
+ Existing options are either overkill (NeMo Curator needs NVIDIA GPUs and processes terabytes of web crawl data) or too narrow (scattered scripts in random repos). datacruxai fills the gap: a single `pip install` that gives you everything needed to validate and clean instruction-tuning datasets on a laptop.
81
+
82
+ **What it does:**
83
+
84
+ - **Deduplication** — exact (hash-based) and near-duplicate (MinHash + LSH) detection
85
+ - **PII detection** — regex-based scanning for emails, phones, SSNs, credit cards, IPs
86
+ - **PII redaction** — replace detected PII with placeholders
87
+ - **Benchmark contamination** — n-gram overlap checking against MMLU, GSM8K, HellaSwag, ARC, TruthfulQA, WinoGrande
88
+ - **Quality scoring** — heuristic checks for instruction quality, response completeness, repetition, formatting
89
+ - **Format support** — Alpaca, ShareGPT, OpenAI chat format; JSONL, JSON, Parquet
90
+ - **Dataset statistics** — length distributions, token estimates, field coverage
91
+
92
+ Everything runs on CPU. Everything is deterministic. No API keys, no signups, no cloud dependencies.
93
+
94
+ ## Install
95
+
96
+ ```bash
97
+ pip install datacruxai
98
+ ```
99
+
100
+ With fuzzy deduplication (MinHash + LSH):
101
+
102
+ ```bash
103
+ pip install datacruxai[fuzzy]
104
+ ```
105
+
106
+ With Parquet support:
107
+
108
+ ```bash
109
+ pip install datacruxai[formats]
110
+ ```
111
+
112
+ Everything:
113
+
114
+ ```bash
115
+ pip install datacruxai[all]
116
+ ```
117
+
118
+ ## Usage
119
+
120
+ ### Load data
121
+
122
+ datacruxai auto-detects Alpaca, ShareGPT, and OpenAI chat formats.
123
+
124
+ ```python
125
+ from datacruxai import load_dataset, detect_format
126
+
127
+ examples = load_dataset("training_data.jsonl") # JSONL, JSON, or Parquet
128
+ print(f"Loaded {len(examples)} examples")
129
+ print(f"Format: {detect_format(examples[0].raw)}")
130
+ ```
131
+
132
+ ### Deduplicate
133
+
134
+ ```python
135
+ from datacruxai import exact_dedup, fuzzy_dedup, dedup
136
+
137
+ # Fast exact dedup (hash-based)
138
+ result = exact_dedup(examples)
139
+ print(f"{result.n_total} → {result.n_unique} (removed {result.n_duplicates})")
140
+
141
+ # Near-duplicate detection (requires datacruxai[fuzzy])
142
+ result = fuzzy_dedup(examples, threshold=0.8)
143
+
144
+ # Combined: exact first, then fuzzy on the remainder
145
+ result = dedup(examples, exact=True, fuzzy=True, fuzzy_threshold=0.8)
146
+ clean_examples = result.originals
147
+ ```
148
+
149
+ ### Detect PII
150
+
151
+ ```python
152
+ from datacruxai import scan_text, scan_examples, redact_text, redact_examples
153
+
154
+ # Scan a single string
155
+ entities = scan_text("Email me at john@example.com or call 555-0123")
156
+ for e in entities:
157
+ print(f" {e.kind}: '{e.text}' at [{e.start}:{e.end}]")
158
+
159
+ # Scan an entire dataset
160
+ pii_results = scan_examples(examples)
161
+ for r in pii_results:
162
+ print(f" Example {r.example_index}: {[e.kind for e in r.entities]}")
163
+
164
+ # Redact PII
165
+ safe = redact_text("SSN: 123-45-6789")
166
+ # "SSN: [SSN]"
167
+
168
+ safe_examples = redact_examples(examples)
169
+ ```
170
+
171
+ ### Check benchmark contamination
172
+
173
+ ```python
174
+ from datacruxai import check_contamination, list_benchmarks
175
+
176
+ # Built-in benchmarks
177
+ print(list_benchmarks())
178
+ # ['arc', 'gsm8k', 'hellaswag', 'mmlu', 'truthfulqa', 'winogrande']
179
+
180
+ report = check_contamination(examples, ngram_size=8)
181
+ print(f"Flagged {report.total_flagged} / {report.total_checked} examples")
182
+ for bench, count in report.by_benchmark.items():
183
+ print(f" {bench}: {count} matches")
184
+
185
+ # Custom benchmark dataset
186
+ custom = {"my_eval": ["question one text", "question two text"]}
187
+ report = check_contamination(examples, benchmarks=custom, ngram_size=5)
188
+ ```
189
+
190
+ ### Score quality
191
+
192
+ ```python
193
+ from datacruxai import score_example, score_dataset, filter_by_quality
194
+
195
+ # Score a single example
196
+ score = score_example(examples[0])
197
+ print(f"Overall: {score.overall:.2f}")
198
+ print(f"Details: {score.details}")
199
+ print(f"Flags: {score.flags}")
200
+
201
+ # Flag low-quality examples
202
+ low_quality = score_dataset(examples, min_score=0.5)
203
+ for s in low_quality:
204
+ print(f" [{s.example_index}] {s.overall:.2f} — {s.flags}")
205
+
206
+ # Filter and keep only good examples
207
+ clean = filter_by_quality(examples, min_score=0.5)
208
+ print(f"Kept {len(clean)} / {len(examples)}")
209
+ ```
210
+
211
+ ### Dataset statistics
212
+
213
+ ```python
214
+ from datacruxai import compute_stats, length_distribution
215
+
216
+ stats = compute_stats(examples)
217
+ print(f"Examples: {stats['n_examples']}")
218
+ print(f"Token estimate: ~{stats['token_estimate']:,}")
219
+ print(f"Empty outputs: {stats['empty_outputs']}")
220
+ print(f"Avg instruction length: {stats['instruction_lengths']['mean']:.0f} chars")
221
+
222
+ # Length histogram
223
+ hist = length_distribution(examples, field="output", bins=10)
224
+ for bucket in hist:
225
+ print(f" {bucket['range']}: {'█' * bucket['count']}")
226
+ ```
227
+
228
+ ### Save results
229
+
230
+ ```python
231
+ from datacruxai import save_jsonl
232
+
233
+ save_jsonl(clean_examples, "cleaned_training_data.jsonl")
234
+ ```
235
+
236
+ ## CLI
237
+
238
+ ```bash
239
+ # Dataset statistics
240
+ datacruxai stats training_data.jsonl
241
+
242
+ # Deduplicate
243
+ datacruxai dedup training_data.jsonl -o deduped.jsonl
244
+
245
+ # Fuzzy dedup
246
+ datacruxai dedup training_data.jsonl --fuzzy -t 0.8 -o deduped.jsonl
247
+
248
+ # PII scan
249
+ datacruxai pii training_data.jsonl
250
+
251
+ # PII redact and save
252
+ datacruxai pii training_data.jsonl -o redacted.jsonl
253
+
254
+ # Contamination check
255
+ datacruxai contamination training_data.jsonl -n 8
256
+
257
+ # Quality scoring
258
+ datacruxai quality training_data.jsonl -t 0.5 -o filtered.jsonl
259
+ ```
260
+
261
+ ## Quality Checks
262
+
263
+ The quality scorer applies these deterministic heuristics:
264
+
265
+ | Check | Weight | What it catches |
266
+ |-------|--------|-----------------|
267
+ | Instruction quality | 25% | Empty, trivial, or all-caps instructions |
268
+ | Response completeness | 30% | Empty, trivial, or refusal-only responses |
269
+ | Length | 15% | Extremely short or long examples |
270
+ | Repetition | 20% | Repeated words, repeated n-grams |
271
+ | Language | 10% | Excessive special characters, whitespace |
272
+
273
+ Scores range from 0.0 (terrible) to 1.0 (clean). The default threshold of 0.5 catches the obvious problems without being overly aggressive.
274
+
275
+ ## Supported Formats
276
+
277
+ | Format | Auto-detected | Key fields |
278
+ |--------|--------------|------------|
279
+ | Alpaca | `instruction`, `input`, `output` | Standard fine-tuning format |
280
+ | ShareGPT | `conversations` | Multi-turn with `from`/`value` |
281
+ | OpenAI chat | `messages` | `role`/`content` pairs |
282
+
283
+ File types: `.jsonl`, `.json`, `.parquet` (with `datacruxai[formats]`)
284
+
285
+ ## Performance
286
+
287
+ Everything is single-threaded and CPU-only by design. On a typical laptop:
288
+
289
+ - **Exact dedup**: ~100k examples/sec
290
+ - **PII scan**: ~50k examples/sec
291
+ - **Quality scoring**: ~80k examples/sec
292
+ - **Contamination check**: depends on n-gram size, ~10k examples/sec for n=8
293
+
294
+ For datasets under 1M examples, everything runs in seconds to minutes. If you're working with larger datasets, consider NeMo Curator (but you'll need GPUs).
295
+
296
+ ## Contributing
297
+
298
+ PRs welcome — especially:
299
+ - Additional PII patterns (non-US phone formats, EU identifiers)
300
+ - More benchmark fingerprints
301
+ - New quality heuristics
302
+ - Performance improvements
303
+
304
+ ```bash
305
+ git clone https://github.com/zbhatti/datacruxai.git
306
+ cd datacruxai
307
+ pip install -e ".[all]"
308
+ pip install pytest ruff
309
+ pytest
310
+ ```
311
+
312
+ ## See Also
313
+
314
+ Part of the **stef41 LLM toolkit** — open-source tools for every stage of the LLM lifecycle:
315
+
316
+ | Project | What it does |
317
+ |---------|-------------|
318
+ | [tokonomics](https://github.com/stef41/tokonomix) | Token counting & cost management for LLM APIs |
319
+ | [castwright](https://github.com/stef41/castwright) | Synthetic instruction data generation |
320
+ | [datamix](https://github.com/stef41/datamix) | Dataset mixing & curriculum optimization |
321
+ | [toksight](https://github.com/stef41/toksight) | Tokenizer analysis & comparison |
322
+ | [trainpulse](https://github.com/stef41/trainpulse) | Training health monitoring |
323
+ | [ckpt](https://github.com/stef41/ckptkit) | Checkpoint inspection, diffing & merging |
324
+ | [quantbench](https://github.com/stef41/quantbenchx) | Quantization quality analysis |
325
+ | [infermark](https://github.com/stef41/infermark) | Inference benchmarking |
326
+ | [modeldiff](https://github.com/stef41/modeldiffx) | Behavioral regression testing |
327
+ | [vibesafe](https://github.com/stef41/vibesafex) | AI-generated code safety scanner |
328
+ | [injectionguard](https://github.com/stef41/injectionguard) | Prompt injection detection |
329
+
330
+ ## License
331
+
332
+ Apache 2.0