Made by Sai, Saaketh and Ragul for GatorHacks V!
Ever played a chess game where you're playing beautifully, then BAM! You've blundered, you lose, and you know exactly what you could have done instead to keep your momentum. Introducing takeback, a tool that allows users to replay their past games with an AI clone of themselves acting as their opponent.
takeback focuses on simulating how real players play, through their tendencies and pacing. An AI clone of you plays as your opponent, allowing you to replay your moves within the game. Users can analyze their past games move by move, with game commentary from Gemma in 'analyze' mode. takeback allows users to sign in with their chess.com usernames, connecting their gameplay data to the application. From there, our clone model trains against Maia's move probability of the users' games, and scores the likelihood of the moves the user plays, taking into account their tendencies, pacing, consistent tactics, and other components of their game to imbibe their style. Soon after users put in their chess.com username to takeback, they have a trained clone model they can play against, analyzing their mistakes and improving their gameplay.
takeback was built with chess players of all skill levels in mind. We wanted to curate the experience for in-game analysis in a clean easy-to-use UI that is supported by cutting edge tech through the Maia version 3 chess model and our own custom-built MLP model for extracting user tendencies and pacing to build their clone. The model works by training on snapshots of each move in a game, understanding the board and player positions, the time players take for their moves, and likely next moves, training on the moves the user makes. Over hundreds of games, the model imbibes the player's tendencies and chess persona.
The application was built using TypeScript and SvelteKit for clean, efficient reactive frontend development, a PostgreSQL database with pgvector for board embedding storage, a FastAPI backend with PyTorch CPU & Stockfish 16, and a local llama.cpp:server running Gemma 2 2B for commentary. Docker was used to allow anybody to run our entire open-source stack with just one command.
Our main challenge was ensuring our clone model could really help chess players in analyzing their blunders. We weighed the pros and cons of using different model architectures, such as LoRA models or having averaged outputs from a random forest model, before finally deciding on the MLP adapter for our chess clone. Integrating our model to the application, specifically the backend required rigorous testing and improvements before the user could smoothly analyze their performance by playing their clone.
We are proud of creating the clone that outperforms the baseline Maia model with an accuracy of around 60%. Our application also supports the game data of many users, storing games of different types, including rapid and blitz games. takeback's analysis mode came out how we envisioned it, allowing the user to see in real time the right moves they could have made to win, along with the reasoning of their clone opponent all supported by Gemma's commentary.
You can create a chess clone! We learned how an MLP model works in the context of our problem, how to create efficient model architectures, and how to think about defining an ML pipeline and system. Our team also learned about various processes of building an end-to-end AI application, through parsing PGNs from chess.com, to integrating an AI model that could do more than just a simple chatbot.
We want to bring our application to more users, chess players of all skill levels. We aim to grow and scale our application to handle hundreds of games for hundreds of users, streamlining our model training, and data pipelines while ensuring our application remains working for a high load.
The system is built as a modular microservice architecture orchestrated via Docker Compose:
flowchart TD
subgraph Client["Browser Client"]
UI["SvelteKit Frontend (Port 3000)<br/>Interactive Chessground UI"]
end
subgraph DockerHost["Docker Container Network"]
subgraph Backend["FastAPI Application (Port 8000)"]
API["REST & SSE Controller"]
Worker["Background Training Worker"]
ML["Maia-3 + Clone MLP Engine"]
SF["Stockfish 16 Engine Binary"]
end
subgraph LLM["Gemma 2 LLM Server (Port 8080)"]
Llama["llama.cpp:server<br/>Gemma 2 2B Instruct (Q4_K_M)"]
end
subgraph DB["Database (Port 5432)"]
PG["PostgreSQL 16 + pgvector<br/>Persistent Volume: postgres_data"]
end
end
UI -->|HTTP / SSE| API
API -->|Async Queries / Vector Ops| PG
API -->|OpenAI-Compatible REST| Llama
API -->|UCI Protocol| SF
API -->|Inference & Training| ML
Worker -->|Async Training Updates| PG
Worker -->|SSE Broadcast| UI
| Service | Technology | Port | Description |
|---|---|---|---|
frontend |
SvelteKit 2 + Vite + TailwindCSS | 3000 |
Reactive chess interface featuring interactive board (chessground), move annotation timeline, clone challenge arena, and game analysis reports. |
backend |
FastAPI + PyTorch CPU + Stockfish 16 | 8000 |
REST API handling JWT authentication, PGN parsing, real-time Maia-3 inference, clone MLP personalization, and background SSE training queues. |
gemma |
llama.cpp:server (Gemma 2 2B IT) | 8080 |
High-efficiency local CPU LLM runner serving gemma-2-2b-it-Q4_K_M.gguf via an OpenAI-compatible REST endpoint for human-like game commentary. |
db |
PostgreSQL 16 Alpine + pgvector | 5432 |
Relational storage for users, games, individual plies, and model metadata, equipped with pgvector for board embedding search and composite b-tree indexes for zero-latency pagination. |
The AI clone combines a foundation chess policy with a personalized neural adapter:
flowchart LR
Board["Chess Board Position + Clock State"] --> FExt["Feature Extractor (28 features)"]
Board --> Maia["Maia-3 Foundation (5M Transformer)"]
Maia --> MLogits["Maia Move Logits (64)"]
FExt --> MLP["Clone MLP Trunk (28 -> 64 -> 64)"]
MLP --> MHead["Move Head (Offsets)"]
MLP --> THead["Time Head (Mean ΞΌ, Log-Std Ο)"]
MLogits --> Combine["Logit Addition + Masking"]
MHead --> Combine
Combine --> MoveChoice["Personalized Move Probability"]
THead --> TimeDist["Log-Normal Think Time Distribution"]
- Maia-3 Foundation Transformer (5M parameters): Provides human-like move probabilities learned from millions of online human games across diverse ratings.
-
Personalized Clone MLP:
-
Trunk: Multi-layer perceptron (input: 28 hand-crafted tactical & context features
$\to$ 64$\to$ 64 with ReLU activations). - Move Head: Outputs 64 move offset values added directly to Maia-3's logit distribution. Initialized to zero so unadapted models exactly match Maia-3.
-
Think Time Head: 2-parameter output
$(\mu, \log \sigma)$ modeling move duration as a Log-Normal distribution$\text{LogNormal}(\mu, \sigma^2)$ conditioned on position complexity, remaining clock, opponent think time, and ply number.
-
Trunk: Multi-layer perceptron (input: 28 hand-crafted tactical & context features
- Joint Loss Objective: $$\mathcal{L} = \mathcal{L}{\text{CE}}(\text{move}) + 0.2 \cdot \mathcal{L}{\text{NLL}}(\text{think time})$$
- Docker (v24.0 or later)
- Docker Compose (v2.20 or later)
cd revisedThe project comes pre-configured with sensible defaults. To customize secrets or credentials:
cp .env.example .envRun the Docker Compose stack in detached mode:
docker compose up --build -dNote
On the first run, Docker will download the necessary base images, fetch the Gemma 2 2B GGUF weights, and download the Maia-3 (5M) model into ./models. Stockfish 16 is pre-installed automatically inside the backend image.
Check that all 4 containers are running and healthy:
docker compose psYou can inspect logs at any time:
docker compose logs -f backend- Web Application: Open http://localhost:3000
- FastAPI Documentation (Swagger UI): http://localhost:8000/docs
- Gemma LLM Server: http://localhost:8080/v1/models
- PostgreSQL Database:
localhost:5432(user: chess_user,password: chess_password,database: chess_db)
To stop all containers cleanly:
docker compose downTo stop and remove stored database volumes:
docker compose down -vTo train or reproduce the clone model directly outside of Docker:
python3 -m venv .venv
source .venv/bin/activate
pip install -r revised/backend/requirements.txtRun the standalone reproduction script:
python FINAL_MODEL/run.py stuffynessThis pipeline automatically:
- Loads player games (or fetches recent games via the Chess.com public API).
- Generates game snapshots with clock calculations and legal move masking.
- Computes 28-dimensional context features and Maia-3 foundation logits.
- Trains the personalized Clone MLP adapter using early stopping on validation move loss.
- Launches an interactive terminal chess game against the newly trained clone!
PYTHONPATH=. pytest tests/All 9 unit and pipeline verification tests (zero-offset exact match, 28-feature dimension, split integrity, clock arithmetic, and backend analysis module) will execute and validate.
βββ revised/ # Complete containerized application
β βββ docker-compose.yml # Orchestrates db, gemma, backend, frontend
β βββ .env / .env.example # Environment configuration
β βββ database/init.sql # PostgreSQL 16 DDL with pgvector
β βββ backend/ # FastAPI application (Python 3.11, PyTorch, Stockfish)
β βββ frontend/ # SvelteKit reactive UI
βββ FINAL_MODEL/ # Canonical model training & evaluation pipeline
β βββ run.py # End-to-end model training & play CLI
β βββ implementation.py # Clone MLP architecture & training loops
β βββ features.py # 28-feature contextual extractor
β βββ snapshots.py # Clock & ply snapshot builder
β βββ maia_extractor.py # Maia-3 batch feature extractor
β βββ play_clone.py # Interactive UCI clone engine
β βββ chess_pgn_parser.py # Chess.com PGN ingest
βββ maia3/ # Maia-3 PyTorch transformer foundation
βββ models/ # Local model weights directory (maia3-5m.pt)
βββ snapshots_dataset.pt # Precomputed 18,000-snapshot tensor dataset
βββ model_analysis/ # Empirical evaluation figures, infographics, and reports
βββ analysis/ # Host-side analysis module for querying DB & API
βββ tests/ # Unit tests and PRD verification suite