ChessFormer is a chess transformer engine developed by @ncylich that leverages the power of transformer models trained on lichess datasets. Designed to simulate a player with an approximate Elo rating of ~1800, ChessFormer provides a sophisticated approach to chess move prediction and game analysis.
ChessFormer uses extensive datasets from lichess, a popular online chess platform, to train the transformer model. The project includes several scripts that handle different aspects of chess data processing and model interaction, providing a comprehensive toolkit for chess enthusiasts and researchers.
transformer.py
: Implements the chess transformer model.chess_loader.py
: Module for loading and processing chess game datasets.uci_to_pos.py
: Script for converting Universal Chess Interface (UCI) notation to board positions.inference.py
: Contains functions for model inference, including preprocessing and postprocessing.file_filter.cpp
: C++ script to filter chess games from PGN files based on Elo ratings.write_positions.py
: Python script to extract and record specific chess positions from games.models.zip
: The best model weights I could produce with my limited m1 pro setup.
Before running the scripts, ensure you have Python 3.x and a C++ compiler installed. Follow these steps:
-
Clone the ChessFormer repository:
git clone https://github.com/ncylich/chessformer cd chessformer
-
Install the required Python dependencies:
pip install -r requirements.txt
-
Compile the C++ script for filtering PGN files:
g++ -o file_filter file_filter.cpp
-
Chess Transformer Model: The
chessformer.py
script is the core of ChessFormer, encapsulating the transformer model for move prediction. -
Data Loading and Processing: Use
chess_loader.py
for loading and processing chess game data. -
Notation Conversion: Convert UCI notations to board positions using
chess_moves_to_input_data .py
. -
Running the Engine: Perform model inference with
inference_test.py
, which includes both preprocessing of chess positions and postprocessing of the model's output. -
Playing Against Engine: Run
play_against.py
. Must unzipmodels.zip
first though. -
Filtering PGN Files: Utilize the compiled
file_filter
program to filter games from PGN files based on specific Elo ratings.
Refer to each script's documentation for more detailed instructions.
Feel free to contribute to ChessFormer. You can contribute by:
- Forking the repository.
- Creating a new branch for your feature or bug fix.
- Committing your changes.
- Pushing your branch and submitting a pull request.
This project is licensed under the MIT License.