Skip to content

Commit 4b07e0c

Browse files
hyperpolymathclaude
andcommitted
feat(vocab): cap CANON at ~100K tokens via MAX_MINED
Add MAX_MINED top-N-by-frequency cap to vocabulary_mine_corpus.jl. Set to 95,000 so the union with the ~9K curated seed lands at 100,180 tokens — matching the 100K target. Rationale: 115K was useful to survey what's *available* (372K raw uniques after the freq≥3 + junk filter collapses to 110K), but diminishing returns kick in after 100K for a 253K-record corpus, and the encoder's max_vocab default is 50K regardless — so a tighter CANON ships the most signal-dense tokens first. Justfile `vocab-canon` now runs mine + canonicalize in sequence. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bc90974 commit 4b07e0c

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

Justfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ run *ARGS:
6666
invariant-path *ARGS:
6767
./scripts/invariant-path.sh {{ARGS}}
6868

69-
# Rebuild the curated seed vocabulary (training_data/vocabulary_CANON.txt)
70-
# from scripts/vocabulary_5x_expansion.jl + the hand-curated vocab files.
71-
# Consumed by src/julia/training/dataloader.jl:build_vocabulary_from_data.
69+
# Rebuild the canonical seed vocabulary (training_data/vocabulary_CANON.txt).
70+
# Two stages: (1) mine frequency-filtered identifiers from the per-prover
71+
# proof corpora, then (2) union with the hand-curated sets. Consumed by
72+
# src/julia/training/dataloader.jl:build_vocabulary_from_data.
7273
vocab-canon:
74+
julia scripts/vocabulary_mine_corpus.jl
7375
julia scripts/vocabulary_canonicalize.jl
7476

7577
# Report corpus balance across provers from stats_UNIFIED.json.

scripts/vocabulary_mine_corpus.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ include(joinpath(REPO_ROOT, "scripts", "vocabulary_canonicalize.jl"))
5252
# identifiers that recur across proofs in a family.
5353
const MIN_FREQ = 3
5454

55+
# Hard cap on the mined vocabulary so the final CANON (mined ∪ curated
56+
# ≈ 9K) lands at roughly 100K tokens. After the freq filter, keep the
57+
# top N tokens by descending frequency; the tail is long but
58+
# diminishing-return. Passing 0 disables the cap.
59+
const MAX_MINED = 95_000
60+
5561
# Per-prover authoritative corpus files — mirrors merge_corpus.jl.
5662
# Aggregate/merged files (UNIFIED, COMPLETE, BALANCED, ULTIMATE, etc.)
5763
# are excluded deliberately to avoid double-counting.
@@ -166,14 +172,21 @@ function mine()
166172
println("Records ingested: $records_in")
167173
println("Raw unique tokens: $(length(counts))")
168174

169-
kept = String[]
175+
kept_pairs = Tuple{String, Int}[]
170176
for (tok, c) in counts
171177
c >= MIN_FREQ || continue
172178
is_valid_token(tok) || continue
173-
push!(kept, tok)
179+
push!(kept_pairs, (tok, c))
180+
end
181+
n_pre_cap = length(kept_pairs)
182+
println("After freq>=$MIN_FREQ + filter: $n_pre_cap tokens")
183+
184+
if MAX_MINED > 0 && length(kept_pairs) > MAX_MINED
185+
sort!(kept_pairs; by = x -> -x[2])
186+
kept_pairs = kept_pairs[1:MAX_MINED]
187+
println("Capped to top $MAX_MINED by frequency.")
174188
end
175-
sort!(kept)
176-
println("After freq>=$MIN_FREQ + filter: $(length(kept)) tokens")
189+
kept = sort!([p[1] for p in kept_pairs])
177190

178191
open(OUTPUT_FILE, "w") do fh
179192
for t in kept
@@ -183,14 +196,16 @@ function mine()
183196
println("Wrote $OUTPUT_FILE")
184197

185198
stats = Dict{String, Any}(
186-
"version" => "mined-v1",
199+
"version" => "mined-v2",
187200
"generated_at" => string(now()),
188201
"generator" => "scripts/vocabulary_mine_corpus.jl",
189202
"min_freq" => MIN_FREQ,
203+
"max_mined" => MAX_MINED,
190204
"files_seen" => files_seen,
191205
"files_missing" => files_miss,
192206
"records_ingested" => records_in,
193207
"raw_unique_tokens" => length(counts),
208+
"kept_before_cap" => n_pre_cap,
194209
"kept_tokens" => length(kept),
195210
)
196211
open(STATS_FILE, "w") do fh

0 commit comments

Comments
 (0)