| --- |
| license: cc0-1.0 |
| task_categories: |
| - other |
| tags: |
| - chess |
| - lichess |
| - sequence-modeling |
| - language-modeling |
| pretty_name: Lichess 2024–2025 Standard Rated (Binary Move Encoding) |
| size_categories: |
| - 1B<n<10B |
| configs: |
| - config_name: metadata |
| data_files: |
| - split: train |
| path: "*-metadata.parquet" |
| --- |
| |
| # Lichess Standard Rated Games, 2024-01 → 2025-09 (binary move encoding) |
|
|
| A compact binary re-encoding of the [Lichess monthly database](https://database.lichess.org/) for standard rated games, covering 21 consecutive months (January 2024 through September 2025). Designed for training sequence models on chess games — every move is one 16-bit token, every game is a variable-length sequence of tokens, and per-game metadata lives in Parquet alongside. |
|
|
| Source PGNs were processed with the encoder at https://github.com/Alfredvc/chess-autocomplete (see `rust/src/move_codec.rs` for the authoritative codec implementation). |
|
|
| ## File layout |
|
|
| Per month, three files share the prefix `lichess_db_standard_rated_YYYY-MM`: |
|
|
| | File | Format | Purpose | |
| | --- | --- | --- | |
| | `*.bin` | Packed little-endian `u16` tokens | Concatenated games. One game = one variable-length run of `u16` move tokens. No in-stream delimiters — use the map file to find game boundaries. | |
| | `*-map.bin` | Packed little-endian `u64` | Cumulative byte offsets, one per game. Game `i` occupies bytes `[offsets[i-1], offsets[i])` in `*.bin` (with `offsets[-1] = 0`). Number of games = `len(map) / 8`. | |
| | `*-metadata.parquet` | Parquet | One row per game, in the same order as games appear in `*.bin`. | |
|
|
| All months together: 63 files, ~272 GB. The 21 Parquet files alone are ~13 GB and can be browsed directly on the Hub's Datasets viewer via the `metadata` config. |
|
|
| ## Metadata schema |
|
|
| | Column | Type | Notes | |
| | --- | --- | --- | |
| | `GameIndex` | `uint64` | 1-based index within the source PGN file. Skipped games (non-standard start positions, etc.) leave gaps. | |
| | `WhiteRating/16` | `uint8` | Rating quantized to 16-pt buckets — multiply by 16 to recover. `0` = unknown. Saturates at 4080+ (255 × 16). | |
| | `BlackRating/16` | `uint8` | Same encoding as WhiteRating. | |
| | `InitialTime` | `uint16` | Initial clock in seconds. `0` = unknown. | |
| | `Increment` | `uint8` | Increment in seconds. | |
|
|
| ## Move token encoding (16 bits per move) |
|
|
| Each `u16`, parsed in little-endian byte order, packs five fields: |
|
|
| ``` |
| bits 15-12 : op (4 bits — piece, castle, promotion, or game-end marker) |
| bits 11-9 : from_file (3 bits, 0=a … 7=h) |
| bits 8-6 : from_rank (3 bits, 0=rank 1 … 7=rank 8) |
| bits 5-3 : to_file (3 bits) |
| bits 2-0 : to_rank (3 bits) |
| ``` |
|
|
| `op` codes: |
|
|
| | Code | Meaning | |
| | --- | --- | |
| | `0b0000` | Pawn move | |
| | `0b0001` | Knight move | |
| | `0b0010` | Bishop move | |
| | `0b0011` | Rook move | |
| | `0b0100` | Queen move | |
| | `0b0101` | King move (non-castle) | |
| | `0b0110` | White king-side castle | |
| | `0b0111` | White queen-side castle | |
| | `0b1000` | Game-end marker (see special tokens below) | |
| | `0b1001` | Promotion to knight | |
| | `0b1010` | Promotion to bishop | |
| | `0b1011` | Promotion to rook | |
| | `0b1100` | Promotion to queen | |
| | `0b1101` | Black king-side castle | |
| | `0b1110` | Black queen-side castle | |
| | `0b1111` | Reserved / unused | |
|
|
| When `op == 0b1000`, the lower 12 bits encode the termination reason rather than squares: |
|
|
| | Token | Reason | |
| | --- | --- | |
| | `0x8000` | Unknown | |
| | `0x8001` | Checkmate | |
| | `0x8002` | Stalemate | |
| | `0x8003` | Insufficient material | |
| | `0x8004` | Fifty-move rule | |
| | `0x8005` | Threefold repetition | |
|
|
| Each game's token stream terminates with one of these markers. This representation is **board-free**: a parser does not need to maintain a chess position to decode any single move (unlike SAN or UCI), since the moving piece type, origin square, destination square, and promotion piece are all explicit. |
|
|
| ## Decoding example (Python) |
|
|
| Reading game `i` from a single month: |
|
|
| ```python |
| import numpy as np |
| import pyarrow.parquet as pq |
| |
| month = "2024-01" |
| prefix = f"lichess_db_standard_rated_{month}" |
| |
| # Per-game byte offsets into *.bin (cumulative end positions) |
| offsets = np.fromfile(f"{prefix}-map.bin", dtype=np.uint64) |
| num_games = len(offsets) |
| |
| # Memory-map the moves |
| moves = np.memmap(f"{prefix}.bin", dtype=np.uint16, mode="r") |
| |
| def get_game_tokens(i: int) -> np.ndarray: |
| start_byte = 0 if i == 0 else offsets[i - 1] |
| end_byte = offsets[i] |
| # offsets are byte positions; tokens are 2 bytes each |
| return moves[start_byte // 2 : end_byte // 2] |
| |
| # Per-game metadata aligns row-for-row with the games in *.bin |
| meta = pq.read_table(f"{prefix}-metadata.parquet").to_pandas() |
| print(meta.iloc[0]) |
| print(get_game_tokens(0)) |
| ``` |
|
|
| To decode an individual move token: |
|
|
| ```python |
| def decode(token: int): |
| op = (token >> 12) & 0xF |
| if op == 0b1000: |
| return ("game_end", token & 0xFFF) |
| from_file = (token >> 9) & 0x7 |
| from_rank = (token >> 6) & 0x7 |
| to_file = (token >> 3) & 0x7 |
| to_rank = token & 0x7 |
| return (op, from_file, from_rank, to_file, to_rank) |
| ``` |
|
|
| ## Coverage |
|
|
| 21 months: `2024-01`, `2024-02`, …, `2024-12`, `2025-01`, …, `2025-09`. |
|
|
| Games per month are on the order of 10⁸ (the source Lichess dumps contain ~90–100M standard rated games per month). Games with non-standard starting positions (e.g., Chess960 mixed into the standard archive, or unusual `FEN` tags) are skipped during encoding, so `GameIndex` is not contiguous. |
|
|
| ## Filtering / partial downloads |
|
|
| Use `huggingface_hub`'s filtered download to pull only the months or file types you need: |
|
|
| ```python |
| from huggingface_hub import snapshot_download |
| |
| # Just the metadata Parquet files (~13 GB total) |
| snapshot_download( |
| repo_id="Alfredvc/chess-autocomplete-lichess", |
| repo_type="dataset", |
| allow_patterns="*-metadata.parquet", |
| local_dir="./lichess", |
| ) |
| |
| # A single month, all three files |
| snapshot_download( |
| repo_id="Alfredvc/chess-autocomplete-lichess", |
| repo_type="dataset", |
| allow_patterns="lichess_db_standard_rated_2024-01*", |
| local_dir="./lichess", |
| ) |
| ``` |
|
|
| ## License |
|
|
| The underlying Lichess game data is published by Lichess under **CC0 1.0** (public domain dedication). This re-encoded copy is released under the same terms. Please cite the [Lichess database](https://database.lichess.org/) when using this dataset. |
|
|