# Chess commentary encoder

> A 230M-parameter encoder that reads chess commentary, finds every move, square and claim, and checks each claim against the board. Runs in your browser.

A fine-tuned LFM2.5-Encoder-230M reads chess commentary and tags every move, piece, square and claim; chess.js then checks each claim against the board. I built it to reward true reasoning during RL ([the story](https://www.manoletre.com/chess.md), and [how it works](#how-it-works) below). It runs in your browser: the first load downloads the model (~145 MB) from [Hugging Face](https://huggingface.co/manoletre/chess-move-tagger). Code and data are on [GitHub](https://github.com/manoletre/chess-moves-from-text). Pick an example or write your own.

## how it works

When [fine-tuning LFM-2.5-1.2b to play chess](https://www.manoletre.com/chess.md) I needed a way to verify the correctness of the reflections it was generating, so that I can positively reward the “good” reflections. To do so I needed to parse chess data out of a text: which words are moves, which are pieces and squares, and which are claims like “gives check” or “wins the queen”. That's token classification, which a small encoder does well and fast.

LFM2.5-Encoder-230M turns every token into a vector of 1,024 numbers. On top of it I trained a single linear layer with 36 outputs, split into five heads. Each head is its own classifier over the same tokens with its own softmax and cross-entropy loss.

*Figure: An example of a forward pass and how tokens from a text are classified.*

'Rxh2+ is the obvious way, but the king just takes it with Kxh2. Rg1+ fails the same way to Kxg1. Rxg3+ is better:' mention: MOVE on Rxh2+, Kxh2, Rg1+, Kxg1 and Rxg3+, PIECE on 'king'. line: new on Rxh2+, Rg1+ and Rxg3+, next on Kxh2 and Kxg1 (the replies). stance: rejected on the first four moves, chosen on Rxg3+. frame: after on 'king', 'takes' and 'is'. claim: WINS on 'takes', EVAL on 'is'.

| head | labels | outputs |
| --- | --- | --- |
| mention | move, piece, square, file, rank, diagonal, region | 15 |
| line | new, next, alternative | 3 |
| stance | chosen, rejected, considered | 3 |
| frame | now, after | 2 |
| claim | check, mate, wins, attacks, flight, eval | 13 |

With these classifications, we can turn the labels into questions that are programmatically verifiable using python-chess or chess.js. For example “rook can swing to g8” becomes verifiable. If the rook is in a position where it can't move to g8 we can't do that.

The encoder doesn't say which rook. It only marks “rook can swing to g8” as a move, and the checker keeps the legal moves that fit what the text says: a rook, landing on g8. If exactly one move fits, that's the move (here the rook on g2 going to g8); if none fits, it's false; if several fit, it can't tell and leaves it unverifiable. A piece with a square (“the rook on g2”) is looked up on that square, and one without is found only if it's the only piece of its kind on the board.

Then rules turn tags into facts. Each claim is linked to the nearest move or piece before it in its clause, and checked on the board as it is now or after that move, depending on its frame: python-chess during training, a chess.js port of the same rules here in the browser (both give the same verdict on all 34,621 facts I compared). A fact is true, false or unverifiable. Evaluations like “the attack fizzles” can only be checked when the solution is known. The checker also reports the chosen move, moves the text rejected and then played, and false refutations: reasons against a move that aren't true.

*Figure: Another reflection: its spans become three facts on the board. The text rejected Rg8 because the king would step away, but after Rg8 it can't: a false refutation.*

'rook can swing to g8' resolves to Rg8 (true). 'deliver check' after Rg8: true. 'simply steps away' after Rg8: false, the king has no legal move. So the text rejected the solution, Rg8#, for a false reason.

Here is the whole reflection that sentence comes from, one head at a time.

*Figure: The whole reflection through each head, then the checks. Click a head to see its labels. One verdict is the checker's mistake: it linked “aimed at” to f1 as well as g8.*

A real reflection: 'White's rook on g2 is aimed at the g8 square ... So the move is Rg8#.' mention: pieces, squares and 3 moves. line: all 3 moves NEW. stance: the first move REJECTED, the other two CHOSEN. frame: claims about now or after the move. claim: ATTACKS, CHECK, FLIGHT, EVAL, ATTACKS, MATE. verify: 'simply steps away' and 'the attack fizzles' are false reasons against Rg8, the move it then plays.

## data

704 training texts are real reflections from the LLMs I trained to play chess, from different points of RL, so the encoder sees how their wording drifted. Claude Opus 5.5 (through my Claude Code subscription) labelled them, and they are split by puzzle so no test puzzle shows up in training. The rest are synthetic chess-related text that is LLM-written.

*Figure: The training set. Validation has 137 texts and test 641, both with real reflections and commentary.*

Train: 3,701 texts: 704 real reflections, 1,497 synthetic reflections, 1,500 chess commentary. Val 137, test 641.

The model is on [Hugging Face](https://huggingface.co/manoletre/chess-move-tagger), and the code, the labelling guide and the data are on [GitHub](https://github.com/manoletre/chess-moves-from-text).
