File size: 13,310 Bytes
b58f293 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | # Final Report — K-12 Math & Coding Dataset
A 1B+ token, K-12-focused math corpus and a 1B+ token educational coding
corpus, built per `pipeline.md`'s 6-phase spec. Both categories comfortably
exceed the 1B-token target after cleaning, deduplication, quality filtering,
and budget-controlled final sampling.
## 1. Total tokens per category (final deliverable)
| Category | Final Tokens | Final Rows | Target | Margin |
|----------|-------------:|-----------:|-------:|-------:|
| Math | 1,004,991,667 | 676,018 | 1,000,000,000 | +0.5% |
| Code | 1,020,505,114 | 937,248 | 1,000,000,000 | +2.1% |
Deliverables: `data/final/math/final.jsonl`, `data/final/code/final.jsonl`.
Schema per record: `{text, source, category, quality_score, token_count,
language, metadata}`. `quality_score` is populated only for finemath4plus
(the one source with an upstream classifier score) — `null` elsewhere, since
no equivalent score exists for structured benchmarks or code sources.
`language` is the natural-language code (`"en"` throughout, all sources
verified predominantly English); for code sources the programming language
is preserved under `metadata.programming_language` instead.
## 2. Per-source breakdown (final corpus)
### Math
| Source | Mode | Rows | Tokens | % of Category |
|--------|------|-----:|-------:|---------------:|
| finemath4plus | sampled to 700M | 508,357 | 700,003,574 | 69.7% |
| openwebmath | sampled to 300M | 146,473 | 300,001,270 | 29.9% |
| gsm8k | all | 8,792 | 1,417,863 | 0.14% |
| hendrycks_math | all | 12,396 | 3,568,960 | 0.36% |
### Code
| Source | Mode | Rows | Tokens | % of Category |
|--------|------|-----:|-------:|---------------:|
| githubcode_python | all (under budget) | 236,531 | 287,901,844 | 28.2% |
| githubcode_javascript | sampled to 300M | 333,786 | 300,000,630 | 29.4% |
| githubcode_java | sampled to 240M | 236,242 | 240,000,466 | 23.5% |
| githubcode_html | sampled to 90M | 51,764 | 90,006,022 | 8.8% |
| githubcode_css | sampled to 60M | 50,152 | 60,000,074 | 5.9% |
| freecodecamp | all | 10,258 | 5,175,953 | 0.5% |
| exercism | all | 422 | 275,072 | 0.03% |
| apps | all | 4,959 | 16,080,052 | 1.6% |
| codecontests | all | 13,134 | 21,065,001 | 2.1% |
`githubcode_python` came in under its original 400M config target (Step 4.1's
`invalid_syntax` filter dropped 41,130 Python-2-syntax files — a deliberate,
verified-beneficial filter, not a bug) and was included in full rather than
backfilled by loosening quality thresholds. The shortfall was made up by
increasing javascript/java/html/css's sampled targets above pipeline.md's
original example percentages, since those sources had ample surplus.
## 3. Pipeline stage summary — token counts
| Category | Raw | After Cleaning | After Dedup | After Filtering | Final |
|----------|----:|----------------:|------------:|-----------------:|------:|
| Math | 3,248,617,940 | 3,231,640,208 | 3,215,245,918 | ~3,059,148,111 | 1,004,991,667 |
| Code | 4,589,566,182 | 2,289,366,123 | 2,235,414,819 | ~2,109,766,319 | 1,020,505,114 |
(Code's raw→cleaned drop is large because Step 1.4's `githubcode` source was
deliberately over-downloaded well beyond the final target, per pipeline.md's
"download ~10x headroom" guidance, then filtered down at every stage.)
## 4. Cleaning pipeline summary (Phase 2)
5 rule groups applied across 4 cleaning scripts (`clean_web_math.py`,
`clean_structured_math.py`, `clean_code_stack.py`, `clean_code_educational.py`):
- **Group A** (web-crawled math): boilerplate/nav stripping, spam/warez
pattern removal, encoding normalization (ftfy), PII redaction.
- **Group B** (structured math): light validation only (already-clean
benchmark data).
- **Group C** (GitHub code): vendored-code exclusion, autogenerated-file
exclusion (javadoc-specific + generic), minified-code exclusion, excessive
encoded-content exclusion, trivial-test exclusion.
- **Group D** (educational code): freeCodeCamp non-coding block exclusion
(108 language-course superblocks removed via `freecodecamp_excluded_blocks.json`).
- **Group E** (PII): email/phone/IPv4/SSN/API-key redaction with extensive
context-aware false-positive suppression (math arithmetic, version
strings, ISBNs, DOIs, test262 spec identifiers — see `config/cleaning_rules.md`).
22 real bugs were found and fixed during Phase 2/4 via direct spot-checking
of actual output (not just exit-code/summary-count trust), documented in full
chronological detail in `progress.md`'s Decisions Log. The single most
consequential: a math-density/language heuristic was wrongly rejecting
excellent K-12 content (41 official AMC 8 competition problems, geometry
"kite/rhombus" problems) because it lacked explicit math vocabulary or used
non-ASCII notation (Greek letters) — fixed by trusting FineMath's own
upstream quality classifier for that source instead of re-applying a cruder
heuristic on top of it.
## 5. Deduplication statistics (Phase 3)
**Exact (SHA-256) dedup:**
| Category | Rows In | Rows Out | Duplicates Removed |
|----------|--------:|---------:|--------------------:|
| Math | 2,181,776 | 2,172,722 | 9,054 (0.4%) |
| Code | 1,974,655 | 1,973,991 | 664 (0.03%) |
**Fuzzy (MinHash LSH, Jaccard 0.8 math / 0.85 code) intra-source dedup:**
| Source | Kept | Removed |
|--------|-----:|--------:|
| finemath4plus | 1,878,340 | 5,128 |
| openwebmath | 267,941 | 21 |
| gsm8k | 8,792 | 0 |
| hendrycks_math | 12,484 | 16 |
| githubcode_python | 289,598 | 3,216 |
| githubcode_javascript | 410,580 | 5,542 |
| githubcode_java | 805,252 | 18,490 |
| githubcode_html | 327,796 | 18,692 |
| githubcode_css | 64,347 | 1,545 |
| freecodecamp | 10,262 | 113 |
| exercism | 422 | 2 |
| apps / codecontests | 5,000 / 13,134 | 0 / 0 |
**Fuzzy inter-source dedup:**
| Category | Total Seen | Total Kept | Removed |
|----------|-----------:|-----------:|--------:|
| Math | 2,167,557 | 2,166,099 | 1,458 |
| Code | 1,926,391 | 1,926,161 | 230 |
A performance bug was found and fixed during this phase: per-shingle
`MinHash.update()` cost scaled with document length (measured 13.6ms/doc,
would have taken ~6+ hours on the largest sources) — fixed by capping
shingles fed into MinHash to 150/doc via deterministic even-spacing
(not random sampling, to stay reproducible), achieving a 4.6x speedup with
`num_perm=128` kept unchanged per spec.
## 6. Quality filter statistics (Phase 4, Step 4.1)
**Math** (`filter_math.py`) drop reasons:
| Source | Records In | Records Out | Top Drop Reasons |
|--------|-----------:|-------------:|-------------------|
| finemath4plus | 1,878,340 | 1,875,104 | reddit_comment_dump (1,108), length_out_of_bounds (1,716), repetition (401), encoding_quality (11) |
| openwebmath | 266,495 | 232,018 | low_math_density (29,603), length_out_of_bounds (3,047), non_english (1,680), repetition (83), reddit_comment_dump (62), encoding_quality (2) |
| gsm8k | 8,792 | 8,792 | none |
| hendrycks_math | 12,472 | 12,396 | length_out_of_bounds (76) |
**Code** (`filter_code.py`) drop reasons:
| Source | Records In | Records Out | Top Drop Reasons |
|--------|-----------:|-------------:|-------------------|
| githubcode_python | 289,598 | 236,531 | invalid_syntax (41,130), comment_ratio_out_of_bounds (10,198), poor_identifier_names (905), length_out_of_bounds (834) |
| githubcode_javascript | 410,571 | 400,453 | comment_ratio_out_of_bounds (6,703), poor_identifier_names (1,586), length_out_of_bounds (1,829) |
| githubcode_java | 805,105 | 771,600 | comment_ratio_out_of_bounds (30,344), length_out_of_bounds (2,409), poor_identifier_names (752) |
| githubcode_html | 327,765 | 324,900 | poor_identifier_names (943), length_out_of_bounds (1,002), comment_ratio_out_of_bounds (920) |
| githubcode_css | 64,304 | 62,405 | comment_ratio_out_of_bounds (1,367), length_out_of_bounds (493), poor_identifier_names (39) |
| freecodecamp / exercism / apps / codecontests | small, near-zero drops | | length_out_of_bounds only |
`invalid_syntax` for Python was investigated directly (14.2% of raw files) and
confirmed to be genuine Python 2 syntax (`print x`, `except X, e:`) — kept as
a deliberate filter since excluding legacy syntax benefits a modern coding
corpus. `comment_ratio` originally had a serious formula bug (a
double-normalized calculation that returned meaningless values, plus a
DOTALL regex bug that let one `#` comment "match" to end-of-file) — both
fixed and the check simplified to a single upper bound (0.8) uniform across
all 5 languages, after measuring that ~54% of real JavaScript files fall
below any reasonable lower bound despite being genuinely good code.
Step 4.2 (optional GPU classifier) was explicitly skipped per pipeline.md's
"optional" designation — not requested by the user, and unnecessary given
ample raw token surplus confirmed at every stage. Step 4.3 was effectively
completed by Step 4.1's scripts.
## 7. Audit results summary (Step 4.4 + Step 5.4)
**Step 4.4 (pre-assembly filtered-data audit, sampled from `data/filtered/`):**
- Code: 39/100 read — ~90% good, ~10% borderline (Sphinx docs, license
pages), 0% bad. Thresholds met.
- Math: 40/100 read — ~80% good, ~12.5% borderline, 7.5% bad. Thresholds
met. Found and fixed the Reddit comment-dump content-appropriateness
issue (`is_reddit_comment_dump`, added despite low 0.065%/0.030% volume
on appropriateness grounds, not quality-volume grounds).
**Step 5.4 (final post-assembly audit, sampled from `data/final/`):**
- Code: 46/200 read — 93.5% good, 4.3% borderline, 2.2% bad. Thresholds met.
- Math: 40/200 read — 72.5% good, 12.5% borderline, **15% bad (above the
10% threshold)**. Six distinct low-frequency patterns with no shared
cheap detection signature (AI-spam filler, off-topic forum dumps,
content-aggregator splicing, thin SEO templates, a scraping artifact, and
one essay-mill/homework-cheating-service ad). Flagged to the user with
three remediation options; **user decision: accept as a documented
residual limitation and proceed to delivery**, given the corpus is still
~85% good+borderline and further tightening risks reintroducing the
AMC-8 false-positive problem. Full detail in `reports/final_audit.md`.
Full detail for both audit rounds: `reports/quality_audit.md` (Step 4.4),
`reports/final_audit.md` (Step 5.4).
## 8. Known limitations and caveats
- **Math corpus bad-rate (15% at final n=40)**: see above — accepted by the
user as a residual limitation. Content is genuinely low-quality/off-topic
in these cases, not corrupted or unsafe at scale, but a downstream
consumer doing further quality-sensitive work may want to apply additional
filtering for AI-generated SEO filler, off-topic forum dumps, and
commercial/service advertisements.
- **AMPS and OpenStax** (pipeline.md's example math sources) were never
sourced — AMPS has no confirmed public HuggingFace dataset, and OpenStax
was not investigated given time constraints and ample surplus from the
sources actually used.
- **The Stack v2** (pipeline.md's primary code source) was gated/inaccessible
(403 GatedRepoError, confirmed 2026-08-22) and was replaced with
`codeparrot/github-code-clean` per user decision — a non-gated substitute
with a different (row-level, not pre-sharded) structure.
- **freeCodeCamp + Exercism combined (~5.5M final tokens)** fell well short
of pipeline.md's example ~150M "tutorial/educational" allocation — accepted
by the user, made up by drawing more from the primary GitHub code source
instead.
- **HTML quality**: flagged early (Step 1.6) as having real quality issues
(OCR garbage, non-javadoc auto-generated docs slipping through). Kept per
user decision, relying on Phase 4's heuristic filters — final audit found
the residual auto-generated-doc gap persists at low frequency (Sphinx,
Clover, Doxygen artifacts), consistent across both audit rounds.
- **quality_score is null for all non-finemath4plus sources** — no
equivalent upstream classifier score exists for those sources; this was a
deliberate choice over fabricating a placeholder value.
- **Duplicate-block detector (built, not deployed)**: a generic
internal-duplication heuristic was built and tested during the Step 4.4
math audit (catching 1.5% of finemath4plus) but rejected after inspection
showed most matches were legitimate forum-quoting structure, not junk
duplication — documented as a rejected approach rather than shipped.
## 9. Pipeline runtime and process notes
The pipeline ran across 2026-08-22 through 2026-08-24. 22+ real bugs were
found and fixed via direct spot-checking of actual output at every stage
(never trusting exit codes or summary counts alone) — full chronological
detail in `progress.md`. One data-integrity incident occurred late in
Phase 5: two duplicate `filter_math.py --source finemath4plus` processes
were found running concurrently, both writing to the same output file in
`"w"` mode (a race condition from an unreconciled duplicate background
launch), corrupting the file mid-write. Caught during Phase 5 token-summing
(the file's row count changed between two consecutive reads), both
processes were killed, the corrupted output deleted, and a single clean
instance rerun and fully verified before any downstream work relied on it.
|