Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- chess
|
| 6 |
+
- reinforcement-learning
|
| 7 |
+
- alphazero
|
| 8 |
+
- pytorch
|
| 9 |
+
library_name: pytorch
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Chess Bot Model - TinyPCN
|
| 13 |
+
|
| 14 |
+
A chess playing neural network trained on expert games from the Lichess Elite Database.
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
This is a policy-value network inspired by AlphaZero, designed to evaluate chess positions and suggest moves.
|
| 19 |
+
|
| 20 |
+
### Architecture
|
| 21 |
+
|
| 22 |
+
- **Input**: 18-plane board representation (12 pieces + 6 metadata planes)
|
| 23 |
+
- **Convolutional backbone**: 32 filters, 1 residual block, ~9,611,202 parameters
|
| 24 |
+
- **Policy head**: 4,672-dimensional output (one per legal move encoding)
|
| 25 |
+
- **Value head**: Single tanh output (-1 to +1 for position evaluation)
|
| 26 |
+
|
| 27 |
+
### Training Data
|
| 28 |
+
|
| 29 |
+
- **Dataset**: Lichess Elite Database (games from 2200+ ELO players)
|
| 30 |
+
- **Positions trained**: 16,800,000
|
| 31 |
+
- **Epochs**: 10
|
| 32 |
+
|
| 33 |
+
### Performance
|
| 34 |
+
|
| 35 |
+
- **Final Policy Loss**: 2.8000
|
| 36 |
+
- **Final Value Loss**: 0.8500
|
| 37 |
+
|
| 38 |
+
### Usage
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
import torch
|
| 42 |
+
import chess
|
| 43 |
+
from model import TinyPCN, encode_board
|
| 44 |
+
|
| 45 |
+
# Load model
|
| 46 |
+
model = TinyPCN(board_channels=18, policy_size=4672)
|
| 47 |
+
model.load_state_dict(torch.load("chess_model.pth"))
|
| 48 |
+
model.eval()
|
| 49 |
+
|
| 50 |
+
# Evaluate a position
|
| 51 |
+
board = chess.Board() # or chess.Board("fen string")
|
| 52 |
+
board_tensor = encode_board(board).unsqueeze(0)
|
| 53 |
+
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
policy_logits, value = model(board_tensor)
|
| 56 |
+
|
| 57 |
+
# Value interpretation:
|
| 58 |
+
# +1.0 = winning for current player
|
| 59 |
+
# 0.0 = drawn/equal position
|
| 60 |
+
# -1.0 = losing for current player
|
| 61 |
+
|
| 62 |
+
print(f"Position evaluation: {value.item():.4f}")
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
### Model Files
|
| 66 |
+
|
| 67 |
+
- `chess_model.pth` - PyTorch model weights
|
| 68 |
+
- `model.py` - Model architecture and board encoding
|
| 69 |
+
- `mcts.py` - Monte Carlo Tree Search implementation
|
| 70 |
+
- `requirements.txt` - Python dependencies
|
| 71 |
+
|
| 72 |
+
### Limitations
|
| 73 |
+
|
| 74 |
+
- Trained on expert games only (no self-play yet)
|
| 75 |
+
- Lightweight architecture for educational purposes
|
| 76 |
+
- May not handle unusual openings or endgames well
|
| 77 |
+
|
| 78 |
+
### Training Details
|
| 79 |
+
|
| 80 |
+
- **Framework**: PyTorch
|
| 81 |
+
- **Optimizer**: Adam
|
| 82 |
+
- **Learning Rate**: 0.001
|
| 83 |
+
- **Batch Size**: 256
|
| 84 |
+
- **Loss Functions**: CrossEntropyLoss (policy) + MSELoss (value)
|
| 85 |
+
|
| 86 |
+
### Authors
|
| 87 |
+
|
| 88 |
+
Created as part of an AlphaZero-style chess engine project.
|
| 89 |
+
|
| 90 |
+
### License
|
| 91 |
+
|
| 92 |
+
MIT License
|