Add lc0 self-play and Lichess Elite position collections
Browse filesAdds two unlabeled position collections in the existing schema:
lc0_selfplay (2,000,000 positions, 9 lc0 runs, split by network strength) and lichess_elite (300,000 positions, 12 months of the Lichess Elite Database).
Includes variance reports and the build scripts.
- README.md +124 -11
- lc0-selfplay-2m-variance.json +93 -0
- lc0-selfplay-2m/_manifest.json +148 -0
- lc0-selfplay-2m/source_split=early/phase=endgame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=early/phase=middlegame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=early/phase=opening/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=low/phase=endgame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=low/phase=middlegame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=low/phase=opening/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=mid/phase=endgame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=mid/phase=middlegame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=mid/phase=opening/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=strong/phase=endgame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=strong/phase=middlegame/positions.parquet +3 -0
- lc0-selfplay-2m/source_split=strong/phase=opening/positions.parquet +3 -0
- lichess-elite-300k-variance.json +90 -0
- lichess-elite-300k/_manifest.json +49 -0
- lichess-elite-300k/source_split=human/phase=endgame/positions.parquet +3 -0
- lichess-elite-300k/source_split=human/phase=middlegame/positions.parquet +3 -0
- lichess-elite-300k/source_split=human/phase=opening/positions.parquet +3 -0
- scripts/build_human_corpus.py +299 -0
- scripts/build_selfplay_corpus.py +422 -0
- scripts/lc0_runs.py +102 -0
- scripts/plain_to_fen.py +81 -0
- scripts/rescorer-optional-syzygy.patch +25 -0
README.md
CHANGED
|
@@ -12,6 +12,8 @@ tags:
|
|
| 12 |
- fen
|
| 13 |
- lc0
|
| 14 |
- wdl
|
|
|
|
|
|
|
| 15 |
|
| 16 |
size_categories:
|
| 17 |
- 1M<n<10M
|
|
@@ -36,28 +38,56 @@ configs:
|
|
| 36 |
path: zero-consensus/validation-*.parquet
|
| 37 |
- split: test
|
| 38 |
path: zero-consensus/test-*.parquet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
---
|
| 40 |
|
| 41 |
# Zero Evaluator High-Variance Chess Positions
|
| 42 |
|
| 43 |
-
This dataset
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
game
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
and retains the original source train/test split. The complete variance audit
|
| 50 |
-
is in `variance-report.json` and `RESULTS.md`.
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
-
- `
|
| 55 |
-
|
| 56 |
-
NNUE WDL labels and per-row engine provenance;
|
| 57 |
- `consensus_wdl`: a one-million-position subset carrying calibrated static WDL
|
| 58 |
from both Lc0 and Stockfish, a blended consensus target, and a per-row
|
| 59 |
agreement weight.
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
## Data layout
|
| 62 |
|
| 63 |
The release consists of six Zstandard-compressed Parquet files partitioned by:
|
|
@@ -246,6 +276,73 @@ row = positions["train"][0]
|
|
| 246 |
print(row["fen"], row["wdl_win"], row["sample_weight"])
|
| 247 |
```
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
## Validation
|
| 250 |
|
| 251 |
- All 1,509,201 source rows were reproduced in Parquet.
|
|
@@ -264,6 +361,15 @@ print(row["fen"], row["wdl_win"], row["sample_weight"])
|
|
| 264 |
shards, each matching its manifest row count and SHA-256 checksum.
|
| 265 |
- Every consensus row carries three WDL triples that each sum to 1000, and a
|
| 266 |
sample weight within `[0.4, 1.0]`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
## Source
|
| 269 |
|
|
@@ -271,4 +377,11 @@ The source is the [Leela Chess Zero standard CCRL dataset](https://lczero.org/bl
|
|
| 271 |
published as 2.5 million CCRL 40/40 and 40/4 engine games with an original
|
| 272 |
80/20 train/test split.
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
The extraction and conversion scripts are included for reproducibility.
|
|
|
|
| 12 |
- fen
|
| 13 |
- lc0
|
| 14 |
- wdl
|
| 15 |
+
- self-play
|
| 16 |
+
- lichess
|
| 17 |
|
| 18 |
size_categories:
|
| 19 |
- 1M<n<10M
|
|
|
|
| 38 |
path: zero-consensus/validation-*.parquet
|
| 39 |
- split: test
|
| 40 |
path: zero-consensus/test-*.parquet
|
| 41 |
+
- config_name: lc0_selfplay
|
| 42 |
+
data_files:
|
| 43 |
+
- split: strong
|
| 44 |
+
path: lc0-selfplay-2m/source_split=strong/**/*.parquet
|
| 45 |
+
- split: mid
|
| 46 |
+
path: lc0-selfplay-2m/source_split=mid/**/*.parquet
|
| 47 |
+
- split: low
|
| 48 |
+
path: lc0-selfplay-2m/source_split=low/**/*.parquet
|
| 49 |
+
- split: early
|
| 50 |
+
path: lc0-selfplay-2m/source_split=early/**/*.parquet
|
| 51 |
+
- config_name: lichess_elite
|
| 52 |
+
data_files:
|
| 53 |
+
- split: train
|
| 54 |
+
path: lichess-elite-300k/source_split=human/**/*.parquet
|
| 55 |
---
|
| 56 |
|
| 57 |
# Zero Evaluator High-Variance Chess Positions
|
| 58 |
|
| 59 |
+
This dataset collects **3,809,201 chess positions** from three distinct styles
|
| 60 |
+
of play — engine tournament games, neural-network self-play, and strong human
|
| 61 |
+
online games. Positions are stored as normalized six-field FEN records for
|
| 62 |
+
immediate board reconstruction without replaying a game, and every collection
|
| 63 |
+
balances opening, middlegame, and endgame coverage.
|
| 64 |
+
|
| 65 |
+
Two of the collections additionally carry static, depth-zero win/draw/loss
|
| 66 |
+
labels. Variance audits are in `variance-report.json`,
|
| 67 |
+
`lc0-selfplay-2m-variance.json`, `lichess-elite-300k-variance.json`, and
|
| 68 |
+
`RESULTS.md`.
|
| 69 |
|
| 70 |
+
Five configurations are available.
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
Positions with labels:
|
| 73 |
|
| 74 |
+
- `stockfish_zero_wdl`: 1,509,201 CCRL positions with immediate static
|
| 75 |
+
Stockfish NNUE WDL labels and per-row engine provenance;
|
|
|
|
| 76 |
- `consensus_wdl`: a one-million-position subset carrying calibrated static WDL
|
| 77 |
from both Lc0 and Stockfish, a blended consensus target, and a per-row
|
| 78 |
agreement weight.
|
| 79 |
|
| 80 |
+
Positions without labels:
|
| 81 |
+
|
| 82 |
+
- `default`: 1,509,201 positions from CCRL engine tournament games;
|
| 83 |
+
- `lc0_selfplay`: 2,000,000 positions from Leela Chess Zero self-play,
|
| 84 |
+
split by the generation strength of the network that produced them;
|
| 85 |
+
- `lichess_elite`: 300,000 positions from strong human games on Lichess.
|
| 86 |
+
|
| 87 |
+
The three unlabeled collections are near-disjoint: of 3,809,201 rows,
|
| 88 |
+
3,784,379 FENs are unique and 24,822 appear in more than one collection,
|
| 89 |
+
almost entirely common opening positions.
|
| 90 |
+
|
| 91 |
## Data layout
|
| 92 |
|
| 93 |
The release consists of six Zstandard-compressed Parquet files partitioned by:
|
|
|
|
| 276 |
print(row["fen"], row["wdl_win"], row["sample_weight"])
|
| 277 |
```
|
| 278 |
|
| 279 |
+
## Self-play and human position collections
|
| 280 |
+
|
| 281 |
+
Two further collections extend the corpus beyond CCRL engine games. Both hold
|
| 282 |
+
positions only — no evaluations — in the same schema as the `default`
|
| 283 |
+
configuration, so they can be read the same way and labeled independently.
|
| 284 |
+
|
| 285 |
+
### `lc0_selfplay`
|
| 286 |
+
|
| 287 |
+
2,000,000 positions sampled from Leela Chess Zero self-play training data
|
| 288 |
+
published at `storage.lczero.org/files/training_data`, drawn from 252,686
|
| 289 |
+
distinct games across 56 archives and 9 training runs spanning 2018-09 to
|
| 290 |
+
2026-08.
|
| 291 |
+
|
| 292 |
+
Splits correspond to the strength of the network that generated the games,
|
| 293 |
+
since a collection drawn only from the strongest run would be narrow in exactly
|
| 294 |
+
the way a varied corpus should not be:
|
| 295 |
+
|
| 296 |
+
| Split | Positions | Runs | Character |
|
| 297 |
+
| --- | ---: | --- | --- |
|
| 298 |
+
| `strong` | 1,200,000 | test80, test91 | Mature run1 and the live run2 |
|
| 299 |
+
| `mid` | 440,000 | test79, test75, late test60 | Transitional styles, sound but more varied |
|
| 300 |
+
| `low` | 260,000 | test40, early test60, test71_5 | Messier tactics, unusual structures |
|
| 301 |
+
| `early` | 100,000 | test30, run3 | Semi-initial play, maximum noise |
|
| 302 |
+
|
| 303 |
+
Records were decoded with the Lc0 rescorer without tablebase rescoring or
|
| 304 |
+
deblundering, and without the position filtering that the Stockfish NNUE
|
| 305 |
+
conversion path applies. Up to twelve positions were taken per game, allocated
|
| 306 |
+
across phases in the same 15/60/25 ratio the splits hold.
|
| 307 |
+
|
| 308 |
+
The `test71` run is excluded: it is the Chess960 run, measured at 30-36%
|
| 309 |
+
Chess960 against at most 1.2% in every other run. Chess960 positions are
|
| 310 |
+
excluded throughout, so every FEN is legal standard chess.
|
| 311 |
+
|
| 312 |
+
Source game results are 583,358 white wins, 893,297 draws, and 523,345 black
|
| 313 |
+
wins — a 44.7% draw rate.
|
| 314 |
+
|
| 315 |
+
### `lichess_elite`
|
| 316 |
+
|
| 317 |
+
300,000 positions from 180,510 games in the
|
| 318 |
+
[Lichess Elite Database](https://database.nikonoel.fr/), which filters the
|
| 319 |
+
Lichess standard database to games where a 2400+ player faced a 2200+ player.
|
| 320 |
+
Twelve months are sampled in equal share, spread across 2020-06 to 2025-10, at
|
| 321 |
+
three positions per game.
|
| 322 |
+
|
| 323 |
+
This is strong human **blitz**, not considered classical play: roughly 88% of
|
| 324 |
+
eligible games are 3+0 or 3+2, 5% rapid, and under 1% classical, with White Elo
|
| 325 |
+
median 2550. Bullet and ultrabullet are excluded.
|
| 326 |
+
|
| 327 |
+
Draws are 12.3% of source games here, against 44.7% in `lc0_selfplay`. Human
|
| 328 |
+
blitz is substantially more decisive than engine self-play, so this collection
|
| 329 |
+
supplies sharper and less balanced positions than the other two.
|
| 330 |
+
|
| 331 |
+
### Loading
|
| 332 |
+
|
| 333 |
+
```python
|
| 334 |
+
from datasets import load_dataset
|
| 335 |
+
|
| 336 |
+
selfplay = load_dataset("Pawitt/zero-evaluator", "lc0_selfplay")
|
| 337 |
+
print(selfplay["strong"][0]["fen"])
|
| 338 |
+
|
| 339 |
+
human = load_dataset("Pawitt/zero-evaluator", "lichess_elite")
|
| 340 |
+
print(human["train"][0]["fen"])
|
| 341 |
+
```
|
| 342 |
+
|
| 343 |
+
Both use the same columns as `default`; see `FORMAT.md`. As there, the source
|
| 344 |
+
game `result` is provenance metadata and not a position label.
|
| 345 |
+
|
| 346 |
## Validation
|
| 347 |
|
| 348 |
- All 1,509,201 source rows were reproduced in Parquet.
|
|
|
|
| 361 |
shards, each matching its manifest row count and SHA-256 checksum.
|
| 362 |
- Every consensus row carries three WDL triples that each sum to 1000, and a
|
| 363 |
sample weight within `[0.4, 1.0]`.
|
| 364 |
+
- The self-play and human collections contain exactly 2,000,000 and 300,000
|
| 365 |
+
rows, with no duplicate FEN within either.
|
| 366 |
+
- Their Parquet forms hold FEN sets identical to the SQLite databases they were
|
| 367 |
+
built from.
|
| 368 |
+
- Sampled rows from both were reconstructed with python-chess: every FEN parses
|
| 369 |
+
as a legal standard-chess position, and `side_to_move`, `piece_count`,
|
| 370 |
+
`in_check`, and `legal_moves` were recomputed and matched.
|
| 371 |
+
- Every split in both holds opening, middlegame, and endgame in a 15/60/25
|
| 372 |
+
ratio.
|
| 373 |
|
| 374 |
## Source
|
| 375 |
|
|
|
|
| 377 |
published as 2.5 million CCRL 40/40 and 40/4 engine games with an original
|
| 378 |
80/20 train/test split.
|
| 379 |
|
| 380 |
+
The self-play collection derives from
|
| 381 |
+
[Lc0 training data](https://storage.lczero.org/files/training_data/), decoded
|
| 382 |
+
with the [Lc0 rescorer](https://github.com/Tilps/lc0/tree/rescore_tb). The human
|
| 383 |
+
collection derives from the
|
| 384 |
+
[Lichess Elite Database](https://database.nikonoel.fr/), itself filtered from
|
| 385 |
+
the [Lichess open database](https://database.lichess.org/).
|
| 386 |
+
|
| 387 |
The extraction and conversion scripts are included for reproducibility.
|
lc0-selfplay-2m-variance.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"database": "/Users/pawit/Documents/vexilon/tmp/vex-position-dataset/data/lc0-selfplay-2m.vpd",
|
| 3 |
+
"database_bytes": 680898560,
|
| 4 |
+
"distributions": {
|
| 5 |
+
"in_check": 119989,
|
| 6 |
+
"material_imbalance_abs_ge_3": 394136,
|
| 7 |
+
"phase": {
|
| 8 |
+
"endgame": 499999,
|
| 9 |
+
"middlegame": 1200001,
|
| 10 |
+
"opening": 300000
|
| 11 |
+
},
|
| 12 |
+
"result": {
|
| 13 |
+
"0-1": 523345,
|
| 14 |
+
"1-0": 583358,
|
| 15 |
+
"1/2-1/2": 893297
|
| 16 |
+
},
|
| 17 |
+
"side_to_move": {
|
| 18 |
+
"black": 1004042,
|
| 19 |
+
"white": 995958
|
| 20 |
+
},
|
| 21 |
+
"source_split": {
|
| 22 |
+
"early": 100000,
|
| 23 |
+
"low": 260000,
|
| 24 |
+
"mid": 440000,
|
| 25 |
+
"strong": 1200000
|
| 26 |
+
},
|
| 27 |
+
"with_castling_rights": 582149,
|
| 28 |
+
"without_castling_rights": 1417851
|
| 29 |
+
},
|
| 30 |
+
"format": "VPD1",
|
| 31 |
+
"high_variance": true,
|
| 32 |
+
"metadata": {
|
| 33 |
+
"completed_unix": "1787660503",
|
| 34 |
+
"corpus": "lc0-selfplay-tiered",
|
| 35 |
+
"excluded_runs": "{\"test71\": \"Chess960 run; 30-36% of positions are Chess960\", \"test78\": \"all tars are 10 KB placeholders\", \"test90\": \"all tars are 10 KB placeholders\"}",
|
| 36 |
+
"fen_fullmove_normalization": "1",
|
| 37 |
+
"format": "VPD1",
|
| 38 |
+
"keep_chess960": "0",
|
| 39 |
+
"per_game": "12",
|
| 40 |
+
"position_count": "2000000",
|
| 41 |
+
"seed": "91",
|
| 42 |
+
"slice_bytes": "120000000",
|
| 43 |
+
"source": "https://storage.lczero.org/files/training_data",
|
| 44 |
+
"target_positions": "2000000",
|
| 45 |
+
"tars_done": "[\"run3/training-run3-20190615-0720.tar\", \"run3/training-run3-20190707-1318.tar\", \"run3/training-run3-20190818-0817.tar\", \"test30/training-run2-20180909-1221.tar\", \"test30/training-run2-20181214-1617.tar\", \"test40/training-run1-20190108-1117.tar\", \"test40/training-run1-20190710-1317.tar\", \"test60/training-run1-20190726-1317.tar\", \"test60/training-run1-20191024-0917.tar\", \"test60/training-run1-20200119-2117.tar\", \"test60/training-run1-test60-20210108-1117.tar\", \"test60/training-run1-test60-20210404-2117.tar\", \"test60/training-run1-test60-20210706-0917.tar\", \"test60/training-run1-test60-20220102-0317.tar\", \"test71_5/training-run3-test71_5-20200705-0821.tar\", \"test71_5/training-run3-test71_5-20200821-1829.tar\", \"test75/training-run3-test75-20210314-0535.tar\", \"test75/training-run3-test75-20210426-0227.tar\", \"test75/training-run3-test75-20210609-1028.tar\", \"test75/training-run3-test75-20210730-0317.tar\", \"test75/training-run3-test75-20210911-0217.tar\", \"test79/training-run2-test79-20220225-0617.tar\", \"test79/training-run2-test79-20220318-1517.tar\", \"test79/training-run2-test79-20220408-2320.tar\", \"test79/training-run2-test79-20220430-2321.tar\", \"test80/training-run1-test80-20240401-0017.tar\", \"test80/training-run1-test80-20240411-1617.tar\", \"test80/training-run1-test80-20240422-1217.tar\", \"test80/training-run1-test80-20240514-0717.tar\", \"test80/training-run1-test80-20240604-1517.tar\", \"test80/training-run1-test80-20240626-0817.tar\", \"test80/training-run1-test80-20240718-1917.tar\", \"test80/training-run1-test80-20240809-0317.tar\", \"test80/training-run1-test80-20240830-1217.tar\", \"test80/training-run1-test80-20240920-2017.tar\", \"test80/training-run1-test80-20241012-0417.tar\", \"test80/training-run1-test80-20241102-1217.tar\", \"test80/training-run1-test80-20241207-2317.tar\", \"test80/training-run1-test80-20241229-0717.tar\", \"test80/training-run1-test80-20250211-2317.tar\", \"test80/training-run1-test80-20250308-0217.tar\", \"test80/training-run1-test80-20250329-1017.tar\", \"test80/training-run1-test80-20250419-1917.tar\", \"test80/training-run1-test80-20250723-0017.tar\", \"test80/training-run1-test80-20250813-0917.tar\", \"test91/training-run2-test91-20251220-0017.tar\", \"test91/training-run2-test91-20260102-1517.tar\", \"test91/training-run2-test91-20260113-0718.tar\", \"test91/training-run2-test91-20260209-0417.tar\", \"test91/training-run2-test91-20260308-0817.tar\", \"test91/training-run2-test91-20260403-1317.tar\", \"test91/training-run2-test91-20260503-0517.tar\", \"test91/training-run2-test91-20260524-2017.tar\", \"test91/training-run2-test91-20260615-0617.tar\", \"test91/training-run2-test91-20260718-2017.tar\", \"test91/training-run2-test91-20260810-0917.tar\"]",
|
| 46 |
+
"tier_quotas": "{\"early\": 100000, \"low\": 260000, \"mid\": 440000, \"strong\": 1200000}"
|
| 47 |
+
},
|
| 48 |
+
"normalized_phase_entropy": 0.853474,
|
| 49 |
+
"numeric": {
|
| 50 |
+
"legal_moves": {
|
| 51 |
+
"max": 81,
|
| 52 |
+
"mean": 30.4465,
|
| 53 |
+
"median": 32,
|
| 54 |
+
"min": 1,
|
| 55 |
+
"p10": 14,
|
| 56 |
+
"p90": 44,
|
| 57 |
+
"stdev": 11.6261
|
| 58 |
+
},
|
| 59 |
+
"material_balance_white_minus_black": {
|
| 60 |
+
"max": 44,
|
| 61 |
+
"mean": 0.007,
|
| 62 |
+
"median": 0,
|
| 63 |
+
"min": -43,
|
| 64 |
+
"p10": -2,
|
| 65 |
+
"p90": 2,
|
| 66 |
+
"stdev": 3.8089
|
| 67 |
+
},
|
| 68 |
+
"piece_count": {
|
| 69 |
+
"max": 32,
|
| 70 |
+
"mean": 21.2929,
|
| 71 |
+
"median": 22,
|
| 72 |
+
"min": 3,
|
| 73 |
+
"p10": 11,
|
| 74 |
+
"p90": 31,
|
| 75 |
+
"stdev": 7.5803
|
| 76 |
+
}
|
| 77 |
+
},
|
| 78 |
+
"positions": 2000000,
|
| 79 |
+
"thresholds": {
|
| 80 |
+
"at_least_1_5m_positions": true,
|
| 81 |
+
"both_castling_states_at_least_10pct": true,
|
| 82 |
+
"checks_at_least_1pct": true,
|
| 83 |
+
"legal_move_p10_at_most_22": true,
|
| 84 |
+
"legal_move_p90_at_least_38": true,
|
| 85 |
+
"legal_move_stdev_at_least_8": true,
|
| 86 |
+
"material_imbalance_at_least_15pct": true,
|
| 87 |
+
"phase_entropy_at_least_0_85": true,
|
| 88 |
+
"phase_min_share_at_least_15pct": true,
|
| 89 |
+
"piece_count_stdev_at_least_5": true,
|
| 90 |
+
"result_min_share_at_least_20pct": true,
|
| 91 |
+
"side_to_move_between_47_and_53pct_white": true
|
| 92 |
+
}
|
| 93 |
+
}
|
lc0-selfplay-2m/_manifest.json
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compression": "zstd",
|
| 3 |
+
"compression_level": 6,
|
| 4 |
+
"elapsed_seconds": 6.299,
|
| 5 |
+
"format": "VPD1-Parquet",
|
| 6 |
+
"partitioning": [
|
| 7 |
+
"source_split",
|
| 8 |
+
"phase"
|
| 9 |
+
],
|
| 10 |
+
"partitions": [
|
| 11 |
+
{
|
| 12 |
+
"bytes": 462723,
|
| 13 |
+
"file": "source_split=early/phase=opening/positions.parquet",
|
| 14 |
+
"max_id": 2000000,
|
| 15 |
+
"min_id": 1900001,
|
| 16 |
+
"phase": "opening",
|
| 17 |
+
"row_groups": 1,
|
| 18 |
+
"rows": 15000,
|
| 19 |
+
"sha256": "5e7177ca9393325b169ac40cb8768f7510d6c7c52b44e9b1eaed4c12ef2dc9f5",
|
| 20 |
+
"source_split": "early"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"bytes": 2006400,
|
| 24 |
+
"file": "source_split=early/phase=middlegame/positions.parquet",
|
| 25 |
+
"max_id": 1995097,
|
| 26 |
+
"min_id": 1900004,
|
| 27 |
+
"phase": "middlegame",
|
| 28 |
+
"row_groups": 1,
|
| 29 |
+
"rows": 60000,
|
| 30 |
+
"sha256": "b7047c2783dccb7134ddac56b77688503d40d03ea396527f071928b7657bb7fb",
|
| 31 |
+
"source_split": "early"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"bytes": 752875,
|
| 35 |
+
"file": "source_split=early/phase=endgame/positions.parquet",
|
| 36 |
+
"max_id": 1998571,
|
| 37 |
+
"min_id": 1900047,
|
| 38 |
+
"phase": "endgame",
|
| 39 |
+
"row_groups": 1,
|
| 40 |
+
"rows": 25000,
|
| 41 |
+
"sha256": "572e45aa624e02ff34249fef5b238d3683df0b3d561ede4a809e80ad3ae801aa",
|
| 42 |
+
"source_split": "early"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"bytes": 1210334,
|
| 46 |
+
"file": "source_split=low/phase=opening/positions.parquet",
|
| 47 |
+
"max_id": 1892253,
|
| 48 |
+
"min_id": 1640020,
|
| 49 |
+
"phase": "opening",
|
| 50 |
+
"row_groups": 1,
|
| 51 |
+
"rows": 39000,
|
| 52 |
+
"sha256": "e24d3b998a74e5462046500276220dcdc72650984459657689bfc479b165d4d9",
|
| 53 |
+
"source_split": "low"
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"bytes": 5130153,
|
| 57 |
+
"file": "source_split=low/phase=middlegame/positions.parquet",
|
| 58 |
+
"max_id": 1892012,
|
| 59 |
+
"min_id": 1640001,
|
| 60 |
+
"phase": "middlegame",
|
| 61 |
+
"row_groups": 3,
|
| 62 |
+
"rows": 156000,
|
| 63 |
+
"sha256": "babc921f7663d44feda792638a0fb1160af2e30963c7cd8db3dd965b9456cda0",
|
| 64 |
+
"source_split": "low"
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"bytes": 1947198,
|
| 68 |
+
"file": "source_split=low/phase=endgame/positions.parquet",
|
| 69 |
+
"max_id": 1900000,
|
| 70 |
+
"min_id": 1640008,
|
| 71 |
+
"phase": "endgame",
|
| 72 |
+
"row_groups": 1,
|
| 73 |
+
"rows": 65000,
|
| 74 |
+
"sha256": "facf4685b2e1f922ebc5b9883ae9aa4f9c00bdfd46624022e2a505f475603ac1",
|
| 75 |
+
"source_split": "low"
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"bytes": 2016352,
|
| 79 |
+
"file": "source_split=mid/phase=opening/positions.parquet",
|
| 80 |
+
"max_id": 1636511,
|
| 81 |
+
"min_id": 1200001,
|
| 82 |
+
"phase": "opening",
|
| 83 |
+
"row_groups": 2,
|
| 84 |
+
"rows": 66000,
|
| 85 |
+
"sha256": "bba32010584312b19fc5b7af297a1912c4a2bc0ed9329a8c964b67f951292177",
|
| 86 |
+
"source_split": "mid"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"bytes": 8540107,
|
| 90 |
+
"file": "source_split=mid/phase=middlegame/positions.parquet",
|
| 91 |
+
"max_id": 1621308,
|
| 92 |
+
"min_id": 1200003,
|
| 93 |
+
"phase": "middlegame",
|
| 94 |
+
"row_groups": 5,
|
| 95 |
+
"rows": 264001,
|
| 96 |
+
"sha256": "655819eb658ee1f384a7c403a930a824af875cde234024762e06d5db2027af93",
|
| 97 |
+
"source_split": "mid"
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"bytes": 3316916,
|
| 101 |
+
"file": "source_split=mid/phase=endgame/positions.parquet",
|
| 102 |
+
"max_id": 1640000,
|
| 103 |
+
"min_id": 1200025,
|
| 104 |
+
"phase": "endgame",
|
| 105 |
+
"row_groups": 2,
|
| 106 |
+
"rows": 109999,
|
| 107 |
+
"sha256": "7134f22a7fefa7b20ac16dacd459ec1f184f42b3779cb2fe091e032f822984e5",
|
| 108 |
+
"source_split": "mid"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"bytes": 5418356,
|
| 112 |
+
"file": "source_split=strong/phase=opening/positions.parquet",
|
| 113 |
+
"max_id": 1198682,
|
| 114 |
+
"min_id": 1,
|
| 115 |
+
"phase": "opening",
|
| 116 |
+
"row_groups": 3,
|
| 117 |
+
"rows": 180000,
|
| 118 |
+
"sha256": "27b6176179db7b2389a264834d42b81088b55fcea01507fdf47e44dbd3b6e91f",
|
| 119 |
+
"source_split": "strong"
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"bytes": 23599709,
|
| 123 |
+
"file": "source_split=strong/phase=middlegame/positions.parquet",
|
| 124 |
+
"max_id": 1156985,
|
| 125 |
+
"min_id": 3,
|
| 126 |
+
"phase": "middlegame",
|
| 127 |
+
"row_groups": 11,
|
| 128 |
+
"rows": 720000,
|
| 129 |
+
"sha256": "65f27ac62d7aece6f475df584319542664602ec901041474bf4a9fd67c56ffa2",
|
| 130 |
+
"source_split": "strong"
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"bytes": 9033051,
|
| 134 |
+
"file": "source_split=strong/phase=endgame/positions.parquet",
|
| 135 |
+
"max_id": 1200000,
|
| 136 |
+
"min_id": 10,
|
| 137 |
+
"phase": "endgame",
|
| 138 |
+
"row_groups": 5,
|
| 139 |
+
"rows": 300000,
|
| 140 |
+
"sha256": "a65684ee64f5824dc03d396bb3a92786fd35ae2a7fda6b06cb96733202efc11e",
|
| 141 |
+
"source_split": "strong"
|
| 142 |
+
}
|
| 143 |
+
],
|
| 144 |
+
"row_group_size": 65536,
|
| 145 |
+
"rows": 2000000,
|
| 146 |
+
"source": "/Users/pawit/Documents/vexilon/tmp/vex-position-dataset/data/lc0-selfplay-2m.vpd",
|
| 147 |
+
"source_sha256": "0cbab31284e50c75d6cdef6de7d4656e77c6ab4a3a4fb848ecf110e5a8eeb7cc"
|
| 148 |
+
}
|
lc0-selfplay-2m/source_split=early/phase=endgame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:572e45aa624e02ff34249fef5b238d3683df0b3d561ede4a809e80ad3ae801aa
|
| 3 |
+
size 752875
|
lc0-selfplay-2m/source_split=early/phase=middlegame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b7047c2783dccb7134ddac56b77688503d40d03ea396527f071928b7657bb7fb
|
| 3 |
+
size 2006400
|
lc0-selfplay-2m/source_split=early/phase=opening/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5e7177ca9393325b169ac40cb8768f7510d6c7c52b44e9b1eaed4c12ef2dc9f5
|
| 3 |
+
size 462723
|
lc0-selfplay-2m/source_split=low/phase=endgame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:facf4685b2e1f922ebc5b9883ae9aa4f9c00bdfd46624022e2a505f475603ac1
|
| 3 |
+
size 1947198
|
lc0-selfplay-2m/source_split=low/phase=middlegame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:babc921f7663d44feda792638a0fb1160af2e30963c7cd8db3dd965b9456cda0
|
| 3 |
+
size 5130153
|
lc0-selfplay-2m/source_split=low/phase=opening/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e24d3b998a74e5462046500276220dcdc72650984459657689bfc479b165d4d9
|
| 3 |
+
size 1210334
|
lc0-selfplay-2m/source_split=mid/phase=endgame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7134f22a7fefa7b20ac16dacd459ec1f184f42b3779cb2fe091e032f822984e5
|
| 3 |
+
size 3316916
|
lc0-selfplay-2m/source_split=mid/phase=middlegame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:655819eb658ee1f384a7c403a930a824af875cde234024762e06d5db2027af93
|
| 3 |
+
size 8540107
|
lc0-selfplay-2m/source_split=mid/phase=opening/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bba32010584312b19fc5b7af297a1912c4a2bc0ed9329a8c964b67f951292177
|
| 3 |
+
size 2016352
|
lc0-selfplay-2m/source_split=strong/phase=endgame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a65684ee64f5824dc03d396bb3a92786fd35ae2a7fda6b06cb96733202efc11e
|
| 3 |
+
size 9033051
|
lc0-selfplay-2m/source_split=strong/phase=middlegame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65f27ac62d7aece6f475df584319542664602ec901041474bf4a9fd67c56ffa2
|
| 3 |
+
size 23599709
|
lc0-selfplay-2m/source_split=strong/phase=opening/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:27b6176179db7b2389a264834d42b81088b55fcea01507fdf47e44dbd3b6e91f
|
| 3 |
+
size 5418356
|
lichess-elite-300k-variance.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"database": "/Users/pawit/Documents/vexilon/tmp/vex-position-dataset/data/lichess-elite-300k.vpd",
|
| 3 |
+
"database_bytes": 88457216,
|
| 4 |
+
"distributions": {
|
| 5 |
+
"in_check": 21620,
|
| 6 |
+
"material_imbalance_abs_ge_3": 55336,
|
| 7 |
+
"phase": {
|
| 8 |
+
"endgame": 75000,
|
| 9 |
+
"middlegame": 180000,
|
| 10 |
+
"opening": 45000
|
| 11 |
+
},
|
| 12 |
+
"result": {
|
| 13 |
+
"*": 3,
|
| 14 |
+
"0-1": 125395,
|
| 15 |
+
"1-0": 137641,
|
| 16 |
+
"1/2-1/2": 36961
|
| 17 |
+
},
|
| 18 |
+
"side_to_move": {
|
| 19 |
+
"black": 150799,
|
| 20 |
+
"white": 149201
|
| 21 |
+
},
|
| 22 |
+
"source_split": {
|
| 23 |
+
"human": 300000
|
| 24 |
+
},
|
| 25 |
+
"with_castling_rights": 69526,
|
| 26 |
+
"without_castling_rights": 230474
|
| 27 |
+
},
|
| 28 |
+
"format": "VPD1",
|
| 29 |
+
"high_variance": false,
|
| 30 |
+
"metadata": {
|
| 31 |
+
"completed_unix": "1787662083",
|
| 32 |
+
"corpus": "lichess-elite-human",
|
| 33 |
+
"excluded_speeds": "ultrabullet,bullet",
|
| 34 |
+
"fen_fullmove_normalization": "1",
|
| 35 |
+
"format": "VPD1",
|
| 36 |
+
"months": "[\"2020-06\", \"2020-10\", \"2021-02\", \"2021-10\", \"2022-02\", \"2022-06\", \"2023-02\", \"2023-06\", \"2023-10\", \"2024-06\", \"2025-02\", \"2025-10\"]",
|
| 37 |
+
"months_done": "[\"2020-06\", \"2020-10\", \"2021-02\", \"2021-10\", \"2022-02\", \"2022-06\", \"2023-02\", \"2023-06\", \"2023-10\", \"2024-06\", \"2025-02\", \"2025-10\"]",
|
| 38 |
+
"per_game": "3",
|
| 39 |
+
"position_count": "300000",
|
| 40 |
+
"seed": "91",
|
| 41 |
+
"source": "https://database.nikonoel.fr/",
|
| 42 |
+
"speed_mix": "{\"2020-06\": {\"blitz\": 419793, \"bullet\": 614, \"classical\": 235, \"rapid\": 4156, \"ultrabullet\": 134}, \"2020-10\": {\"blitz\": 394174, \"bullet\": 985, \"classical\": 123, \"rapid\": 7759, \"ultrabullet\": 30}, \"2021-02\": {\"blitz\": 482896, \"bullet\": 765, \"classical\": 230, \"rapid\": 22605, \"ultrabullet\": 146}, \"2021-10\": {\"blitz\": 958088, \"bullet\": 1088, \"classical\": 268, \"rapid\": 66809, \"ultrabullet\": 111}, \"2022-02\": {\"blitz\": 358362, \"bullet\": 261, \"classical\": 42, \"rapid\": 15909, \"ultrabullet\": 66}, \"2022-06\": {\"blitz\": 317872, \"bullet\": 304, \"classical\": 149, \"rapid\": 16842, \"ultrabullet\": 64}, \"2023-02\": {\"blitz\": 251068, \"classical\": 438, \"rapid\": 16001}, \"2023-06\": {\"blitz\": 269958, \"classical\": 266, \"rapid\": 20810}, \"2023-10\": {\"blitz\": 263539, \"classical\": 1913, \"rapid\": 20468}, \"2024-06\": {\"blitz\": 237026, \"bullet\": 781, \"classical\": 836, \"rapid\": 14602, \"ultrabullet\": 76}, \"2025-02\": {\"blitz\": 240625, \"bullet\": 1204, \"classical\": 905, \"rapid\": 13639, \"ultrabullet\": 57}, \"2025-10\": {\"blitz\": 262599, \"bullet\": 1641, \"classical\": 1332, \"rapid\": 15244, \"ultrabullet\": 303}}",
|
| 43 |
+
"target_positions": "300000"
|
| 44 |
+
},
|
| 45 |
+
"normalized_phase_entropy": 0.853474,
|
| 46 |
+
"numeric": {
|
| 47 |
+
"legal_moves": {
|
| 48 |
+
"max": 94,
|
| 49 |
+
"mean": 30.3457,
|
| 50 |
+
"median": 33,
|
| 51 |
+
"min": 0,
|
| 52 |
+
"p10": 11,
|
| 53 |
+
"p90": 44,
|
| 54 |
+
"stdev": 12.1602
|
| 55 |
+
},
|
| 56 |
+
"material_balance_white_minus_black": {
|
| 57 |
+
"max": 52,
|
| 58 |
+
"mean": 0.017,
|
| 59 |
+
"median": 0,
|
| 60 |
+
"min": -67,
|
| 61 |
+
"p10": -2,
|
| 62 |
+
"p90": 2,
|
| 63 |
+
"stdev": 2.6994
|
| 64 |
+
},
|
| 65 |
+
"piece_count": {
|
| 66 |
+
"max": 32,
|
| 67 |
+
"mean": 21.785,
|
| 68 |
+
"median": 23,
|
| 69 |
+
"min": 2,
|
| 70 |
+
"p10": 11,
|
| 71 |
+
"p90": 30,
|
| 72 |
+
"stdev": 7.2753
|
| 73 |
+
}
|
| 74 |
+
},
|
| 75 |
+
"positions": 300000,
|
| 76 |
+
"thresholds": {
|
| 77 |
+
"at_least_1_5m_positions": false,
|
| 78 |
+
"both_castling_states_at_least_10pct": true,
|
| 79 |
+
"checks_at_least_1pct": true,
|
| 80 |
+
"legal_move_p10_at_most_22": true,
|
| 81 |
+
"legal_move_p90_at_least_38": true,
|
| 82 |
+
"legal_move_stdev_at_least_8": true,
|
| 83 |
+
"material_imbalance_at_least_15pct": true,
|
| 84 |
+
"phase_entropy_at_least_0_85": true,
|
| 85 |
+
"phase_min_share_at_least_15pct": true,
|
| 86 |
+
"piece_count_stdev_at_least_5": true,
|
| 87 |
+
"result_min_share_at_least_20pct": false,
|
| 88 |
+
"side_to_move_between_47_and_53pct_white": true
|
| 89 |
+
}
|
| 90 |
+
}
|
lichess-elite-300k/_manifest.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compression": "zstd",
|
| 3 |
+
"compression_level": 6,
|
| 4 |
+
"elapsed_seconds": 0.794,
|
| 5 |
+
"format": "VPD1-Parquet",
|
| 6 |
+
"partitioning": [
|
| 7 |
+
"source_split",
|
| 8 |
+
"phase"
|
| 9 |
+
],
|
| 10 |
+
"partitions": [
|
| 11 |
+
{
|
| 12 |
+
"bytes": 1362411,
|
| 13 |
+
"file": "source_split=human/phase=opening/positions.parquet",
|
| 14 |
+
"max_id": 289784,
|
| 15 |
+
"min_id": 1,
|
| 16 |
+
"phase": "opening",
|
| 17 |
+
"row_groups": 1,
|
| 18 |
+
"rows": 45000,
|
| 19 |
+
"sha256": "5ff78f6b35751f46d98a387a7336a2e6aef953e3b2bdbd193bc6bdc07286becc",
|
| 20 |
+
"source_split": "human"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"bytes": 6763819,
|
| 24 |
+
"file": "source_split=human/phase=middlegame/positions.parquet",
|
| 25 |
+
"max_id": 300000,
|
| 26 |
+
"min_id": 2,
|
| 27 |
+
"phase": "middlegame",
|
| 28 |
+
"row_groups": 3,
|
| 29 |
+
"rows": 180000,
|
| 30 |
+
"sha256": "c470e9a3126c03a8af0001dbb567e6da9aae52c11a75439563f309404bb3cd82",
|
| 31 |
+
"source_split": "human"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"bytes": 2466867,
|
| 35 |
+
"file": "source_split=human/phase=endgame/positions.parquet",
|
| 36 |
+
"max_id": 295912,
|
| 37 |
+
"min_id": 3,
|
| 38 |
+
"phase": "endgame",
|
| 39 |
+
"row_groups": 2,
|
| 40 |
+
"rows": 75000,
|
| 41 |
+
"sha256": "f6f821171a524c53412c592e2546f6d8d9eb6dc4259b401246f0b5f7ac7311f7",
|
| 42 |
+
"source_split": "human"
|
| 43 |
+
}
|
| 44 |
+
],
|
| 45 |
+
"row_group_size": 65536,
|
| 46 |
+
"rows": 300000,
|
| 47 |
+
"source": "/Users/pawit/Documents/vexilon/tmp/vex-position-dataset/data/lichess-elite-300k.vpd",
|
| 48 |
+
"source_sha256": "87c00d3e4b3c9387b7f71097f2b1826e6ad6c994ae8df24f267de400814e27f9"
|
| 49 |
+
}
|
lichess-elite-300k/source_split=human/phase=endgame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f6f821171a524c53412c592e2546f6d8d9eb6dc4259b401246f0b5f7ac7311f7
|
| 3 |
+
size 2466867
|
lichess-elite-300k/source_split=human/phase=middlegame/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c470e9a3126c03a8af0001dbb567e6da9aae52c11a75439563f309404bb3cd82
|
| 3 |
+
size 6763819
|
lichess-elite-300k/source_split=human/phase=opening/positions.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5ff78f6b35751f46d98a387a7336a2e6aef953e3b2bdbd193bc6bdc07286becc
|
| 3 |
+
size 1362411
|
scripts/build_human_corpus.py
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build the human partition of the corpus from the Lichess Elite Database.
|
| 2 |
+
|
| 3 |
+
The Elite Database is the Lichess standard database filtered to games where a
|
| 4 |
+
2400+ player faced a 2200+ player. It is published as one zip per month at
|
| 5 |
+
database.nikonoel.fr.
|
| 6 |
+
|
| 7 |
+
Composition, measured on 2025-08: about 88% of games are 3+0 or 3+2 blitz, 6%
|
| 8 |
+
rapid, under 1% classical, with White Elo median 2550 and a maximum of 3215.
|
| 9 |
+
The partition is therefore strong human blitz, not considered classical play.
|
| 10 |
+
That is a real characteristic rather than a defect for this corpus: the point of
|
| 11 |
+
a human partition is positions engines do not reach, and human blitz reaches
|
| 12 |
+
plenty. It is recorded in the database metadata so it is never a surprise.
|
| 13 |
+
Games below --min-base-seconds are dropped, which removes bullet.
|
| 14 |
+
|
| 15 |
+
Sampling is two-phase per month. chess.pgn.read_headers skips move text and runs
|
| 16 |
+
at about 75,000 games/s, against 1,300 for a full parse, so the whole month is
|
| 17 |
+
indexed by byte offset first and only the games actually selected are parsed.
|
| 18 |
+
That keeps selection uniform over games — sampling by byte offset instead would
|
| 19 |
+
have favoured long games — while costing seconds rather than minutes.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
from __future__ import annotations
|
| 23 |
+
|
| 24 |
+
import argparse
|
| 25 |
+
import collections
|
| 26 |
+
import hashlib
|
| 27 |
+
import json
|
| 28 |
+
import random
|
| 29 |
+
import re
|
| 30 |
+
import shutil
|
| 31 |
+
import subprocess
|
| 32 |
+
import sys
|
| 33 |
+
import tempfile
|
| 34 |
+
import time
|
| 35 |
+
import zipfile
|
| 36 |
+
from pathlib import Path
|
| 37 |
+
|
| 38 |
+
import chess
|
| 39 |
+
import chess.pgn
|
| 40 |
+
|
| 41 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "vex-position-dataset"))
|
| 42 |
+
from vpd import ( # noqa: E402
|
| 43 |
+
PHASE_NAMES,
|
| 44 |
+
connect,
|
| 45 |
+
initialize,
|
| 46 |
+
make_quotas,
|
| 47 |
+
phase_of,
|
| 48 |
+
position_record,
|
| 49 |
+
set_metadata,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
from build_selfplay_corpus import INSERT_SQL, spread # noqa: E402
|
| 53 |
+
|
| 54 |
+
BASE = "https://database.nikonoel.fr"
|
| 55 |
+
MONTH = re.compile(r"lichess_elite_(\d{4}-\d{2})\.zip")
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def list_months() -> list[str]:
|
| 59 |
+
out = subprocess.run(
|
| 60 |
+
["curl", "-sS", "--max-time", "120", f"{BASE}/"], capture_output=True, text=True
|
| 61 |
+
)
|
| 62 |
+
return sorted(set(MONTH.findall(out.stdout)))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
SPEEDS = ("ultrabullet", "bullet", "blitz", "rapid", "classical", "correspondence")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def base_seconds(time_control: str) -> int:
|
| 69 |
+
"""Seconds on the clock before increment; 0 when unparseable."""
|
| 70 |
+
|
| 71 |
+
head = (time_control or "").split("+")[0]
|
| 72 |
+
return int(head) if head.isdigit() else 0
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def speed_category(headers) -> str:
|
| 76 |
+
"""Classify a game's speed from whichever headers the month provides.
|
| 77 |
+
|
| 78 |
+
The Elite Database changed schema partway through its history. Months from
|
| 79 |
+
2025 carry TimeControl, LichessURL and UTCDate; older months instead carry
|
| 80 |
+
EventType and PlyCount and no TimeControl at all. Reading only TimeControl
|
| 81 |
+
silently rejects every game in the older format, so all three sources are
|
| 82 |
+
tried and anything still unrecognised is kept rather than dropped.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
base = base_seconds(headers.get("TimeControl", ""))
|
| 86 |
+
if base:
|
| 87 |
+
if base < 60:
|
| 88 |
+
return "ultrabullet"
|
| 89 |
+
if base < 180:
|
| 90 |
+
return "bullet"
|
| 91 |
+
if base < 480:
|
| 92 |
+
return "blitz"
|
| 93 |
+
if base < 1500:
|
| 94 |
+
return "rapid"
|
| 95 |
+
return "classical"
|
| 96 |
+
event_type = headers.get("EventType", "").strip().lower()
|
| 97 |
+
if event_type in SPEEDS:
|
| 98 |
+
return event_type
|
| 99 |
+
event = headers.get("Event", "").lower()
|
| 100 |
+
for name in SPEEDS:
|
| 101 |
+
if name in event:
|
| 102 |
+
return name
|
| 103 |
+
return "unknown"
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def index_month(pgn: Path, excluded: frozenset[str]) -> tuple[list[int], collections.Counter]:
|
| 107 |
+
"""Byte offsets of every eligible game, plus the speed mix."""
|
| 108 |
+
|
| 109 |
+
offsets: list[int] = []
|
| 110 |
+
mix: collections.Counter = collections.Counter()
|
| 111 |
+
# utf-8-sig: some months begin with a byte order mark.
|
| 112 |
+
with open(pgn, encoding="utf-8-sig", errors="replace") as handle:
|
| 113 |
+
while True:
|
| 114 |
+
offset = handle.tell()
|
| 115 |
+
headers = chess.pgn.read_headers(handle)
|
| 116 |
+
if headers is None:
|
| 117 |
+
break
|
| 118 |
+
speed = speed_category(headers)
|
| 119 |
+
mix[speed] += 1
|
| 120 |
+
if speed not in excluded:
|
| 121 |
+
offsets.append(offset)
|
| 122 |
+
return offsets, mix
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def sample_positions(
|
| 126 |
+
game: chess.pgn.Game,
|
| 127 |
+
per_game: int,
|
| 128 |
+
counts: dict[int, int],
|
| 129 |
+
phase_quotas: dict[int, int],
|
| 130 |
+
rng: random.Random,
|
| 131 |
+
) -> list[tuple[chess.Board, int, int, str]]:
|
| 132 |
+
"""Reservoir one position per phase, as the CCRL extractor does."""
|
| 133 |
+
|
| 134 |
+
board = game.board()
|
| 135 |
+
reservoir: dict[int, tuple[chess.Board, int]] = {}
|
| 136 |
+
seen = {phase: 0 for phase in PHASE_NAMES}
|
| 137 |
+
try:
|
| 138 |
+
for ply, move in enumerate(game.mainline_moves(), start=1):
|
| 139 |
+
board.push(move)
|
| 140 |
+
phase = phase_of(board, ply)
|
| 141 |
+
if counts[phase] >= phase_quotas[phase]:
|
| 142 |
+
continue
|
| 143 |
+
seen[phase] += 1
|
| 144 |
+
if rng.randrange(seen[phase]) == 0:
|
| 145 |
+
reservoir[phase] = (board.copy(stack=False), ply)
|
| 146 |
+
except (ValueError, AssertionError):
|
| 147 |
+
return []
|
| 148 |
+
|
| 149 |
+
result = game.headers.get("Result", "*")
|
| 150 |
+
picks = [(b, phase, ply, result) for phase, (b, ply) in reservoir.items()]
|
| 151 |
+
rng.shuffle(picks)
|
| 152 |
+
return picks[:per_game]
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def process_month(
|
| 156 |
+
db, month: str, counts: dict[int, int], phase_quotas: dict[int, int],
|
| 157 |
+
quota: int, per_game: int, excluded: frozenset[str], seed: int, scratch: Path,
|
| 158 |
+
) -> dict[str, object]:
|
| 159 |
+
stats: dict[str, object] = {"games": 0, "inserted": 0, "eligible": 0, "mix": {}}
|
| 160 |
+
workdir = Path(tempfile.mkdtemp(prefix="elite.", dir=scratch))
|
| 161 |
+
try:
|
| 162 |
+
archive = workdir / f"{month}.zip"
|
| 163 |
+
subprocess.run(
|
| 164 |
+
["curl", "-fsS", "--max-time", "1800", f"{BASE}/lichess_elite_{month}.zip",
|
| 165 |
+
"-o", str(archive)],
|
| 166 |
+
capture_output=True,
|
| 167 |
+
)
|
| 168 |
+
if not archive.exists() or archive.stat().st_size < 1_000_000:
|
| 169 |
+
return stats
|
| 170 |
+
with zipfile.ZipFile(archive) as zf:
|
| 171 |
+
name = zf.namelist()[0]
|
| 172 |
+
pgn = workdir / name
|
| 173 |
+
with zf.open(name) as src, open(pgn, "wb") as dst:
|
| 174 |
+
shutil.copyfileobj(src, dst, 1 << 20)
|
| 175 |
+
archive.unlink()
|
| 176 |
+
|
| 177 |
+
offsets, mix = index_month(pgn, excluded)
|
| 178 |
+
stats["eligible"] = len(offsets)
|
| 179 |
+
stats["mix"] = dict(mix.most_common())
|
| 180 |
+
if not offsets:
|
| 181 |
+
return stats
|
| 182 |
+
|
| 183 |
+
rng = random.Random(
|
| 184 |
+
int.from_bytes(
|
| 185 |
+
hashlib.blake2b(f"{seed}:{month}".encode(), digest_size=8).digest(), "big"
|
| 186 |
+
)
|
| 187 |
+
)
|
| 188 |
+
rng.shuffle(offsets)
|
| 189 |
+
|
| 190 |
+
with open(pgn, encoding="utf-8-sig", errors="replace") as handle:
|
| 191 |
+
for offset in offsets:
|
| 192 |
+
if sum(counts.values()) >= quota:
|
| 193 |
+
break
|
| 194 |
+
handle.seek(offset)
|
| 195 |
+
game = chess.pgn.read_game(handle)
|
| 196 |
+
if game is None:
|
| 197 |
+
continue
|
| 198 |
+
stats["games"] += 1
|
| 199 |
+
picks = sample_positions(game, per_game, counts, phase_quotas, rng)
|
| 200 |
+
for board, phase, ply, result in picks:
|
| 201 |
+
cursor = db.execute(
|
| 202 |
+
INSERT_SQL,
|
| 203 |
+
position_record(
|
| 204 |
+
board, "human", f"lichess-elite/{month}",
|
| 205 |
+
stats["games"], ply, result, phase,
|
| 206 |
+
),
|
| 207 |
+
)
|
| 208 |
+
if cursor.rowcount:
|
| 209 |
+
counts[phase] += 1
|
| 210 |
+
stats["inserted"] = int(stats["inserted"]) + 1
|
| 211 |
+
finally:
|
| 212 |
+
shutil.rmtree(workdir, ignore_errors=True)
|
| 213 |
+
return stats
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def main() -> None:
|
| 217 |
+
parser = argparse.ArgumentParser(
|
| 218 |
+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
|
| 219 |
+
)
|
| 220 |
+
parser.add_argument("--output", required=True, type=Path)
|
| 221 |
+
parser.add_argument("--target", type=int, default=300_000)
|
| 222 |
+
parser.add_argument("--per-game", type=int, default=3)
|
| 223 |
+
parser.add_argument("--months", type=int, default=12)
|
| 224 |
+
parser.add_argument("--exclude-speeds", default="ultrabullet,bullet",
|
| 225 |
+
help="comma-separated speeds to drop; empty keeps everything")
|
| 226 |
+
parser.add_argument("--seed", type=int, default=91)
|
| 227 |
+
parser.add_argument("--scratch", type=Path, default=Path(tempfile.gettempdir()))
|
| 228 |
+
parser.add_argument("--dry-run", action="store_true")
|
| 229 |
+
args = parser.parse_args()
|
| 230 |
+
|
| 231 |
+
excluded = frozenset(x.strip() for x in args.exclude_speeds.split(",") if x.strip())
|
| 232 |
+
available = list_months()
|
| 233 |
+
if not available:
|
| 234 |
+
sys.exit("Could not list months from database.nikonoel.fr")
|
| 235 |
+
chosen = sorted(available[i] for i in spread(len(available))[: args.months])
|
| 236 |
+
print(f"{len(available)} months available ({available[0]} .. {available[-1]})")
|
| 237 |
+
print(f"Using {len(chosen)}: {', '.join(chosen)}")
|
| 238 |
+
print(f"Target {args.target:,} positions, {args.per_game} per game, "
|
| 239 |
+
f"excluding {sorted(excluded) or ['nothing']}")
|
| 240 |
+
if args.dry_run:
|
| 241 |
+
return
|
| 242 |
+
|
| 243 |
+
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 244 |
+
db = connect(args.output)
|
| 245 |
+
initialize(db)
|
| 246 |
+
set_metadata(db, "corpus", "lichess-elite-human")
|
| 247 |
+
set_metadata(db, "source", f"{BASE}/")
|
| 248 |
+
set_metadata(db, "target_positions", args.target)
|
| 249 |
+
set_metadata(db, "seed", args.seed)
|
| 250 |
+
set_metadata(db, "per_game", args.per_game)
|
| 251 |
+
set_metadata(db, "excluded_speeds", args.exclude_speeds)
|
| 252 |
+
set_metadata(db, "months", json.dumps(chosen))
|
| 253 |
+
db.commit()
|
| 254 |
+
|
| 255 |
+
counts = {
|
| 256 |
+
p: db.execute("SELECT COUNT(*) FROM positions WHERE phase=?", (p,)).fetchone()[0]
|
| 257 |
+
for p in PHASE_NAMES
|
| 258 |
+
}
|
| 259 |
+
done_row = db.execute("SELECT value FROM metadata WHERE key='months_done'").fetchone()
|
| 260 |
+
months_done = set(json.loads(done_row[0])) if done_row else set()
|
| 261 |
+
mixes: dict[str, dict] = {}
|
| 262 |
+
started = time.monotonic()
|
| 263 |
+
|
| 264 |
+
# Each month gets an equal share, otherwise the first month alone fills the
|
| 265 |
+
# target and the spread across the database's history never happens.
|
| 266 |
+
for index, month in enumerate(chosen, start=1):
|
| 267 |
+
if sum(counts.values()) >= args.target or month in months_done:
|
| 268 |
+
continue
|
| 269 |
+
cumulative = min(args.target, round(args.target * index / len(chosen)))
|
| 270 |
+
stats = process_month(
|
| 271 |
+
db, month, counts, make_quotas(cumulative), cumulative, args.per_game,
|
| 272 |
+
excluded, args.seed, args.scratch,
|
| 273 |
+
)
|
| 274 |
+
mixes[month] = stats["mix"]
|
| 275 |
+
months_done.add(month)
|
| 276 |
+
set_metadata(db, "months_done", json.dumps(sorted(months_done)))
|
| 277 |
+
set_metadata(db, "speed_mix", json.dumps(mixes, sort_keys=True))
|
| 278 |
+
db.commit()
|
| 279 |
+
print(
|
| 280 |
+
f" {month} eligible={stats['eligible']:>7,} read={stats['games']:>7,} "
|
| 281 |
+
f"+{stats['inserted']:>6,} -> {sum(counts.values()):,}/{args.target:,} "
|
| 282 |
+
f"[{(time.monotonic() - started) / 60:.1f}m]",
|
| 283 |
+
flush=True,
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
total = db.execute("SELECT COUNT(*) FROM positions").fetchone()[0]
|
| 287 |
+
set_metadata(db, "position_count", total)
|
| 288 |
+
set_metadata(db, "completed_unix", int(time.time()))
|
| 289 |
+
db.commit()
|
| 290 |
+
print(f"\nWrote {total:,} positions to {args.output}")
|
| 291 |
+
for phase, count in db.execute(
|
| 292 |
+
"SELECT phase, COUNT(*) FROM positions GROUP BY phase ORDER BY phase"
|
| 293 |
+
):
|
| 294 |
+
print(f" {PHASE_NAMES[phase]:11} {count:>8,}")
|
| 295 |
+
db.close()
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
if __name__ == "__main__":
|
| 299 |
+
main()
|
scripts/build_selfplay_corpus.py
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build a tiered lc0 self-play position corpus as a VPD1 database.
|
| 2 |
+
|
| 3 |
+
For every run slice named in lc0_runs.TIERS this streams a bounded prefix of
|
| 4 |
+
several tars, converts them to FENs through the rescorer, samples a few
|
| 5 |
+
positions per game, and inserts them into the same VPD1 schema the CCRL corpus
|
| 6 |
+
uses, so the two are directly comparable.
|
| 7 |
+
|
| 8 |
+
Two choices are worth stating.
|
| 9 |
+
|
| 10 |
+
Tars are read as bounded prefixes rather than in full. Positions cost the same
|
| 11 |
+
number of bytes either way, but a prefix of each of forty tars spans forty
|
| 12 |
+
points in a run's history, where four whole tars span four. Network diversity
|
| 13 |
+
per byte downloaded is much better, and it is the diversity that this corpus is
|
| 14 |
+
for.
|
| 15 |
+
|
| 16 |
+
Only a few positions per game are kept. A game contributes about 110 positions,
|
| 17 |
+
and consecutive ones are near-duplicates; sampling across phases keeps the
|
| 18 |
+
effective sample size close to the row count. The CCRL corpus took three per
|
| 19 |
+
game. Eight is the default here because these tars must be downloaded rather
|
| 20 |
+
than read from a local archive, and eight cuts the download roughly fourfold
|
| 21 |
+
for positions that are still tens of plies apart.
|
| 22 |
+
|
| 23 |
+
Nothing is dropped for being hard to train on. Chess960 positions are dropped
|
| 24 |
+
by default only because their Shredder-FEN castling fields are not standard
|
| 25 |
+
chess and the rest of this pipeline assumes standard chess; pass
|
| 26 |
+
--keep-chess960 to retain them.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
from __future__ import annotations
|
| 30 |
+
|
| 31 |
+
import argparse
|
| 32 |
+
import hashlib
|
| 33 |
+
import json
|
| 34 |
+
import random
|
| 35 |
+
import re
|
| 36 |
+
import shutil
|
| 37 |
+
import subprocess
|
| 38 |
+
import sys
|
| 39 |
+
import tempfile
|
| 40 |
+
import time
|
| 41 |
+
from pathlib import Path
|
| 42 |
+
|
| 43 |
+
import chess
|
| 44 |
+
|
| 45 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "vex-position-dataset"))
|
| 46 |
+
from vpd import ( # noqa: E402
|
| 47 |
+
PHASE_NAMES,
|
| 48 |
+
connect,
|
| 49 |
+
current_counts,
|
| 50 |
+
initialize,
|
| 51 |
+
make_quotas,
|
| 52 |
+
phase_of,
|
| 53 |
+
position_record,
|
| 54 |
+
set_metadata,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
from lc0_runs import EXCLUDED, TIERS, quotas, run_quotas # noqa: E402
|
| 58 |
+
|
| 59 |
+
BASE = "https://storage.lczero.org/files/training_data"
|
| 60 |
+
LISTING_ROW = re.compile(r'href="([^"]+\.tar)">[^<]*</a>\s+(\S+)\s+(\S+)\s+(\d+)')
|
| 61 |
+
STANDARD_CASTLING = set("KQkq-")
|
| 62 |
+
MIN_REAL_TAR = 50_000_000
|
| 63 |
+
|
| 64 |
+
INSERT_SQL = """
|
| 65 |
+
INSERT OR IGNORE INTO positions(
|
| 66 |
+
random_key, fen, source_split, source_member, game_number, ply,
|
| 67 |
+
result, side_to_move, phase, piece_count, non_pawn_material,
|
| 68 |
+
material_balance, legal_moves, in_check, castling_mask, halfmove_clock
|
| 69 |
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def spread(count: int) -> list[int]:
|
| 74 |
+
"""Indices 0..count-1 ordered so that any prefix is spread over the range.
|
| 75 |
+
|
| 76 |
+
Van der Corput: reversing the bits of successive integers visits the range
|
| 77 |
+
at ever finer resolution, so stopping early still leaves the tars taken
|
| 78 |
+
scattered across the run's history rather than clustered at one end.
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
if count <= 0:
|
| 82 |
+
return []
|
| 83 |
+
bits = max(1, (count - 1).bit_length())
|
| 84 |
+
seen: list[int] = []
|
| 85 |
+
used = set()
|
| 86 |
+
for i in range(1 << bits):
|
| 87 |
+
reversed_bits = int(format(i, f"0{bits}b")[::-1], 2)
|
| 88 |
+
if reversed_bits < count and reversed_bits not in used:
|
| 89 |
+
used.add(reversed_bits)
|
| 90 |
+
seen.append(reversed_bits)
|
| 91 |
+
return seen
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def list_tars(run: str, cache: dict[str, list[tuple[str, int]]]) -> list[tuple[str, int]]:
|
| 95 |
+
if run in cache:
|
| 96 |
+
return cache[run]
|
| 97 |
+
out = subprocess.run(
|
| 98 |
+
["curl", "-sS", "--max-time", "180", f"{BASE}/{run}/"],
|
| 99 |
+
capture_output=True,
|
| 100 |
+
text=True,
|
| 101 |
+
)
|
| 102 |
+
rows = [
|
| 103 |
+
(name, int(size))
|
| 104 |
+
for name, _, _, size in LISTING_ROW.findall(out.stdout)
|
| 105 |
+
if int(size) >= MIN_REAL_TAR
|
| 106 |
+
]
|
| 107 |
+
cache[run] = rows
|
| 108 |
+
return rows
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def fetch_prefix(run: str, tar: str, limit: int, destination: Path) -> int:
|
| 112 |
+
"""Download at most `limit` bytes of a tar.
|
| 113 |
+
|
| 114 |
+
head closes the socket once it has enough, which the CDN honours where it
|
| 115 |
+
ignores Range requests.
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
command = (
|
| 119 |
+
f'curl -sS --max-time 900 "{BASE}/{run}/{tar}" | head -c {limit} > "{destination}"'
|
| 120 |
+
)
|
| 121 |
+
subprocess.run(command, shell=True, capture_output=True)
|
| 122 |
+
return destination.stat().st_size if destination.exists() else 0
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def to_plain(rescorer: Path, tar_path: Path, workdir: Path, threads: int) -> Path | None:
|
| 126 |
+
subprocess.run(["tar", "xf", str(tar_path), "-C", str(workdir)], capture_output=True)
|
| 127 |
+
chunks = list(workdir.rglob("*.gz"))
|
| 128 |
+
if not chunks:
|
| 129 |
+
return None
|
| 130 |
+
plain = workdir / "positions.plain"
|
| 131 |
+
subprocess.run(
|
| 132 |
+
[
|
| 133 |
+
str(rescorer),
|
| 134 |
+
"rescore",
|
| 135 |
+
f"--input={chunks[0].parent}",
|
| 136 |
+
"--no-delete-files",
|
| 137 |
+
f"--nnue-plain-file={plain}",
|
| 138 |
+
"--nnue-best-score=true",
|
| 139 |
+
"--nnue-best-move=true",
|
| 140 |
+
"--deblunder=false",
|
| 141 |
+
f"--threads={threads}",
|
| 142 |
+
],
|
| 143 |
+
capture_output=True,
|
| 144 |
+
text=True,
|
| 145 |
+
)
|
| 146 |
+
return plain if plain.exists() else None
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def games(plain: Path):
|
| 150 |
+
"""Yield (fen, ply, result) lists, one per game.
|
| 151 |
+
|
| 152 |
+
The rescorer appends games back to back and restarts ply at zero for each,
|
| 153 |
+
so a non-increasing ply is a game boundary.
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
+
current: list[tuple[str, int, str]] = []
|
| 157 |
+
fen = None
|
| 158 |
+
ply = None
|
| 159 |
+
last_ply = None
|
| 160 |
+
with open(plain, encoding="utf-8", errors="replace") as handle:
|
| 161 |
+
for row in handle:
|
| 162 |
+
if row.startswith("fen "):
|
| 163 |
+
fen = row[4:].strip()
|
| 164 |
+
elif row.startswith("ply "):
|
| 165 |
+
ply = int(row[4:])
|
| 166 |
+
elif row.startswith("result "):
|
| 167 |
+
result = row[7:].strip()
|
| 168 |
+
elif row.startswith("e") and row.strip() == "e":
|
| 169 |
+
if fen is None or ply is None:
|
| 170 |
+
continue
|
| 171 |
+
if last_ply is not None and ply <= last_ply and current:
|
| 172 |
+
yield current
|
| 173 |
+
current = []
|
| 174 |
+
current.append((fen, ply, result))
|
| 175 |
+
last_ply = ply
|
| 176 |
+
fen = ply = None
|
| 177 |
+
if current:
|
| 178 |
+
yield current
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def absolute_result(plain_result: str, white_to_move: bool) -> str:
|
| 182 |
+
"""Convert a .plain result to the PGN string VPD1 stores.
|
| 183 |
+
|
| 184 |
+
Stockfish's plain format reports the game outcome from the side to move's
|
| 185 |
+
perspective as 1/0/-1. VPD1 stores an absolute PGN result, as the CCRL
|
| 186 |
+
corpus does, so the two are comparable and vpd.py analyze can read them.
|
| 187 |
+
"""
|
| 188 |
+
|
| 189 |
+
try:
|
| 190 |
+
value = int(plain_result)
|
| 191 |
+
except (TypeError, ValueError):
|
| 192 |
+
return "*"
|
| 193 |
+
if value == 0:
|
| 194 |
+
return "1/2-1/2"
|
| 195 |
+
white_won = (value > 0) == white_to_move
|
| 196 |
+
return "1-0" if white_won else "0-1"
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def sample_game(
|
| 200 |
+
positions: list[tuple[str, int, str]],
|
| 201 |
+
per_game: int,
|
| 202 |
+
counts: dict[int, int],
|
| 203 |
+
phase_quotas: dict[int, int],
|
| 204 |
+
rng: random.Random,
|
| 205 |
+
keep_chess960: bool,
|
| 206 |
+
) -> list[tuple[chess.Board, int, int, str]]:
|
| 207 |
+
"""Pick a spread of positions from one game, respecting phase quotas."""
|
| 208 |
+
|
| 209 |
+
by_phase: dict[int, list[tuple[chess.Board, int, str]]] = {p: [] for p in PHASE_NAMES}
|
| 210 |
+
for fen, ply, result in positions:
|
| 211 |
+
if not keep_chess960 and not set(fen.split(" ")[2]) <= STANDARD_CASTLING:
|
| 212 |
+
continue
|
| 213 |
+
try:
|
| 214 |
+
board = chess.Board(fen)
|
| 215 |
+
except ValueError:
|
| 216 |
+
continue
|
| 217 |
+
by_phase[phase_of(board, ply)].append((board, ply, result))
|
| 218 |
+
|
| 219 |
+
# Split the per-game budget in the same 15/60/25 proportion as the corpus
|
| 220 |
+
# quota. Taking an equal count from each phase instead saturates the small
|
| 221 |
+
# opening quota long before the others, after which most of a downloaded
|
| 222 |
+
# game is discarded.
|
| 223 |
+
total_quota = sum(phase_quotas.values()) or 1
|
| 224 |
+
chosen: list[tuple[chess.Board, int, int, str]] = []
|
| 225 |
+
for phase, available in by_phase.items():
|
| 226 |
+
if not available or counts[phase] >= phase_quotas[phase]:
|
| 227 |
+
continue
|
| 228 |
+
wanted = max(1, round(per_game * phase_quotas[phase] / total_quota))
|
| 229 |
+
take = min(wanted, len(available), phase_quotas[phase] - counts[phase])
|
| 230 |
+
for board, ply, result in rng.sample(available, take):
|
| 231 |
+
chosen.append((board, phase, ply, result))
|
| 232 |
+
return chosen
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def process_tar(
|
| 236 |
+
db,
|
| 237 |
+
rescorer: Path,
|
| 238 |
+
run: str,
|
| 239 |
+
tar: str,
|
| 240 |
+
tier: str,
|
| 241 |
+
limit: int,
|
| 242 |
+
threads: int,
|
| 243 |
+
per_game: int,
|
| 244 |
+
counts: dict[int, int],
|
| 245 |
+
phase_quotas: dict[int, int],
|
| 246 |
+
seed: int,
|
| 247 |
+
keep_chess960: bool,
|
| 248 |
+
scratch: Path,
|
| 249 |
+
) -> dict[str, int]:
|
| 250 |
+
stats = {"bytes": 0, "games": 0, "inserted": 0, "chess960": 0}
|
| 251 |
+
workdir = Path(tempfile.mkdtemp(prefix="lc0tar.", dir=scratch))
|
| 252 |
+
try:
|
| 253 |
+
tar_path = workdir / "prefix.tar"
|
| 254 |
+
stats["bytes"] = fetch_prefix(run, tar, limit, tar_path)
|
| 255 |
+
if stats["bytes"] < 100_000:
|
| 256 |
+
return stats
|
| 257 |
+
plain = to_plain(rescorer, tar_path, workdir, threads)
|
| 258 |
+
if plain is None:
|
| 259 |
+
return stats
|
| 260 |
+
tar_path.unlink(missing_ok=True)
|
| 261 |
+
|
| 262 |
+
for game_number, positions in enumerate(games(plain), start=1):
|
| 263 |
+
stats["games"] += 1
|
| 264 |
+
stats["chess960"] += sum(
|
| 265 |
+
not set(f.split(" ")[2]) <= STANDARD_CASTLING for f, _, _ in positions
|
| 266 |
+
)
|
| 267 |
+
rng = random.Random(
|
| 268 |
+
int.from_bytes(
|
| 269 |
+
hashlib.blake2b(
|
| 270 |
+
f"{seed}:{tar}:{game_number}".encode(), digest_size=8
|
| 271 |
+
).digest(),
|
| 272 |
+
"big",
|
| 273 |
+
)
|
| 274 |
+
)
|
| 275 |
+
for board, phase, ply, result in sample_game(
|
| 276 |
+
positions, per_game, counts, phase_quotas, rng, keep_chess960
|
| 277 |
+
):
|
| 278 |
+
cursor = db.execute(
|
| 279 |
+
INSERT_SQL,
|
| 280 |
+
position_record(
|
| 281 |
+
board, tier, f"{run}/{tar}", game_number, ply,
|
| 282 |
+
absolute_result(result, board.turn == chess.WHITE), phase,
|
| 283 |
+
),
|
| 284 |
+
)
|
| 285 |
+
if cursor.rowcount:
|
| 286 |
+
counts[phase] += 1
|
| 287 |
+
stats["inserted"] += 1
|
| 288 |
+
if all(counts[p] >= phase_quotas[p] for p in phase_quotas):
|
| 289 |
+
break
|
| 290 |
+
finally:
|
| 291 |
+
shutil.rmtree(workdir, ignore_errors=True)
|
| 292 |
+
return stats
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def main() -> None:
|
| 296 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 297 |
+
parser.add_argument("--output", required=True, type=Path)
|
| 298 |
+
parser.add_argument("--target", type=int, default=2_000_000)
|
| 299 |
+
parser.add_argument("--per-game", type=int, default=12)
|
| 300 |
+
parser.add_argument("--slice-bytes", type=int, default=120_000_000)
|
| 301 |
+
parser.add_argument("--threads", type=int, default=8)
|
| 302 |
+
parser.add_argument("--seed", type=int, default=91)
|
| 303 |
+
parser.add_argument("--keep-chess960", action="store_true")
|
| 304 |
+
parser.add_argument("--scratch", type=Path, default=Path(tempfile.gettempdir()))
|
| 305 |
+
parser.add_argument(
|
| 306 |
+
"--rescorer",
|
| 307 |
+
type=Path,
|
| 308 |
+
default=Path(__file__).resolve().parent.parent / "lc0-rescorer/build/release/rescorer",
|
| 309 |
+
)
|
| 310 |
+
parser.add_argument("--dry-run", action="store_true", help="show the plan and exit")
|
| 311 |
+
args = parser.parse_args()
|
| 312 |
+
|
| 313 |
+
if not args.rescorer.exists():
|
| 314 |
+
sys.exit(f"No rescorer at {args.rescorer}")
|
| 315 |
+
|
| 316 |
+
tier_quota = quotas(args.target)
|
| 317 |
+
plan: list[tuple[str, str, float, float, int]] = []
|
| 318 |
+
for tier in TIERS:
|
| 319 |
+
for key, quota in run_quotas(tier, tier_quota[tier.name]).items():
|
| 320 |
+
name, window = key.split(":")
|
| 321 |
+
first, last = (float(x) for x in window.split("-"))
|
| 322 |
+
plan.append((tier.name, name, first, last, quota))
|
| 323 |
+
|
| 324 |
+
print("Excluded runs:")
|
| 325 |
+
for name, why in EXCLUDED.items():
|
| 326 |
+
print(f" {name:9} {why}")
|
| 327 |
+
print(f"\nTarget {args.target:,} positions, {args.per_game} per game, "
|
| 328 |
+
f"{args.slice_bytes / 1e6:.0f} MB per tar\n")
|
| 329 |
+
for tier, run, first, last, quota in plan:
|
| 330 |
+
print(f" {tier:7} {run:9} [{first:.2f}-{last:.2f}] {quota:>9,}")
|
| 331 |
+
if args.dry_run:
|
| 332 |
+
return
|
| 333 |
+
|
| 334 |
+
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 335 |
+
db = connect(args.output)
|
| 336 |
+
initialize(db)
|
| 337 |
+
set_metadata(db, "corpus", "lc0-selfplay-tiered")
|
| 338 |
+
set_metadata(db, "source", BASE)
|
| 339 |
+
set_metadata(db, "target_positions", args.target)
|
| 340 |
+
set_metadata(db, "seed", args.seed)
|
| 341 |
+
set_metadata(db, "per_game", args.per_game)
|
| 342 |
+
set_metadata(db, "slice_bytes", args.slice_bytes)
|
| 343 |
+
set_metadata(db, "keep_chess960", int(args.keep_chess960))
|
| 344 |
+
set_metadata(db, "excluded_runs", json.dumps(EXCLUDED, sort_keys=True))
|
| 345 |
+
set_metadata(db, "tier_quotas", json.dumps(tier_quota, sort_keys=True))
|
| 346 |
+
db.commit()
|
| 347 |
+
|
| 348 |
+
done_row = db.execute("SELECT value FROM metadata WHERE key='tars_done'").fetchone()
|
| 349 |
+
tars_done = set(json.loads(done_row[0])) if done_row else set()
|
| 350 |
+
|
| 351 |
+
listing_cache: dict[str, list[tuple[str, int]]] = {}
|
| 352 |
+
started = time.monotonic()
|
| 353 |
+
|
| 354 |
+
for tier, run, first, last, quota in plan:
|
| 355 |
+
have = db.execute(
|
| 356 |
+
"SELECT COUNT(*) FROM positions WHERE source_split=? AND source_member LIKE ?",
|
| 357 |
+
(tier, f"{run}/%"),
|
| 358 |
+
).fetchone()[0]
|
| 359 |
+
if have >= quota:
|
| 360 |
+
print(f"[{tier}/{run}] already at {have:,}/{quota:,}")
|
| 361 |
+
continue
|
| 362 |
+
|
| 363 |
+
tars = list_tars(run, listing_cache)
|
| 364 |
+
window = tars[int(len(tars) * first) : max(int(len(tars) * last), 1)]
|
| 365 |
+
if not window:
|
| 366 |
+
print(f"[{tier}/{run}] no tars in window", file=sys.stderr)
|
| 367 |
+
continue
|
| 368 |
+
|
| 369 |
+
# Phase quotas are scoped to this run slice so each contributes the same
|
| 370 |
+
# opening/middlegame/endgame mix as the CCRL corpus.
|
| 371 |
+
base = {
|
| 372 |
+
p: db.execute(
|
| 373 |
+
"SELECT COUNT(*) FROM positions WHERE source_split=? "
|
| 374 |
+
"AND source_member LIKE ? AND phase=?",
|
| 375 |
+
(tier, f"{run}/%", p),
|
| 376 |
+
).fetchone()[0]
|
| 377 |
+
for p in PHASE_NAMES
|
| 378 |
+
}
|
| 379 |
+
slice_quota = make_quotas(quota)
|
| 380 |
+
counts = dict(base)
|
| 381 |
+
|
| 382 |
+
print(f"\n[{tier}/{run}] {have:,}/{quota:,} from {len(window)} tars "
|
| 383 |
+
f"in [{first:.2f}-{last:.2f}]")
|
| 384 |
+
|
| 385 |
+
for index in spread(len(window)):
|
| 386 |
+
if all(counts[p] >= slice_quota[p] for p in slice_quota):
|
| 387 |
+
break
|
| 388 |
+
tar = window[index][0]
|
| 389 |
+
token = f"{run}/{tar}"
|
| 390 |
+
if token in tars_done:
|
| 391 |
+
continue
|
| 392 |
+
stats = process_tar(
|
| 393 |
+
db, args.rescorer, run, tar, tier, args.slice_bytes, args.threads,
|
| 394 |
+
args.per_game, counts, slice_quota, args.seed, args.keep_chess960,
|
| 395 |
+
args.scratch,
|
| 396 |
+
)
|
| 397 |
+
tars_done.add(token)
|
| 398 |
+
set_metadata(db, "tars_done", json.dumps(sorted(tars_done)))
|
| 399 |
+
db.commit()
|
| 400 |
+
total = sum(counts.values())
|
| 401 |
+
elapsed = time.monotonic() - started
|
| 402 |
+
print(
|
| 403 |
+
f" {tar[-21:]:21} {stats['bytes'] / 1e6:6.0f}MB "
|
| 404 |
+
f"games={stats['games']:5,} +{stats['inserted']:6,} "
|
| 405 |
+
f"-> {total:,}/{quota:,} [{elapsed / 60:.1f}m]",
|
| 406 |
+
flush=True,
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
total = db.execute("SELECT COUNT(*) FROM positions").fetchone()[0]
|
| 410 |
+
set_metadata(db, "position_count", total)
|
| 411 |
+
set_metadata(db, "completed_unix", int(time.time()))
|
| 412 |
+
db.commit()
|
| 413 |
+
print(f"\nWrote {total:,} positions to {args.output}")
|
| 414 |
+
for row in db.execute(
|
| 415 |
+
"SELECT source_split, COUNT(*) FROM positions GROUP BY source_split ORDER BY 2 DESC"
|
| 416 |
+
):
|
| 417 |
+
print(f" {row[0]:8} {row[1]:>9,}")
|
| 418 |
+
db.close()
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
if __name__ == "__main__":
|
| 422 |
+
main()
|
scripts/lc0_runs.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Which lc0 self-play runs to draw from, and in what proportion.
|
| 2 |
+
|
| 3 |
+
Tiers follow generation quality: the networks producing the games get weaker as
|
| 4 |
+
you go down, so the lower tiers contribute noisier, more exploratory positions.
|
| 5 |
+
Keeping a minority of them is deliberate — a corpus drawn only from the strongest
|
| 6 |
+
run is narrow in exactly the way this corpus is meant not to be.
|
| 7 |
+
|
| 8 |
+
Availability was surveyed against storage.lczero.org on 2026-08-25 and differs
|
| 9 |
+
from the run list usually quoted:
|
| 10 |
+
|
| 11 |
+
* test70, test77, test76, test50, test20 and test10 are not hosted at all.
|
| 12 |
+
* test78 and test90 exist but every tar is a 10 KB placeholder.
|
| 13 |
+
* test80's retained window now starts 2024-04-01; earlier tars were pruned.
|
| 14 |
+
* test80 stopped producing on 2025-09-24. test91 is the live run.
|
| 15 |
+
* test71 is the Chess960 run — measured 30-36% Chess960 against at most 1.2%
|
| 16 |
+
elsewhere — so it is excluded rather than tiered. test71_5 measured 0%.
|
| 17 |
+
|
| 18 |
+
Named substitutes for the missing runs stay in era and strength order:
|
| 19 |
+
test79 and test75 stand in for T70/T78 in the mid tier, test71_5 for T50.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
from __future__ import annotations
|
| 23 |
+
|
| 24 |
+
from dataclasses import dataclass, field
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@dataclass(frozen=True)
|
| 28 |
+
class Run:
|
| 29 |
+
name: str
|
| 30 |
+
# Restrict to a slice of the run's date-sorted tars, as "late test60" and
|
| 31 |
+
# "early test60" belong to different tiers.
|
| 32 |
+
first: float = 0.0
|
| 33 |
+
last: float = 1.0
|
| 34 |
+
weight: float = 1.0
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@dataclass(frozen=True)
|
| 38 |
+
class Tier:
|
| 39 |
+
name: str
|
| 40 |
+
share: float
|
| 41 |
+
runs: tuple[Run, ...]
|
| 42 |
+
note: str = ""
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
TIERS: tuple[Tier, ...] = (
|
| 46 |
+
Tier(
|
| 47 |
+
"strong",
|
| 48 |
+
0.60,
|
| 49 |
+
(Run("test80", weight=2.0), Run("test91", weight=1.0)),
|
| 50 |
+
"Mature run1 plus the live run2. Core modern play.",
|
| 51 |
+
),
|
| 52 |
+
Tier(
|
| 53 |
+
"mid",
|
| 54 |
+
0.22,
|
| 55 |
+
(Run("test79"), Run("test75"), Run("test60", first=0.60)),
|
| 56 |
+
"Late-T60 through T79: transitional styles, sound but more varied.",
|
| 57 |
+
),
|
| 58 |
+
Tier(
|
| 59 |
+
"low",
|
| 60 |
+
0.13,
|
| 61 |
+
(Run("test40"), Run("test60", last=0.35), Run("test71_5", weight=0.5)),
|
| 62 |
+
"2019-2020 nets. Messier tactics and unusual structures.",
|
| 63 |
+
),
|
| 64 |
+
Tier(
|
| 65 |
+
"early",
|
| 66 |
+
0.05,
|
| 67 |
+
(Run("test30"), Run("run3", weight=0.5)),
|
| 68 |
+
"2018-2019 semi-initial play. Kept small; maximum noise.",
|
| 69 |
+
),
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
EXCLUDED = {
|
| 73 |
+
"test71": "Chess960 run; 30-36% of positions are Chess960",
|
| 74 |
+
"test78": "all tars are 10 KB placeholders",
|
| 75 |
+
"test90": "all tars are 10 KB placeholders",
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def quotas(total: int) -> dict[str, int]:
|
| 80 |
+
"""Positions per tier, with the rounding residue given to the largest."""
|
| 81 |
+
|
| 82 |
+
assigned = {tier.name: int(total * tier.share) for tier in TIERS}
|
| 83 |
+
largest = max(TIERS, key=lambda t: t.share).name
|
| 84 |
+
assigned[largest] += total - sum(assigned.values())
|
| 85 |
+
return assigned
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def run_quotas(tier: Tier, tier_total: int) -> dict[str, int]:
|
| 89 |
+
"""Positions per (run, slice) inside one tier, split by run weight."""
|
| 90 |
+
|
| 91 |
+
total_weight = sum(r.weight for r in tier.runs)
|
| 92 |
+
out: dict[str, int] = {}
|
| 93 |
+
for run in tier.runs:
|
| 94 |
+
key = f"{run.name}:{run.first:.2f}-{run.last:.2f}"
|
| 95 |
+
out[key] = int(tier_total * run.weight / total_weight)
|
| 96 |
+
residue = tier_total - sum(out.values())
|
| 97 |
+
if out:
|
| 98 |
+
out[next(iter(out))] += residue
|
| 99 |
+
return out
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
assert abs(sum(t.share for t in TIERS) - 1.0) < 1e-9
|
scripts/plain_to_fen.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extract every FEN from a Stockfish .plain file.
|
| 2 |
+
|
| 3 |
+
This replaces filter_plain.py for consumers that want positions rather than
|
| 4 |
+
Stockfish NNUE training samples. filter_plain.py drops any position holding
|
| 5 |
+
castling rights that did not arise from a standard opening, because Stockfish
|
| 6 |
+
cannot train on Chess960 castling. Nothing here is dropped by default: the
|
| 7 |
+
positions are the product, and which ones to keep is the caller's decision.
|
| 8 |
+
|
| 9 |
+
Chess960 positions are recognised and counted, and can be excluded with
|
| 10 |
+
--standard-only. They are reported either way, so the composition of the output
|
| 11 |
+
is never silent.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import argparse
|
| 17 |
+
import gzip
|
| 18 |
+
import sys
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
# Shredder-FEN castling fields name the rook files, so anything outside KQkq is
|
| 22 |
+
# a Chess960 game. lc0's test80 run mixes a small share of them into self-play.
|
| 23 |
+
STANDARD_CASTLING = set("KQkq-")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def is_chess960(fen: str) -> bool:
|
| 27 |
+
field = fen.split(" ")[2]
|
| 28 |
+
return not set(field) <= STANDARD_CASTLING
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def opened(path: Path, mode: str):
|
| 32 |
+
if path.suffix == ".gz":
|
| 33 |
+
return gzip.open(path, mode + "t", encoding="utf-8")
|
| 34 |
+
return open(path, mode, encoding="utf-8")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def convert(source: Path, destination: Path, standard_only: bool) -> dict[str, int]:
|
| 38 |
+
counts = {"positions": 0, "chess960": 0, "written": 0}
|
| 39 |
+
with opened(source, "r") as infile, opened(destination, "w") as outfile:
|
| 40 |
+
for row in infile:
|
| 41 |
+
if not row.startswith("fen "):
|
| 42 |
+
continue
|
| 43 |
+
fen = row[4:].strip()
|
| 44 |
+
counts["positions"] += 1
|
| 45 |
+
frc = is_chess960(fen)
|
| 46 |
+
counts["chess960"] += frc
|
| 47 |
+
if standard_only and frc:
|
| 48 |
+
continue
|
| 49 |
+
counts["written"] += 1
|
| 50 |
+
outfile.write(fen + "\n")
|
| 51 |
+
return counts
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def main() -> None:
|
| 55 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 56 |
+
parser.add_argument("input", type=Path, help="a .plain or .plain.gz file")
|
| 57 |
+
parser.add_argument("-o", "--output", type=Path)
|
| 58 |
+
parser.add_argument(
|
| 59 |
+
"--standard-only",
|
| 60 |
+
action="store_true",
|
| 61 |
+
help="drop Chess960 positions instead of keeping them",
|
| 62 |
+
)
|
| 63 |
+
args = parser.parse_args()
|
| 64 |
+
|
| 65 |
+
destination = args.output
|
| 66 |
+
if destination is None:
|
| 67 |
+
stem = args.input.name.replace(".plain.gz", "").replace(".plain", "")
|
| 68 |
+
destination = args.input.with_name(stem + ".fen")
|
| 69 |
+
|
| 70 |
+
counts = convert(args.input, destination, args.standard_only)
|
| 71 |
+
print(
|
| 72 |
+
f"{args.input} -> {destination}\n"
|
| 73 |
+
f" positions read: {counts['positions']:,}\n"
|
| 74 |
+
f" chess960: {counts['chess960']:,}\n"
|
| 75 |
+
f" written: {counts['written']:,}",
|
| 76 |
+
file=sys.stderr,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
main()
|
scripts/rescorer-optional-syzygy.patch
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/src/selfplay/loop.cc b/src/selfplay/loop.cc
|
| 2 |
+
index a0a03d7..6bc4736 100644
|
| 3 |
+
--- a/src/selfplay/loop.cc
|
| 4 |
+
+++ b/src/selfplay/loop.cc
|
| 5 |
+
@@ -905,7 +905,7 @@ void ProcessFile(const std::string& file, SyzygyTablebase* tablebase,
|
| 6 |
+
const auto& board = history.Last().GetBoard();
|
| 7 |
+
if (board.castlings().no_legal_castle() &&
|
| 8 |
+
(board.ours() | board.theirs()).count() <= 3 &&
|
| 9 |
+
- board.pawns().empty()) {
|
| 10 |
+
+ tablebase->max_cardinality() >= 3 && board.pawns().empty()) {
|
| 11 |
+
ProbeState state;
|
| 12 |
+
WDLScore wdl = tablebase->probe_wdl(history.Last(), &state);
|
| 13 |
+
// Only fail state means the WDL is wrong, probe_wdl may produce
|
| 14 |
+
@@ -1239,8 +1239,9 @@ void RescoreLoop::RunLoop() {
|
| 15 |
+
if (!tablebase.init(
|
| 16 |
+
options_.GetOptionsDict().Get<std::string>(kSyzygyTablebaseId)) ||
|
| 17 |
+
tablebase.max_cardinality() < 3) {
|
| 18 |
+
- std::cerr << "FAILED TO LOAD SYZYGY" << std::endl;
|
| 19 |
+
- return;
|
| 20 |
+
+ std::cerr << "No Syzygy tablebases loaded; continuing without tablebase "
|
| 21 |
+
+ "rescoring. Positions and moves are unaffected."
|
| 22 |
+
+ << std::endl;
|
| 23 |
+
}
|
| 24 |
+
auto dtmPaths =
|
| 25 |
+
options_.GetOptionsDict().Get<std::string>(kGaviotaTablebaseId);
|