Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
| 1 |
-
---
|
| 2 |
-
license:
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
library_name: onnx
|
| 4 |
+
tags:
|
| 5 |
+
- chess
|
| 6 |
+
- deep-learning
|
| 7 |
+
- pytorch
|
| 8 |
+
- onnx
|
| 9 |
+
- resnet
|
| 10 |
+
- strategy
|
| 11 |
+
- game-ai
|
| 12 |
+
- gambitflow
|
| 13 |
+
datasets:
|
| 14 |
+
- Rafs-an09002/gambitflow-elite-data
|
| 15 |
+
language:
|
| 16 |
+
- en
|
| 17 |
+
pipeline_tag: reinforcement-learning
|
| 18 |
+
metrics:
|
| 19 |
+
- mse
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# ♟️ GambitFlow Nexus-core (CE)
|
| 23 |
+
|
| 24 |
+
<div align="center">
|
| 25 |
+
|
| 26 |
+

|
| 27 |
+
|
| 28 |
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
| 29 |
+

|
| 30 |
+

|
| 31 |
+
-green)
|
| 32 |
+
|
| 33 |
+
[**Live Engine Demo**](https://chessmate-engine.onrender.com/) • [**GitHub Repository**](https://github.com/NeuraxLabs/GambitFlow)
|
| 34 |
+
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
## 📖 Model Overview
|
| 38 |
+
|
| 39 |
+
**Nexus-core CE** is the flagship chess engine of the **GambitFlow** project. It is a deep neural network designed to evaluate chess positions with grandmaster-like intuition. unlike traditional engines (like early Stockfish versions) that rely on hand-crafted evaluation functions, Nexus-core learned chess strategy by analyzing millions of games played by elite human players.
|
| 40 |
+
|
| 41 |
+
It serves as the static evaluation function (brain) for the GambitFlow search algorithm.
|
| 42 |
+
|
| 43 |
+
## 🧠 Technical Architecture
|
| 44 |
+
|
| 45 |
+
The model is built using a **Residual Neural Network (ResNet)** architecture, inspired by AlphaZero but optimized for web deployment.
|
| 46 |
+
|
| 47 |
+
| Component | Specification | Description |
|
| 48 |
+
| :--- | :--- | :--- |
|
| 49 |
+
| **Input Layer** | `(1, 12, 8, 8)` | A 12-channel bitboard representation. Channels 0-5 for White pieces, 6-11 for Black pieces. |
|
| 50 |
+
| **Convolutional Block** | 128 Filters, 3x3 Kernel | Initial feature extraction from the raw board state. |
|
| 51 |
+
| **Residual Tower** | **10 Blocks** | A stack of 10 Residual Blocks. Each block consists of `Conv2d -> BatchNorm -> ReLU -> Conv2d -> BatchNorm -> Add -> ReLU`. This depth allows the model to understand complex spatial patterns and long-term strategy. |
|
| 52 |
+
| **Value Head** | Dense / Linear | Compresses the extracted features into a single scalar value. |
|
| 53 |
+
| **Output** | `Scalar (-1.0 to 1.0)` | `Tanh` activated score. Positive values favor White, negative values favor Black. |
|
| 54 |
+
| **Parameter Count** | **~3.5 Million** | Optimized for balancing depth and inference speed in browsers. |
|
| 55 |
+
|
| 56 |
+
## 📊 Training Methodology
|
| 57 |
+
|
| 58 |
+
The model was trained using a highly optimized pipeline on Google Colab (T4 GPUs).
|
| 59 |
+
|
| 60 |
+
### 1. Data Source ("The Elite Dataset")
|
| 61 |
+
We did not use random chess games. We curated a dataset (`gambitflow-elite-data`) specifically for high-level play.
|
| 62 |
+
- **Source:** Lichess Standard Rated Games (January 2017).
|
| 63 |
+
- **Filtering Criteria:** Both White and Black players must have an **ELO > 2000**.
|
| 64 |
+
- **Volume:** Over **5,000,000 unique positions** extracted from the first 20 moves of elite games.
|
| 65 |
+
|
| 66 |
+
### 2. Training Protocol
|
| 67 |
+
- **Framework:** PyTorch 2.5.1.
|
| 68 |
+
- **Optimization:**
|
| 69 |
+
- **Mixed Precision (AMP):** Used `torch.amp.autocast` (float16) to double the batch size and training speed without losing accuracy.
|
| 70 |
+
- **Optimizer:** AdamW with Weight Decay.
|
| 71 |
+
- **Loss Function:** Mean Squared Error (MSE) comparing the model's evaluation against the actual game outcome (0, 0.5, or 1).
|
| 72 |
+
- **Gradient Accumulation:** Effective batch size of 1024 to ensure stable convergence.
|
| 73 |
+
|
| 74 |
+
### 3. Export & Optimization
|
| 75 |
+
- The model was exported to **ONNX** format using **Opset Version 17**.
|
| 76 |
+
- **Constant Folding** was enabled to bake static parts of the graph into the model, reducing runtime overhead.
|
| 77 |
+
- Validated for **WebAssembly (WASM)** compatibility via `onnxruntime-web`.
|
| 78 |
+
|
| 79 |
+
## 💻 Usage (JavaScript / ONNX Runtime)
|
| 80 |
+
|
| 81 |
+
This model is designed to run client-side.
|
| 82 |
+
|
| 83 |
+
```javascript
|
| 84 |
+
import * as ort from 'onnxruntime-web';
|
| 85 |
+
|
| 86 |
+
// 1. Initialize Session
|
| 87 |
+
const session = await ort.InferenceSession.create('./chess_model_v2.onnx');
|
| 88 |
+
|
| 89 |
+
// 2. Encode Board (FEN to Tensor)
|
| 90 |
+
// Input must be a Float32Array of size 768 (12x8x8 flattened)
|
| 91 |
+
const inputTensor = new ort.Tensor('float32', float32Array, [1, 12, 8, 8]);
|
| 92 |
+
|
| 93 |
+
// 3. Run Inference
|
| 94 |
+
const results = await session.run({ board_state: inputTensor });
|
| 95 |
+
const evaluation = results.evaluation.data[0];
|
| 96 |
+
|
| 97 |
+
console.log("Position Score:", evaluation);
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## ⚠️ License
|
| 101 |
+
|
| 102 |
+
**GambitFlow Nexus-core** is licensed under the **Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)** license.
|
| 103 |
+
|
| 104 |
+
- **Allowed:** Personal use, educational research, forking for non-commercial improvements.
|
| 105 |
+
- **Prohibited:** Selling the model, using it in paid software services, or claiming it as your own without attribution.
|
| 106 |
+
|
| 107 |
+
---
|