Skip to content

Latest commit

 

History

History
50 lines (29 loc) · 2.95 KB

README.md

File metadata and controls

50 lines (29 loc) · 2.95 KB

ai-chess-bot

Overview

Project to apply a deep neural network to learn a chess position evaluation function from labeled lichess.com position examples and use the result to play live chess.

Only the evaluation function learning component is currently implemented in this repository. Move generation and move selection, possibly including minimax, alpha beta pruning, etc. would be necessary to complete a playable bot for live chess.

Getting Started

Prerequisites

Install Python3

Install PyTorch Lightning (conda recommended)

Modify layer_count, batch_size, learning_rate, max_epochs etc. in config.py

Train the model: $ python3 train.py

You may be prompted to enter account information related to Weights and Biases model training analytics. Sign up for a free account or skip this step, as it's not required for model training or inference.

Training Method

The network is trained on a Lichess Standard Chess open database files which represent games in Portable Game Notion and some proportion of them include the traditional Stockfish chess engine's evaluation, showing white or black's advantage in centipawns for the given position.

These PGNs are converted into bitboard representation for each piece type, along with some other relevant information, and the ([bitboards], eval()) tuples are used as labeled inputs for the neural network, which is implemented in PyTorch Lighting.

Model Architecture

The model structure includes an 808 element input layer, which receives the concatenated piecewise bitboard representations of the position under consideration along with some other board/game state information.

There are a configurable number (tested from 4-8) of hidden layers with ReLU activation enabled.

The output layer consists of a single floating point output element which represents the model's estimated evaluation for the given input position.

Model

Training Results

An initial hyperparameter sweep was used to determine optimal hyperparameters. Batch size was was initially determined to have little effect on the rate of improvement, so it was fixed at 512. The sweep was then conducted to find optimal values for network layer count and learning rate. The sweep results were visualized using TensorBoard.

Training Loss for Hyperparameter Sweep

HyperparameterSweep

Multi Epoch Training Run

With a batch size of 512, a layer count of 4, and a learning rate of 0.001, a 725k step run resulted in an end of run loss value of 1.3405.

Multi Epoch Training Run

Project derived from the Towards Data Science blog post Train Your Own Chess AI.