Spaces:
Sleeping
Sleeping
setting up yaml for README
Browse files
README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Transformer4Chess
|
| 3 |
+
emoji: ♟️
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
short_description: Transformer-based chess move predictor served via FastAPI.
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Transformer4Chess
|
| 13 |
+
|
| 14 |
+
A FastAPI inference service for a transformer-based chess policy model. Given a list of UCI moves played from the starting position, it returns the model's predicted next move.
|
| 15 |
+
|
| 16 |
+
## API
|
| 17 |
+
|
| 18 |
+
### `POST /inference`
|
| 19 |
+
|
| 20 |
+
**Request body:**
|
| 21 |
+
|
| 22 |
+
```json
|
| 23 |
+
{
|
| 24 |
+
"moves": ["e2e4", "e7e5", "g1f3"]
|
| 25 |
+
}
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
- `moves` — list of UCI-encoded moves played from the standard starting position.
|
| 29 |
+
|
| 30 |
+
**Response:**
|
| 31 |
+
|
| 32 |
+
```json
|
| 33 |
+
{
|
| 34 |
+
"move": "b8c6"
|
| 35 |
+
}
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
**Status codes:**
|
| 39 |
+
|
| 40 |
+
- `200` — inference succeeded.
|
| 41 |
+
- `400` — one of the supplied moves is illegal in the resulting position.
|
| 42 |
+
- `500` — the model failed to evaluate the position.
|
| 43 |
+
|
| 44 |
+
### Interactive docs
|
| 45 |
+
|
| 46 |
+
FastAPI auto-generates Swagger UI at `/docs` and ReDoc at `/redoc`.
|
| 47 |
+
|
| 48 |
+
## Local development
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
python3.12 -m venv .venv
|
| 52 |
+
source .venv/bin/activate
|
| 53 |
+
pip install -r requirements.txt
|
| 54 |
+
uvicorn app:app --reload
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Then:
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
curl -X POST http://127.0.0.1:8000/inference \
|
| 61 |
+
-H "Content-Type: application/json" \
|
| 62 |
+
-d '{"moves": ["e2e4", "e7e5"]}'
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Model
|
| 66 |
+
|
| 67 |
+
- `ChessPolicyModel` — causal transformer with per-position CNN board cross-attention.
|
| 68 |
+
- `Tokenizer` — BPE-style tokenizer trained on UCI move strings.
|
| 69 |
+
- Weights and tokenizer are loaded once at startup via FastAPI's `lifespan` hook.
|