File size: 2,597 Bytes
7a8de87
 
 
 
 
9269e61
7a8de87
9269e61
 
 
 
 
7a8de87
9269e61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
license: apache-2.0
base_model: convaiinnovations/laya
tags: [chess, laya, decision-model]
---
# LayaChess: Laya fine-tuned for chess

[Laya](https://huggingface.co/convaiinnovations/laya) (Convai Innovations, ModernBERT-large, 421M) is a System 1
decision model that had never seen a chessboard. This checkpoint fine-tunes it on 2 million Stockfish-rated moves from
DeepMind's [ChessBench](https://github.com/google-deepmind/searchless_chess). For each legal move, a Laya `score`
question predicts the win chance of the side to move over 10 levels. The
[LayaChess engine](https://github.com/devroopsaha744/LayaChess) wraps it in a Monte Carlo tree search.

- **Play it online:** [huggingface.co/spaces/datafreak/laya-chess](https://huggingface.co/spaces/datafreak/laya-chess)
- **Write-up:** [LayaChess: teaching a System 1 decision model to play chess](https://devroopsaha744.github.io/portfolio/blog/laya-chess/)
- **Demo video:** [youtube.com/watch?v=bPpAlWArs7E](https://www.youtube.com/watch?v=bPpAlWArs7E)
- **Code:** [github.com/devroopsaha744/LayaChess](https://github.com/devroopsaha744/LayaChess)

## Results
| | Base Laya | This checkpoint |
|---|---|---|
| Picks Stockfish's best move (300 held-out positions) | 6% | **27%** |
| Win-chance error (percentage points) | 28.6 | **8.2** |

Checkpoint `final`: step 32,000, 2,048,000 training examples. Encoding, levels and the question template are in
`chess_meta.json`. `train_state.pt` is the optimizer state for resuming training; inference doesn't need it.

## Run it on your own machine
```bash
git clone https://github.com/devroopsaha744/LayaChess.git
cd LayaChess/engine
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python -m laya_chess.play          # browser board at http://localhost:8000
```
The engine downloads this checkpoint on first start. Optional: install Stockfish (`brew install stockfish` or
`sudo apt install stockfish`) to see its preferred move next to Laya's. Full steps are in the
[GitHub README](https://github.com/devroopsaha744/LayaChess#run-it-on-your-own-machine).

## Use it from Python
```python
import chess
from laya_chess import LayaChessModel

model = LayaChessModel("datafreak/laya-chess")
for move, win in model.score_moves(chess.Board())[:5]:
    print(move, f"{win:.0%}")
```

## Credits
[Laya](https://github.com/NandhaKishorM/laya) by Convai Innovations (Apache 2.0) 路
[ChessBench](https://github.com/google-deepmind/searchless_chess) by Google DeepMind 路
[Stockfish](https://stockfishchess.org) 路 [python-chess](https://python-chess.readthedocs.io)