Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- chess
|
| 5 |
+
- game-ai
|
| 6 |
+
- pytorch
|
| 7 |
+
- safetensors
|
| 8 |
+
library_name: transformers
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# ChessLC0 Chess Model
|
| 12 |
+
|
| 13 |
+
This is BT4, the model behind LeelaChessZero Engine, one of the best Neural Network based engine available. This model is way worse than stockfish but constitute one of the best 0 search heuristics out there.
|
| 14 |
+
For stronger play, reducing temperature T (lower is stronger) is suggested.
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
The ChessLC0 model is a transformer-based architecture designed for chess gameplay. It can:
|
| 19 |
+
- Predict the next best move given a move history (requires 7 prior boards)
|
| 20 |
+
- Evaluate chess positions
|
| 21 |
+
- Generate move probabilities
|
| 22 |
+
|
| 23 |
+
**Important**: This model requires move history (7 prior boards) to work properly. You must provide a list of UCI moves representing the game history.
|
| 24 |
+
|
| 25 |
+
## Please Like if this model is useful to you :)
|
| 26 |
+
|
| 27 |
+
A like goes a long way !
|
| 28 |
+
|
| 29 |
+
## Usage
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
import torch
|
| 33 |
+
from transformers import AutoModel
|
| 34 |
+
|
| 35 |
+
model = AutoModel.from_pretrained("Maxlegrec/ChessLC0", trust_remote_code=True)
|
| 36 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 37 |
+
model = model.to(device)
|
| 38 |
+
|
| 39 |
+
# Example usage with move history (model requires 7 prior boards)
|
| 40 |
+
# This sequence provides enough history for the model
|
| 41 |
+
move_history = [
|
| 42 |
+
"e2e4", "e7e5", "g1f3", "b8c6", "f1b5", "a7a6", "b5a4",
|
| 43 |
+
"g8f6", "e1g1", "f8e7", "f1e1", "b7b5", "a4b3", "d7d6"
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
# Sample move from policy
|
| 47 |
+
move = model.get_move_from_fen_no_thinking(move_history, T=0.1, device=device)
|
| 48 |
+
print(f"Policy-based move: {move}")
|
| 49 |
+
|
| 50 |
+
# Get the best move using value analysis
|
| 51 |
+
value_move, value = model.get_best_move_value(move_history, T=0, device=device)
|
| 52 |
+
print(f"Value-based move: {value_move}")
|
| 53 |
+
print(f"Position value [black_win, draw, white_win]: {value}")
|
| 54 |
+
|
| 55 |
+
# Get position evaluation
|
| 56 |
+
position_value = model.get_position_value(move_history, device=device)
|
| 57 |
+
print(f"Position value [black_win, draw, white_win]: {position_value}")
|
| 58 |
+
|
| 59 |
+
# Get move probabilities
|
| 60 |
+
probs = model.get_move_from_fen_no_thinking(move_history, T=1, device=device, return_probs=True)
|
| 61 |
+
top_moves = sorted(probs.items(), key=lambda x: x[1], reverse=True)[:5]
|
| 62 |
+
print("Top 5 moves:")
|
| 63 |
+
for move, prob in top_moves:
|
| 64 |
+
print(f" {move}: {prob:.4f}")
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Requirements
|
| 68 |
+
|
| 69 |
+
python-version <=3.11
|
| 70 |
+
cuda-version < 13.0
|
| 71 |
+
|
| 72 |
+
- torch>=2.0.0
|
| 73 |
+
- transformers>=4.48.1
|
| 74 |
+
- bulletchess>=0.4.0
|
| 75 |
+
- numpy>=1.21.0
|
| 76 |
+
|
| 77 |
+
## Model Architecture
|
| 78 |
+
|
| 79 |
+
- **Transformer layers**: 15
|
| 80 |
+
- **Hidden size**: 1024
|
| 81 |
+
- **Feed-forward size**: 1536
|
| 82 |
+
- **Attention heads**: 32
|
| 83 |
+
- **Vocabulary size**: 1858 (chess moves)
|