edarsem commited on
Commit
31f6c03
·
verified ·
1 Parent(s): 648d0c4

Add model card

Browse files
Files changed (1) hide show
  1. README.md +99 -0
README.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - chess
5
+ - transformer
6
+ - pytorch
7
+ - imitation-learning
8
+ language:
9
+ - en
10
+ pipeline_tag: text-generation
11
+ library_name: pytorch
12
+ ---
13
+
14
+ # Chessformer v0
15
+
16
+ A ~50M parameter transformer trained to **imitate human chess play across the full Elo spectrum**, conditioned on player Elo, remaining clock time, and time increment.
17
+
18
+ > **44.4% top-1 joint move accuracy** on a held-out, Elo-balanced validation set (predicting the exact human move — from-square and to-square).
19
+
20
+ ## What it does
21
+
22
+ - **Strength is a dial.** Pass `white_elo=1200` and it plays like a 1200. Pass `white_elo=2800` and it plays like a 2800.
23
+ - **No rules, no search.** Legal-move understanding is emergent from training data only.
24
+ - **Clock-aware.** Conditioning on remaining time lets the model represent time-pressure play.
25
+ - **One forward pass per move.** From-square and to-square are predicted autoregressively in a single masked forward, not via tree search.
26
+
27
+ ## Usage
28
+
29
+ ```python
30
+ import chess, torch
31
+ from chessformer.model import ChessformerModel, unwrap_state_dict
32
+ from chessformer.tokenizer import build_vocab
33
+ from chessformer.inference import pick_move
34
+
35
+ vocab = build_vocab()
36
+ ckpt = torch.load("chessformer_v0.pt", map_location="cpu")
37
+ model = ChessformerModel(vocab=vocab, **ckpt["cfg"]["model"])
38
+ model.load_state_dict(unwrap_state_dict(ckpt["model"]), strict=True)
39
+ model.eval()
40
+
41
+ board = chess.Board()
42
+ move = pick_move(model, vocab, torch.device("cpu"), board,
43
+ white_elo=2500, black_elo=2500,
44
+ white_clock_s=120.0, black_clock_s=120.0,
45
+ increment_s=5.0)
46
+ print(move) # e.g. e2e4
47
+ ```
48
+
49
+ ## Architecture
50
+
51
+ | Param | Value |
52
+ | --- | --- |
53
+ | Parameters | ~50M |
54
+ | d_model | 512 |
55
+ | n_heads | 8 |
56
+ | n_layers | 12 |
57
+ | FFN | SwiGLU, 4× expansion |
58
+ | Norm | RMSNorm (pre-norm) |
59
+ | Attention | Flash Attention (SDPA) |
60
+ | Max sequence length | 41 tokens |
61
+
62
+ Board pieces use **additive embeddings**: `emb[color] + emb[piece_type] + emb[file] + emb[rank]`. No positional encoding needed. Elo, clock, and increment use soft bracket interpolation.
63
+
64
+ ## Training
65
+
66
+ - **Data:** Lichess standard rated games, January 2018 (~100k games, ~6.6M positions)
67
+ - **Val/Test:** December 2017 (different month — no game-level leakage), Elo-balanced across 1000–2900
68
+ - **Steps:** 20,000
69
+ - **Batch size:** 1024 (2× T4 GPU, DDP)
70
+ - **LR:** 3e-4, cosine decay with 1000-step warmup
71
+ - **Optimizer:** AdamW, weight decay 0.01
72
+
73
+ ## Metrics (val_games, Elo-balanced)
74
+
75
+ | Metric | Value |
76
+ | --- | --- |
77
+ | Top-1 joint move accuracy | **44.4%** |
78
+ | Validation loss | **1.785** |
79
+
80
+ ## Limitations
81
+
82
+ - Trained on one month of Lichess — tactical blindspots exist, especially in quiet positions.
83
+ - Puzzle-solving is emergent and not explicitly optimized.
84
+ - Clock conditioning is only as good as the training data's clock annotations.
85
+
86
+ ## License
87
+
88
+ Apache 2.0. Training data from [database.lichess.org](https://database.lichess.org/) (CC0).
89
+
90
+ ## Citation
91
+
92
+ ```
93
+ @misc{chessformer2024,
94
+ author = {Albert-Roulhac, Edouard},
95
+ title = {Chessformer: Elo-conditioned human chess imitation via transformer},
96
+ year = {2024},
97
+ url = {https://github.com/edarsem/chessformer},
98
+ }
99
+ ```