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