MostLime commited on
Commit
e39576a
·
1 Parent(s): 798ceca

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +222 -3
README.md CHANGED
@@ -1,3 +1,222 @@
1
- ---
2
- license: cc-by-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ task_categories:
4
+ - text-generation
5
+ language:
6
+ - en
7
+ tags:
8
+ - chess
9
+ - uci
10
+ - transformer
11
+ - games
12
+ - elite
13
+ - lichess
14
+ - twic
15
+ - tokenized
16
+ size_categories:
17
+ - 1M<n<10M
18
+ ---
19
+
20
+ # chess-elite-uci
21
+
22
+ A transformer-ready dataset of ~8 million elite chess games, pre-tokenized in UCI notation with a deterministic 1977-token vocabulary. Built for training chess language models directly — no preprocessing required.
23
+
24
+ ## Dataset Summary
25
+
26
+ | Field | Value |
27
+ |---|---|
28
+ | Total games | 7,972,071 |
29
+ | Lichess Elite games | 7,805,503 |
30
+ | TWIC OTB games | 166,568 |
31
+ | Average sequence length | 94.3 tokens |
32
+ | Max sequence length | 255 tokens |
33
+ | Vocabulary size | 1,977 tokens |
34
+ | Mean combined Elo | 5,212 (~2,606 per player) |
35
+
36
+ ## Sources
37
+
38
+ **Lichess Elite Database** (June 2020 – November 2025)
39
+ Games where both players are rated 2500+ vs 2300+ (2022 onwards: 2500+ vs 2300+; prior: 2400+ vs 2200+). Source: [database.nikonoel.fr](https://database.nikonoel.fr). Licensed CC0.
40
+
41
+ **The Week in Chess (TWIC)** (Issues 920–1633, ~2013–2026)
42
+ OTB classical tournament games where both players are FIDE-rated 2500+. Source: [theweekinchess.com](https://theweekinchess.com). Permission pending.
43
+
44
+ Cross-dataset duplicates (3,173 games appearing in both sources) were removed using SHA1 hashing of move sequences. Lichess takes priority on conflicts.
45
+
46
+ ## Vocabulary
47
+
48
+ The vocabulary contains **1,977 tokens** and is fully deterministic — enumerated from chess geometry, not derived from data. It will never produce OOV tokens for any legal chess game.
49
+ ```
50
+ ID Token Description
51
+ ─────────────────────────────────────────────────────────────
52
+ 0 <PAD> Padding
53
+ 1 <W> POV token: white wins / white side for draws
54
+ 2 <B> POV token: black wins / black side for draws
55
+ 3 <CHECKMATE> Terminal: game ended in checkmate
56
+ 4 <RESIGN> Terminal: losing side resigned (≥ 40 ply)
57
+ 5 <STALEMATE> Terminal: draw by stalemate
58
+ 6 <REPETITION> Terminal: draw by threefold repetition
59
+ 7 <FIFTY_MOVE> Terminal: draw by 50-move rule
60
+ 8 <INSUFF_MATERIAL> Terminal: draw by insufficient material
61
+ 9+ a1a2 … h7h8q 1968 UCI move strings, sorted lexicographically
62
+ ```
63
+
64
+ The full vocabulary is provided in `vocab.json` as `{ token_str: int_id }`.
65
+
66
+ ## Sequence Format
67
+
68
+ Every game is encoded as a flat list of integer token IDs:
69
+ ```
70
+ [ <POV> | m1 | m2 | m3 | ... | mN | <TERMINAL> ]
71
+ ```
72
+
73
+ - **POV token** (position 0): `<W>` if white wins, `<B>` if black wins. For draws, assigned randomly 50/50 between `<W>` and `<B>`.
74
+ - **Move tokens** (positions 1 to N): UCI half-moves alternating white/black, e.g. `e2e4`, `e7e5`, `g1f3`, `e1g1` (castling), `e7e8q` (promotion).
75
+ - **Terminal token** (position N+1): encodes why the game ended.
76
+
77
+ Maximum sequence length is **255 tokens** (1 POV + 253 moves + 1 terminal). Sequences are variable length — pad to 255 with `<PAD>` (ID 0) in your DataLoader.
78
+
79
+ ## NTP Loss Mask
80
+
81
+ The `ntp_mask` column contains a binary list of the same length as `token_ids`. It indicates which positions should have next-token-prediction (NTP) loss applied during training:
82
+ ```
83
+ Position NTP loss
84
+ ─────────────────────────────
85
+ POV token 1 (always)
86
+ Winning side move 1
87
+ Losing side move 0 (context only)
88
+ Terminal token 1 (always)
89
+ Draw game moves 1 (both sides, since neither lost)
90
+ ```
91
+
92
+ This implements win-conditioned training: the model learns to predict the winning side's moves given the POV token, while still attending to the losing side's moves as context. For TOP (Token Order Prediction) auxiliary loss, apply no masking — all tokens should be ranked.
93
+
94
+ Usage in PyTorch:
95
+ ```python
96
+ loss = cross_entropy(logits, labels, reduction="none")
97
+ loss = (loss * ntp_mask).sum() / ntp_mask.sum()
98
+ ```
99
+
100
+ ## Filtering
101
+
102
+ Games were filtered as follows before inclusion:
103
+
104
+ **Decisive games (1-0 / 0-1):**
105
+ - **Checkmates**: verified by `board.is_checkmate()` on the final position. No length minimum.
106
+ - **Resignations**: not checkmate, minimum 40 halfmoves (20 moves each side).
107
+
108
+ **Draws (1/2-1/2):**
109
+ - Only **forced draws** are included: stalemate, insufficient material, 50-move rule, threefold repetition.
110
+ - Draw-by-agreement is excluded (`board.is_game_over(claim_draw=True)` must return True).
111
+
112
+ **All games:**
113
+ - Maximum 253 halfmoves (fits within 255-token sequence budget).
114
+ - Both player Elo values must be present and non-zero.
115
+ - All moves must be legally parseable by python-chess.
116
+
117
+ **Game type breakdown:**
118
+
119
+ | Type | Count | % |
120
+ |---|---|---|
121
+ | White checkmate | 1,702,751 | 21.4% |
122
+ | White resignation | 2,000,000 | 25.1% |
123
+ | Black checkmate | 1,702,752 | 21.4% |
124
+ | Black resignation | 2,000,000 | 25.1% |
125
+ | Forced draw | 400,000 | 5.0% |
126
+ | TWIC (all types) | 166,568 | 2.1% |
127
+
128
+ ## Schema
129
+ ```python
130
+ {
131
+ "white_elo": int32, # white player Elo
132
+ "black_elo": int32, # black player Elo
133
+ "combined_elo": int32, # white_elo + black_elo
134
+ "result": string, # "1-0", "0-1", or "1/2-1/2"
135
+ "game_type": string, # "checkmate", "resignation", or "forced_draw"
136
+ "pov": string, # "<W>" or "<B>"
137
+ "terminal": string, # "<CHECKMATE>", "<RESIGN>", "<STALEMATE>", ...
138
+ "source": string, # "lichess" or "twic"
139
+ "moves_uci": string, # space-separated UCI moves, human-readable
140
+ "token_ids": list[int32], # encoded sequence, use this for training
141
+ "ntp_mask": list[int32], # 1 = apply NTP loss, 0 = skip
142
+ "seq_len": int32, # len(token_ids), always in [3, 255]
143
+ }
144
+ ```
145
+
146
+ ## Usage
147
+ ```python
148
+ from datasets import load_dataset
149
+ import json
150
+
151
+ # Load dataset
152
+ ds = load_dataset("MostLime/chess-elite-uci", split="train")
153
+
154
+ # Load vocabulary
155
+ with open("vocab.json") as f:
156
+ vocab = json.load(f)
157
+ id_to_token = {v: k for k, v in vocab.items()}
158
+
159
+ # Decode a game
160
+ row = ds[0]
161
+ tokens = [id_to_token[i] for i in row["token_ids"]]
162
+ print(" ".join(tokens))
163
+ # → <W> e2e4 e7e5 g1f3 b8c6 f1b5 ... <RESIGN>
164
+
165
+ # Filter by source
166
+ lichess_only = ds.filter(lambda x: x["source"] == "lichess")
167
+ twic_only = ds.filter(lambda x: x["source"] == "twic")
168
+
169
+ # PyTorch DataLoader
170
+ import torch
171
+ from torch.utils.data import DataLoader
172
+
173
+ def collate(batch):
174
+ max_len = 255
175
+ token_ids = torch.zeros(len(batch), max_len, dtype=torch.long)
176
+ ntp_mask = torch.zeros(len(batch), max_len, dtype=torch.float)
177
+ for i, row in enumerate(batch):
178
+ n = row["seq_len"]
179
+ token_ids[i, :n] = torch.tensor(row["token_ids"], dtype=torch.long)
180
+ ntp_mask[i, :n] = torch.tensor(row["ntp_mask"], dtype=torch.float)
181
+ return {"token_ids": token_ids, "ntp_mask": ntp_mask}
182
+
183
+ loader = DataLoader(ds, batch_size=32, collate_fn=collate)
184
+ ```
185
+
186
+ ## Inference
187
+
188
+ At inference time, prepend the POV token for the side the model plays as, then feed opponent moves as context and sample responses:
189
+ ```python
190
+ # Model plays as white
191
+ sequence = [vocab["<W>"]]
192
+
193
+ # Opponent plays e7e5 — append as context
194
+ sequence.append(vocab["e7e5"])
195
+
196
+ # Sample model's next move from legal UCI moves for the current position
197
+ ```
198
+
199
+ Terminal tokens are never generated during normal play — the game ends when the opponent resigns or a draw is claimed externally.
200
+
201
+ ## Related Work
202
+
203
+ - [Grandmaster-Level Chess Without Search](https://arxiv.org/abs/2402.04494) — 270M parameter transformer reaching 2895 Lichess blitz Elo
204
+ - [adamkarvonen/chess_games](https://huggingface.co/datasets/adamkarvonen/chess_games) — raw PGN blocks used in chess-GPT
205
+
206
+ ## Citation
207
+ ```bibtex
208
+ @dataset{mostlime2026chessEliteUCI,
209
+ author = {MostLime},
210
+ title = {chess-elite-uci: A Transformer-Ready Dataset of Elite Chess Games},
211
+ year = {2026},
212
+ publisher = {HuggingFace},
213
+ url = {https://huggingface.co/datasets/MostLime/chess-elite-uci}
214
+ }
215
+ ```
216
+
217
+ ## Acknowledgements
218
+
219
+ - [Lichess Elite Database](https://database.nikonoel.fr) by nikonoel — CC0
220
+ - [The Week in Chess](https://theweekinchess.com) by Mark Crowther — permission pending
221
+ - [python-chess](https://python-chess.readthedocs.io) for move parsing and board state verification
222
+ - [Modal](https://modal.com) for distributed compute