Upload ChessBot Chess model
Browse files- README.md +66 -9
- config.json +3 -1
- usage_example.py +2 -6
README.md
CHANGED
@@ -1,16 +1,73 @@
|
|
1 |
---
|
2 |
license: mit
|
3 |
-
pipeline_tag: tabular-classification
|
4 |
tags:
|
5 |
-
- board-games
|
6 |
- chess
|
7 |
-
- model_hub_mixin
|
8 |
-
- pytorch_model_hub_mixin
|
9 |
- reinforcement-learning
|
10 |
-
-
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
|
|
3 |
tags:
|
|
|
4 |
- chess
|
|
|
|
|
5 |
- reinforcement-learning
|
6 |
+
- game-ai
|
7 |
+
- pytorch
|
8 |
+
library_name: transformers
|
9 |
---
|
10 |
|
11 |
+
# ChessBot Chess Model
|
12 |
+
|
13 |
+
This is a ChessBot model for chess move prediction and position evaluation.
|
14 |
+
|
15 |
+
## Model Description
|
16 |
+
|
17 |
+
The ChessBot model is a transformer-based architecture designed for chess gameplay. It can:
|
18 |
+
- Predict the next best move given a chess position (FEN)
|
19 |
+
- Evaluate chess positions
|
20 |
+
- Generate move probabilities
|
21 |
+
|
22 |
+
## Usage
|
23 |
+
|
24 |
+
```python
|
25 |
+
import torch
|
26 |
+
from huggingface_hub import snapshot_download
|
27 |
+
|
28 |
+
# Download the model files
|
29 |
+
model_path = snapshot_download(repo_id="Maxlegrec/ChessBot")
|
30 |
+
|
31 |
+
# Add to path and import
|
32 |
+
import sys
|
33 |
+
sys.path.append(model_path)
|
34 |
+
from modeling_chessbot import ChessBotModel, ChessBotConfig
|
35 |
+
|
36 |
+
# Load the model
|
37 |
+
config = ChessBotConfig()
|
38 |
+
model = ChessBotModel.from_pretrained(model_path)
|
39 |
+
|
40 |
+
# Example usage
|
41 |
+
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
42 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
43 |
+
model = model.to(device)
|
44 |
+
|
45 |
+
# Get the best move
|
46 |
+
move = model.get_move_from_fen_no_thinking(fen, T=0.1, device=device)
|
47 |
+
print(f"Predicted move: {move}")
|
48 |
+
```
|
49 |
+
|
50 |
+
## Requirements
|
51 |
+
|
52 |
+
- torch>=2.0.0
|
53 |
+
- transformers>=4.30.0
|
54 |
+
- python-chess>=1.10.0
|
55 |
+
- numpy>=1.21.0
|
56 |
+
|
57 |
+
## Model Architecture
|
58 |
+
|
59 |
+
- **Transformer layers**: 10
|
60 |
+
- **Hidden size**: 512
|
61 |
+
- **Feed-forward size**: 736
|
62 |
+
- **Attention heads**: 8
|
63 |
+
- **Vocabulary size**: 1929 (chess moves)
|
64 |
+
|
65 |
+
## Training Data
|
66 |
+
|
67 |
+
This model was trained on chess game data to learn optimal move selection and position evaluation.
|
68 |
+
|
69 |
+
## Limitations
|
70 |
+
|
71 |
+
- The model works best with standard chess positions
|
72 |
+
- Performance may vary with unusual or rare positions
|
73 |
+
- Requires GPU for optimal inference speed
|
config.json
CHANGED
@@ -2,7 +2,9 @@
|
|
2 |
"d_ff": 736,
|
3 |
"d_model": 512,
|
4 |
"max_position_embeddings": 64,
|
|
|
5 |
"num_heads": 8,
|
6 |
"num_layers": 10,
|
|
|
7 |
"vocab_size": 1929
|
8 |
-
}
|
|
|
2 |
"d_ff": 736,
|
3 |
"d_model": 512,
|
4 |
"max_position_embeddings": 64,
|
5 |
+
"model_type": "chessbot",
|
6 |
"num_heads": 8,
|
7 |
"num_layers": 10,
|
8 |
+
"transformers_version": "4.53.1",
|
9 |
"vocab_size": 1929
|
10 |
+
}
|
usage_example.py
CHANGED
@@ -10,16 +10,12 @@ This model can be used without installing any external packages except:
|
|
10 |
|
11 |
import torch
|
12 |
import sys
|
13 |
-
|
14 |
-
|
15 |
-
# Get the directory of this script (the model directory)
|
16 |
-
model_dir = os.path.dirname(os.path.abspath(__file__))
|
17 |
-
sys.path.append(model_dir) # Add the model directory to path
|
18 |
from modeling_chessbot import ChessBotModel, ChessBotConfig
|
19 |
|
20 |
# Load the model
|
21 |
config = ChessBotConfig()
|
22 |
-
model = ChessBotModel.from_pretrained(
|
23 |
|
24 |
# Example usage
|
25 |
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
|
|
10 |
|
11 |
import torch
|
12 |
import sys
|
13 |
+
sys.path.append("./") # Add the model directory to path
|
|
|
|
|
|
|
|
|
14 |
from modeling_chessbot import ChessBotModel, ChessBotConfig
|
15 |
|
16 |
# Load the model
|
17 |
config = ChessBotConfig()
|
18 |
+
model = ChessBotModel.from_pretrained("./")
|
19 |
|
20 |
# Example usage
|
21 |
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|