Why I started this
My journey in chess began in 2020, and since then I've become a 2500 rated player on lichess. Chess has become one of my biggest passions, and as an avid chess fan (and player!), I always wanted a tool that could tell the strength of my opponent at a glance. Being able to see the types of moves, or openings they liked to play, would not only help me understand my opponent, but also myself, as I would see similar mistakes that I often made.
How the project started
The project started as a small opening explorer (ChessOpeningAnalyzer): load a set of games, then walk through the moves played, position by position, with how often each was chosen and how those games turned out. It showed what a player had done, but not what they would do next, or why they lost.
Two things pushed it further. The first was Maia, a neural network trained to play like a human of a given rating rather than to find the best move. If a network can learn how people at a rating play, it should be able to learn how one person plays. The second was my interest in large language models. A move predictor works much like one: a language model learns from millions of sentences to predict the next word, and a move predictor learns from millions of positions to predict the next move. LLMs are also adapted the same way: pre-train a general model on lots of data, then fine-tune it on a little data of your own. That is how a general move predictor can become a model of one player.
So I rebuilt the explorer in phases, each measured before the next began. Where it ended up:
- A model that predicts one player's moves. A small neural network learns how people play from 12 million positions. It is then fine-tuned on one player's own games in about 20 seconds on a CPU. On held-out later games of 45 players, it names the move they actually played 64.6% of the time in the first 20 plies (half-moves). Counting which moves are popular gets 30.5%.
- Every gain is measured against a baseline, on data the model never saw. Each player's games are split by date, so nothing learns from the future. Each comparison gets a 95% range from resampling players.
- A product around it. A command-line report, an API that builds reports in the background, a web page to walk through them on a board, and a static demo.
- Reports that explain themselves. Stockfish evaluates each game's position after moves 12 and 30. So a report says not just that a player does badly in a line, but whether the opening leaves them worse off or they lose the points later. It also shows where in the game their points come from.
| Predictor, on 31,554 test moves of 45 players | Top-1 | Log loss |
| Uniform guess among the legal moves | 3.8% | 3.39 |
| Popularity: what everyone plays here | 30.5% | 2.54 |
| The player's own history, backed off to popularity | 45.7% | 2.05 |
| The player's history, backed off to the network | 59.7% | 1.36 |
| The player's history, backed off to the network fine-tuned on them | 64.6% | 1.18 |
Top-1 is how often the predictor's first choice was the move played. Log loss is the average of −ln(probability given to the move played). Lower is better, and it punishes being confidently wrong, which matters when the probabilities are shown to a reader.
The problem
Preparing for an opponent means reading their games, and there are far too many. Lichess makes every game public, but an active player has hundreds or thousands of them. Its explorer shows what someone has played. It doesn't say what they're likely to play next, especially in positions they've rarely reached, or where they lose points.
The obvious shortcuts mislead. A line can look weak only because it was played against stronger opponents. A few bad results can look like a pattern when they're luck. And a bad result says nothing about whether the opening went wrong or the game was lost thirty moves later.
So a scout has to answer two questions, and be honest about how sure it is:
- What will they play? That's a prediction problem: given a position and a player, a probability for each legal move.
- Where do they do badly, and why? That's a measurement problem: which lines score below what the ratings predicted, by more than luck explains, and whether the opening or the later game is the reason.
Keeping the evaluation honest
Most of the work that makes the numbers believable is here, so it comes first.
- Test players. 50 players were picked at random from one Lichess monthly dump, 10 from each of five rating bands, leaving out bots. Their 500 most recent games were downloaded and pinned by game id, so the results can be reproduced. 45 players remain after the date rule below.
- Split by date, not at random. Each player's earliest 70% of games are for learning, the next 15% for tuning, and the latest 15% for the final test. A random split would let a model learn from games played after the ones it is tested on.
- No data from the future anywhere. The population data (648,377 games from the morning of 1 September 2026) is older than every test game. Players whose validation games start before it ends are left out. The network is trained only on that sample.
- Tuned on validation, tested once. Every setting was chosen on the validation moves. The test moves were scored once per phase, at the end. Test figures came within about half a point of validation ones, so the tuning didn't overfit.
- Ranges from resampling players, not moves. One player's moves aren't independent of each other, so resampling moves would make the ranges look narrower than they are.
Baselines first
Before any neural network, I built the simplest predictors that could work, and scored them the same way.
- Popularity counts what everyone played in the same position. It knows the first few moves well, but by moves 6 to 10 most positions aren't in the sample at all. It had counts for only 31% of them.
- The player's own history counts what they played there before.
- Backing off blends the two. A narrow count is pulled towards a broader one, harder the fewer games it has: p(move) = (games here that played it + k × the broader probability) / (games here + k). Tuning k on validation showed players repeat themselves: one earlier game in a position counts for about twice the population's opinion.
Knowing the player added +15.2 points of top-1 over popularity (95% range +12.4 to +17.8). It reached 70% in the first five moves. But in moves 6 to 10 every baseline was stuck near 21%, because they can only use positions seen before. That gap set the goal for the next phase.
A small network that generalises
Rather than looking up the same position, a network can learn from similar ones. The design follows Maia, a network trained to play like humans, at a much smaller size:
- Input: the board as 18 planes of 8×8, seen from the side to move. That's one plane per piece type and colour, plus castling, en passant and the player's rating.
- Body: 4 residual blocks of 32 channels, 81,600 weights, small enough to train on a 2-core laptop CPU.
- Output: a score for each from-square × to-square, with a softmax over the legal moves only.
- Training: one pass over 12.1 million positions in about 2 hours. I compared two sizes on a 2-million-example subset first, and made training 1.65 times faster by storing the tensors "channels last".
Alone, the network beats popularity by +14.1 points. Behind the player's history, it beats history + popularity by +14.0 points (+13.2 to +14.9). It does so in every rating band. In moves 6 to 10, top-1 went from 20.9% to 46.4%.
Personalising from few games
The network knows how people play, but not how this player plays. Following McIlroy-Young et al., Learning Models of Individual Behavior in Chess (KDD 2022), I fine-tuned a copy of it on each player's own earlier moves: a few passes at a small learning rate, so it shifts towards their habits without forgetting the rest. Their work used Maia and players with thousands of games. This is a much smaller version, with about 350 games per player.
- The gain: +4.9 points of top-1 over the untuned network behind the same history (+3.7 to +6.3). Log loss fell by 0.18. It helps most where counting can't, in moves 6 to 10: 46.4% to 53.1%.
- The settings were chosen by a grid on validation. I tried learning rates 0.00003 to 0.001, 1 to 8 passes, and all the weights against the output layer only. Too high a learning rate visibly memorised: its log loss rose with more passes.
- A learning curve cut each player's history to 0, 10, 25, 50, 100 and 200 games. Fine-tuning helps from 10 games on. With 50 games it matches the untuned network with all of a player's games, about a seventh of the data. That matters for a scout, as the opponent you know least about is the one you most need to read.
- Calibration. A scout shows probabilities, so they have to mean what they say. Sorting predictions into bins, the first choice's stated probability is off from how often it was played by about 2 points on average. The combined predictor is slightly overconfident: it says 65% for moves played about 61% of the time.
From a model to a product
The report needs only the 350 KB network and the Lichess API, so it ships inside the package.
- The report. For each colour, it builds a tree of the player's likely moves and the replies they've faced, 10 plies deep. Each line's score is compared with the Elo expectation from both players' ratings, with a 95% range. A weak spot is a line whose whole range is below zero. The report checks dozens of lines, so about one in twenty such spots can be luck, and the page says so.
- Why a spot happens. Stockfish evaluates each game's position after move 12. Each evaluation becomes a win chance with the curve Lichess fits to its own games, and is averaged per line. A weak spot is then marked "the opening" if the position after move 12 was already clearly worse, and "later" if it was level or better. It's marked "unclear" otherwise.
- Where the points go. With the position after move 30 evaluated too, each colour's score splits into three parts that add up exactly to it: the opening, the middlegame and the rest. The report adds how they score from winning and losing positions, and how many games they lose on time. On the demo players, this shows, for example, two strong players who build their whole edge as White before move 30 and add almost nothing after it.
- The API. FastAPI, with one background worker. A report takes about a minute, so asking for one and fetching it are separate calls, with progress stages. Reports are kept for 6 hours, so two people scouting the same player share one build.
- The page. Plain HTML, CSS and JavaScript, with no framework or build step. The server sends each position and move's squares, so the page needs no rules of chess. It draws the board with arrows sized by probability. It works on a phone and in dark mode.
- Hosting. A Dockerfile and a Caddy setup for any Linux server, and a static demo on GitHub Pages with reports built ahead of time. The static demo was built when the free Oracle Cloud servers ran out of capacity.
A first report on 500 games takes about a minute on the development machine, plus about a minute of Stockfish. Rebuilding the demo reports on 1,000 games, with half of each player's games already downloaded and evaluated, took 25 to 44 s fine-tuning and about 2 minutes evaluating per player. Downloads and evaluations are cached, so a later report only fetches and evaluates new games.
Architecture
ChessScout is one Python package with clear internal layers, rather than separate services. Each layer may only use the ones below it. At the bottom is the domain: what a game, a result and a position are. Above it sit the parts that deal with the outside world: reading game files and the Lichess API, the moves table, the prediction models, and the chess engine. Above those, the services do what the app is for: the explorer, evaluation, training and the scouting report. At the top, the command line and the web API only parse input and format output. CI fails the build if an import breaks this.
There are two paths through it. The offline path turns Lichess's monthly database files into a moves table: one row per position in each game, with the move played from it, stored as Parquet files and queried with DuckDB. Millions of games can then be counted without loading them into memory, and filtering by player, rating or date is a query rather than a rebuild. Each position is identified by a hash of the board, so different move orders that reach the same position are counted together. The network's training examples are exported from this table. The online path starts from a username: download the player's new games (earlier ones are cached), fine-tune the saved network on them, evaluate their positions with Stockfish, and build the report.
Every predictor, from the popularity count to the fine-tuned network, implements one small interface: given a position and the player, return a probability for each legal move. So a single evaluation service scores them all in the same way, and the report can use any of them.
The web side is kept small on purpose. A report takes about a minute, so the API queues requests for a single background worker, which also keeps to Lichess's rule of one request at a time. The page is plain HTML, CSS and JavaScript: the server works out every position and move, so the page only draws them. The same page runs as the static demo, reading reports saved ahead of time instead of calling the API.
Engineering
- 558 tests, including checks against a brute-force recount of the moves table, a fake Lichess server, a fake chess engine, and doctests. Pyright type checking runs on every push, on Python 3.10 to 3.12.
- The data pipeline reads Lichess's monthly dumps into Parquet, queried with DuckDB. Every speed-up was measured before being kept, such as a position-hash cache (1.35 times faster) and sorted files (5 times faster lookups). So was one that didn't help: parallel workers on a memory-starved 2-core machine.
What's borrowed
- The idea of fine-tuning a move-prediction network per player comes from McIlroy-Young, Sen, Kleinberg and Anderson (KDD 2022). The network's design follows Maia's, at half its width (32 channels against 64) and two thirds of its depth (4 blocks against 6).
- The win-chance curve is Lichess's. Opening names come from lichess-org/chess-openings (CC0).
- python-chess handles the rules, PyTorch the training, and Stockfish the evaluations.
Limitations, and what I'd do next
- One morning of population data. The network learned from 8 hours of one day, which over-represents some time zones. More months of games would likely help: its gains hadn't levelled off.
- Small samples per line. With 500 games, most lines have too few games for a clear verdict. Doubling to 1,000 took the demo from 1 clear weak spot to 8 weak and 26 strong spots. 22 of those 34 now say why. The live server stays at 500 games to keep a first report near a minute.
- The opening only, for prediction. The network predicts the first 20 plies. The phase split looks at the whole game, but only at three points in it.
- Next steps: temperature scaling to fix the slight overconfidence; more population data; and a short written summary per player, generated from the report's numbers.