Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- chess
|
| 5 |
+
- transformer
|
| 6 |
+
- behavioral-cloning
|
| 7 |
+
- no-search
|
| 8 |
+
language:
|
| 9 |
+
- en
|
| 10 |
+
pipeline_tag: other
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Artoria Zero
|
| 14 |
+
|
| 15 |
+
**Grandmaster-Level Chess Without Search** — A decoder-only transformer trained via behavioral cloning to predict chess moves directly from board state, with no search algorithm (no MCTS, no Alpha-Beta).
|
| 16 |
+
|
| 17 |
+
Based on the approach from [arXiv:2402.04494](https://arxiv.org/abs/2402.04494).
|
| 18 |
+
|
| 19 |
+
## Model Variants
|
| 20 |
+
|
| 21 |
+
| Variant | d_model | Layers | Heads | Parameters | Checkpoint |
|
| 22 |
+
|---------|---------|--------|-------|------------|------------|
|
| 23 |
+
| **Small** | 256 | 8 | 8 | ~19M | `small/checkpoint.pt` |
|
| 24 |
+
| **Mid** | 512 | 16 | 8 | ~100M | `mid/checkpoint.pt` |
|
| 25 |
+
| **Large** | 1024 | 40 | 32 | ~500M | `large/checkpoint.pt` |
|
| 26 |
+
|
| 27 |
+
## Architecture
|
| 28 |
+
|
| 29 |
+
- **Type**: Decoder-only Transformer (LLaMA-style)
|
| 30 |
+
- **Normalization**: RMSNorm (pre-norm)
|
| 31 |
+
- **FFN**: SwiGLU
|
| 32 |
+
- **Attention**: Bidirectional (no causal mask)
|
| 33 |
+
- **Input**: FEN string tokenized to 79 ASCII tokens
|
| 34 |
+
- **Output**: Dual-head — Policy (move classification, ~4544 classes) + Value (position evaluation, tanh [-1, 1])
|
| 35 |
+
- **Pooling**: Mean pooling over sequence
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
import torch
|
| 41 |
+
from artoria import ChessTokenizer, GrandmasterChessModel, ChessModelConfig
|
| 42 |
+
import json
|
| 43 |
+
|
| 44 |
+
# Load config
|
| 45 |
+
with open("small/config.json") as f:
|
| 46 |
+
config = ChessModelConfig(**json.load(f))
|
| 47 |
+
|
| 48 |
+
tokenizer = ChessTokenizer()
|
| 49 |
+
config.num_classes = tokenizer.num_actions
|
| 50 |
+
|
| 51 |
+
model = GrandmasterChessModel(config)
|
| 52 |
+
checkpoint = torch.load("small/checkpoint.pt", map_location="cpu")
|
| 53 |
+
model.load_state_dict(checkpoint["model_state_dict"])
|
| 54 |
+
model.eval()
|
| 55 |
+
|
| 56 |
+
# Predict move from FEN
|
| 57 |
+
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
| 58 |
+
tokens = tokenizer.tokenize(fen).unsqueeze(0)
|
| 59 |
+
|
| 60 |
+
with torch.no_grad():
|
| 61 |
+
logits, value = model(tokens)
|
| 62 |
+
|
| 63 |
+
# Get best legal move
|
| 64 |
+
import chess
|
| 65 |
+
board = chess.Board(fen)
|
| 66 |
+
best_move, best_prob = None, -1
|
| 67 |
+
probs = torch.softmax(logits[0], dim=0)
|
| 68 |
+
for m in board.legal_moves:
|
| 69 |
+
idx = tokenizer.action_to_class(m.uci())
|
| 70 |
+
if idx != -1 and probs[idx].item() > best_prob:
|
| 71 |
+
best_move, best_prob = m.uci(), probs[idx].item()
|
| 72 |
+
|
| 73 |
+
print(f"Best move: {best_move} (confidence: {best_prob:.4f}, eval: {value.item():.4f})")
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Training
|
| 77 |
+
|
| 78 |
+
Trained on Lichess standard chess games via behavioral cloning (imitation learning). The model learns to predict the next move played by strong players given a board position.
|
| 79 |
+
|
| 80 |
+
## Source Code
|
| 81 |
+
|
| 82 |
+
[github.com/ShinapriLN/artoria](https://github.com/ShinapriLN/artoria)
|
| 83 |
+
|
| 84 |
+
## License
|
| 85 |
+
|
| 86 |
+
MIT
|