classical-ja-pretrain / code /scripts /README_threeway_split.md
kuramot6f's picture
Initial release (history squashed)
7a088d4
|
Raw History Blame Contribute Delete
6.34 kB
# Filtered train / validation / test data
Input corpus: `unified/pretrain-v1/build-003/pretrain.jsonl`.
Saved tokens: `unified/tokens-v1/build-002/`.
Frozen related-work groups: `unified/split-groups-v1/build-003/`.
Three-way split: `unified/training-tokens-v1/build-006/`.
The input already contains 1,003,802,442 token IDs across 114,688 documents, with document BOS/EOS. All 6,674 user-excluded Kanripo unknown-dynasty files are absent. The splitter copies existing token slices without retokenizing or changing their values.
## Reproduce
Commands used for the initial build:
```bash
.venv-tokenizer/bin/python -m unittest discover -s scripts -p test_threeway_split.py -v
.venv-tokenizer/bin/python scripts/threeway_split.py group \
--output unified/split-groups-v1/build-002
.venv-tokenizer/bin/python scripts/refine_split_groups.py
.venv-tokenizer/bin/python scripts/threeway_split.py split \
--groups unified/split-groups-v1/build-003 \
--output unified/training-tokens-v1/build-006
```
Outputs must be fresh directories. `refine_split_groups.py` uses the recorded build-002 grouping and writes build-003; use fresh paths in a copied/reconfigured invocation for a subsequent revision. An earlier incomplete grouping build-001 was interrupted while the comparison implementation was optimized; it is not used.
## Whole-work grouping and duplicate review
Initial groups connect source-document/work IDs, normalized candidate titles/editions, and whitespace-insensitive exact texts. Work-named Wikisource categories provide additional alias links within the original frozen include-category tree. Generic era and genre categories never merge unrelated works. Explicit suffixes such as `卷409`, `卷第四百九`, `第四百九巻`, and `409巻` are canonicalized in a second pass so physical volumes remain in the same global group.
Candidate near duplicates are searched across the full retained corpus using punctuation/whitespace-insensitive 5-grams. The candidate index uses bottom-32 rolling-hash sketches; a pair needs at least four shared anchors. Anchors with more than 128 postings are disabled, and the best 128 candidates per document are considered. A prefilter requires at least 16 of the shorter document's bottom-32 hashes to occur in the other document. Candidates passing the full rolling-hash overlap check are confirmed against the existing full BLAKE2b 5-gram rule: at least 200 significant characters, 100 distinct 5-grams, and 90% coverage of the shorter normalized document, or full document containment. Confirmed matches join their work groups; no training document is deleted by this step.
`joins.jsonl` records each confirmed near-duplicate, category alias, and volume alias edge. `groups.json` freezes complete group membership. The grouping report records comparison/skipping/capping counts and the twenty largest groups for inspection. This is a bounded candidate search, not an exhaustive identity or semantic-duplicate guarantee. Containment in much longer texts and unknown aliases can remain undetected. Candidate titles and volume suffixes can also merge unrelated works with identical names.
## Allocation
Seed: 20261024. Target independent group proportions within each source/era:
| Source | Train | Validation | Test |
|---|---:|---:|---:|
| Kanripo, NDL | 98% | 1% | 1% |
| Minhon, Wikisource | 90% | 5% | 5% |
All members of a global group receive one split, including groups crossing sources/eras. Sparse strata are processed first. One-group strata stay in training; two-group strata aim for train/validation; three or more aim for all three. Global constraints can prevent complete coverage, and small eras can have large percentage deviations. Group-count targets are primary; seeded candidate selection and bounded swaps improve token balance without changing the required grouping/coverage constraints. Actual counts, coverage gaps, and unmet targets are in the reports.
Era evidence is reused by document ID from corrected historical metadata in the prior build-005. Its old split assignments are discarded. The filtered token manifest and era-evidence file are hashed so the new grouping is bound to these inputs.
## Files and evaluation isolation
- `{source}.{train,validation,test}.bin`: twelve little-endian uint32 streams.
- `splits.jsonl`: original document metadata, input/split token offsets, era/evidence, group, split, and token-slice SHA256.
- `group-joins.jsonl`: confirmed cross-document links whose endpoints must remain together.
- `evaluation-windows.jsonl`: fixed validation/test windows keyed by source, era, and work group. Each window references one or more document slices in its split stream. Windows contain at most 2049 input IDs for 2048 next-token predictions. Predicted tokens never overlap; the previous final token may be reused as context for the next window. Short groups/tails have explicit lengths and are not silently counted as padding loss.
- `report.json`, `REPORT.md`: source/era group/document/token amounts and actual proportions, duplicate review, and evaluation window counts.
- `verification.json`: full ID/token coverage, exclusion absence, copied-token equality, group/title/exact/confirmed-match separation, and evaluation-window boundary/prediction checks.
- `manifest.json`: completed state, input/group/evidence/code hashes, policy, seed, file hashes, and an explicit training-file allowlist.
`token_data.TokenData` opens only train/validation streams and verifies only the declared `training_files` for this build. It never opens test streams for sampling or startup hashes. Independent split verification checks all twelve streams. Test windows are reserved for final evaluation; validation windows are for training decisions. Model evaluation code must honor the saved segment lists and explicit predicted-token lengths when these manifests are integrated into the model runner. The loader was extracted from the retired JAX runner without a training-framework dependency.
The existing tokenizer predates exclusion/splitting. This is a model-data holdout; the tokenizer was exposed to the earlier corpus, including now-excluded documents. Retraining the tokenizer on retained training text only would be a separate change. Era metadata also does not certify that every retained passage meets the historical cutoff.