Edouard Silvestre
Back to projects

Epitech · 3rd year · Solo

my_torch

A neural network written from scratch in NumPy that reads a chess position and tells check from checkmate.

  • Python
  • NumPy
  • Deep learning
Try it
Period
Oct – Nov 2026
Team
Solo project
Code
View the code
FEN · 769256256645 classesNothingCheck WhiteCheck BlackCheckmate WhiteCheckmate Blackfig. 01 — my_torch · a network written by hand

The project

my_torch is a neural network module I wrote in Python with NumPy, without any deep learning library. Dense layers, activations, initialisers, losses, optimisers, mini-batches, L2 regularisation, early stopping, dropout and MC dropout, learning rate scheduling: everything is written by hand, backpropagation included.

I applied it to chess. From a position in FEN notation, encoded as 769 inputs, the network predicts Nothing, Check or Checkmate, and for which colour.

I play chess (1,400 Elo). Teaching a network what I see on the board, with no framework hiding the maths, was the best way to understand what really happens during training.

In numbers

Check / Nothing, on the test split
95.7%
Checkmate / Check / Nothing with colours, on the test split
90.0%
positions from real games in the dataset
723,019
tests passed on the grader
10 / 10

What was hard

  • My first version, trained on 80,000 positions from random games, passed only 2 tests out of 10 on the grader. On real games it dropped to 53.6%: it saw checks everywhere.
  • Writing backpropagation by hand, for six activations, with no framework to flag a mistake. Some errors stay invisible as long as you only use ReLU.
  • Overfitting: without regularisation, 95.8% on training against 85.3% on validation.

What I learned

  • Data matters more than architecture: switching to positions from real games gained more than 30 points, while the compared architectures differed by one point.
  • Checking gradients with finite differences, on networks varied enough to expose the errors.
  • Choosing on validation, measuring once on the test set, and fixing every seed so that each result can be reproduced exactly.

Try it.

The network, live

Place the pieces, or load a position. The real trained network runs in your browser with the Python code of the repository, and its answer is compared with the rules of chess.

The benchmarks

Every choice behind the final network was compared with its alternatives, on the same data.

  • Signal variance through 10 ReLU layers, by initialiser
    Signal stability by initialiser
  • Architectures: compared learning curves
    Architectures · learning curves
  • Architectures: summary of the results
    Architectures · summary
  • Activations: compared learning curves
    Activations · learning curves
  • Activations: summary of the results
    Activations · summary
  • Initialisers: compared learning curves
    Initialisers · learning curves
  • Initialisers: summary of the results
    Initialisers · summary
  • Optimisers: compared learning curves
    Optimisers · learning curves
  • Optimisers: summary of the results
    Optimisers · summary
  • Batch sizes: compared learning curves
    Batch sizes · learning curves
  • Batch sizes: summary of the results
    Batch sizes · summary
  • Confusion matrix of the network over the five classes
    Confusion matrix

Credits

  • Chess pieces: Colin M.L. Burnett (BSD licence).
  • Python in the browser: Pyodide (MPL 2.0). Rules of chess: chess.js (BSD).