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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
library_name: onnx
|
| 4 |
+
tags:
|
| 5 |
+
- chess
|
| 6 |
+
- deep-learning
|
| 7 |
+
- pytorch
|
| 8 |
+
- onnx
|
| 9 |
+
- strategy
|
| 10 |
+
- game-ai
|
| 11 |
+
datasets:
|
| 12 |
+
- Rafs-an09002/chessmate-opening-stats
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
pipeline_tag: reinforcement-learning
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# ♟️ ChessMate AI - CNN Evaluation Model
|
| 19 |
+
|
| 20 |
+
<div align="center">
|
| 21 |
+
|
| 22 |
+

|
| 23 |
+
|
| 24 |
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
| 25 |
+

|
| 26 |
+

|
| 27 |
+
|
| 28 |
+
[**Live Demo**](https://chessmate-engine.onrender.com) • [**GitHub Repository**](https://github.com/Rafsan1711/Chessmate-Engine)
|
| 29 |
+
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
## 📖 Model Description
|
| 33 |
+
|
| 34 |
+
This is a **Convolutional Neural Network (CNN)** trained to evaluate chess positions. It takes a board state as input and outputs a scalar evaluation score between `-1` (Black winning) and `+1` (White winning).
|
| 35 |
+
|
| 36 |
+
It is the core "brain" of the **ChessMate AI** project, designed to run efficiently in web browsers using `onnxruntime-web`.
|
| 37 |
+
|
| 38 |
+
- **Architecture:** 3-Layer CNN with Batch Normalization and ReLU activation.
|
| 39 |
+
- **Framework:** Trained in PyTorch, exported to ONNX (Opset 14).
|
| 40 |
+
- **Size:** ~7.5 MB (Highly optimized for web loading).
|
| 41 |
+
- **Training Data:** 100,000+ Master-level games from Lichess (Standard Rated > 2000 ELO).
|
| 42 |
+
|
| 43 |
+
## 🛠️ Technical Specifications
|
| 44 |
+
|
| 45 |
+
### Input Shape
|
| 46 |
+
The model expects a Tensor of shape `(1, 12, 8, 8)` representing the board state using One-Hot Encoding.
|
| 47 |
+
|
| 48 |
+
- **Channels (12):**
|
| 49 |
+
- 0-5: White Pieces (Pawn, Knight, Bishop, Rook, Queen, King)
|
| 50 |
+
- 6-11: Black Pieces (Pawn, Knight, Bishop, Rook, Queen, King)
|
| 51 |
+
- **Dimensions (8x8):** The chess board squares.
|
| 52 |
+
|
| 53 |
+
### Output
|
| 54 |
+
- **Shape:** `(1, 1)`
|
| 55 |
+
- **Value:** Float between `-1.0` and `1.0`.
|
| 56 |
+
- `> 0`: Advantage White
|
| 57 |
+
- `< 0`: Advantage Black
|
| 58 |
+
- `~ 0`: Equal/Draw
|
| 59 |
+
|
| 60 |
+
## 💻 Usage (JavaScript / ONNX.js)
|
| 61 |
+
|
| 62 |
+
This model is designed to be used directly in the browser via `onnxruntime-web`.
|
| 63 |
+
|
| 64 |
+
```javascript
|
| 65 |
+
import * as ort from 'onnxruntime-web';
|
| 66 |
+
|
| 67 |
+
// 1. Load the session
|
| 68 |
+
const session = await ort.InferenceSession.create('./chess_model.onnx');
|
| 69 |
+
|
| 70 |
+
// 2. Prepare Input (Float32Array of size 12*8*8)
|
| 71 |
+
// Convert FEN string to 12x8x8 one-hot encoded array
|
| 72 |
+
const inputData = new Float32Array(768).fill(0);
|
| 73 |
+
// ... (Fill array based on piece positions) ...
|
| 74 |
+
|
| 75 |
+
const tensor = new ort.Tensor('float32', inputData, [1, 12, 8, 8]);
|
| 76 |
+
|
| 77 |
+
// 3. Run Inference
|
| 78 |
+
const results = await session.run({ board_state: tensor });
|
| 79 |
+
const evaluation = results.evaluation.data[0];
|
| 80 |
+
|
| 81 |
+
console.log(`Position Score: ${evaluation}`);
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## 🧠 Training Details
|
| 85 |
+
|
| 86 |
+
- **Loss Function:** Mean Squared Error (MSE)
|
| 87 |
+
- **Optimizer:** Adam (lr=0.001)
|
| 88 |
+
- **Epochs:** 50 (with Early Stopping)
|
| 89 |
+
- **Target Label:** Normalized Stockfish Evaluation / Game Result (Win/Loss/Draw).
|
| 90 |
+
|
| 91 |
+
## ⚠️ License & Limitations
|
| 92 |
+
|
| 93 |
+
This model is licensed under **CC BY-NC 4.0** (Attribution-NonCommercial 4.0 International).
|
| 94 |
+
|
| 95 |
+
**You are free to:**
|
| 96 |
+
- Use this model for research, education, and personal projects.
|
| 97 |
+
- Modify and adapt the model.
|
| 98 |
+
|
| 99 |
+
**You may NOT:**
|
| 100 |
+
- Sell this model or use it in a commercial product without permission.
|
| 101 |
+
|
| 102 |
+
---
|
| 103 |
+
<div align="center">
|
| 104 |
+
<p>Created by <a href="https://github.com/Rafsan1711">Rafsan1711</a></p>
|
| 105 |
+
</div>
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
### 2. Dataset Repository (`chessmate-opening-stats`) - README
|
| 111 |
+
|
| 112 |
+
এটি কপি করে আপনার **Dataset Repository**-র `README.md` ফাইলে পেস্ট করুন।
|
| 113 |
+
|
| 114 |
+
```markdown
|
| 115 |
+
---
|
| 116 |
+
license: cc-by-nc-4.0
|
| 117 |
+
task_categories:
|
| 118 |
+
- reinforcement-learning
|
| 119 |
+
- tabular-classification
|
| 120 |
+
language:
|
| 121 |
+
- en
|
| 122 |
+
tags:
|
| 123 |
+
- chess
|
| 124 |
+
- opening
|
| 125 |
+
- statistics
|
| 126 |
+
- game-ai
|
| 127 |
+
size_categories:
|
| 128 |
+
- 1M<n<10M
|
| 129 |
+
pretty_name: ChessMate Opening Statistics
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
# ♟️ ChessMate AI - Opening Statistics Database
|
| 133 |
+
|
| 134 |
+
<div align="center">
|
| 135 |
+
|
| 136 |
+

|
| 137 |
+
|
| 138 |
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
| 139 |
+

|
| 140 |
+

|
| 141 |
+
|
| 142 |
+
[**Live Explorer**](https://chessmate-engine.onrender.com) • [**GitHub Repository**](https://github.com/Rafsan1711/Chessmate-Engine)
|
| 143 |
+
|
| 144 |
+
</div>
|
| 145 |
+
|
| 146 |
+
## 📖 Dataset Description
|
| 147 |
+
|
| 148 |
+
This dataset contains aggregated opening statistics derived from over **100,000 high-rated Lichess games** (ELO 2000+). It maps chess board positions (FEN) to their historical outcomes (White Win, Draw, Black Win).
|
| 149 |
+
|
| 150 |
+
It is designed to power the **ChessMate AI Opening Explorer** and serve as an opening book for the engine.
|
| 151 |
+
|
| 152 |
+
- **Source:** Lichess Standard Rated Games (Feb 2016).
|
| 153 |
+
- **Format:** SQLite Database (`.db`).
|
| 154 |
+
- **Optimization:** Indexed by FEN for O(1) lookup speed.
|
| 155 |
+
|
| 156 |
+
## 📂 File Structure
|
| 157 |
+
|
| 158 |
+
The main file is `chess_stats.db`, which contains a single table:
|
| 159 |
+
|
| 160 |
+
### Table: `positions`
|
| 161 |
+
|
| 162 |
+
| Column | Type | Description |
|
| 163 |
+
|--------|------|-------------|
|
| 164 |
+
| `fen` | TEXT (PK) | The board position in Forsyth–Edwards Notation (Primary Key). |
|
| 165 |
+
| `stats` | TEXT | JSON string containing move counts and win rates. |
|
| 166 |
+
|
| 167 |
+
**Example JSON in `stats` column:**
|
| 168 |
+
```json
|
| 169 |
+
{
|
| 170 |
+
"total": 520,
|
| 171 |
+
"moves": {
|
| 172 |
+
"e4": { "white": 200, "black": 150, "draw": 170 },
|
| 173 |
+
"d4": { "white": 100, "black": 80, "draw": 20 }
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
## 🛠️ Usage (Node.js / Better-SQLite3)
|
| 179 |
+
|
| 180 |
+
This database is designed to be streamed or downloaded by a backend service.
|
| 181 |
+
|
| 182 |
+
```javascript
|
| 183 |
+
const Database = require('better-sqlite3');
|
| 184 |
+
const db = new Database('chess_stats.db', { readonly: true });
|
| 185 |
+
|
| 186 |
+
const fen = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR";
|
| 187 |
+
const row = db.prepare('SELECT stats FROM positions WHERE fen = ?').get(fen);
|
| 188 |
+
|
| 189 |
+
if (row) {
|
| 190 |
+
console.log(JSON.parse(row.stats));
|
| 191 |
+
}
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
## ⚠️ License
|
| 195 |
+
|
| 196 |
+
This dataset is licensed under **CC BY-NC 4.0** (Attribution-NonCommercial 4.0 International).
|
| 197 |
+
|
| 198 |
+
**You are free to:**
|
| 199 |
+
- Use this data for research, education, and personal projects.
|
| 200 |
+
|
| 201 |
+
**You may NOT:**
|
| 202 |
+
- Sell this data or use it in a commercial product without permission.
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
<div align="center">
|
| 206 |
+
<p>Created by <a href="https://github.com/Rafsan1711">Rafsan1711</a></p>
|
| 207 |
+
</div>
|