Atenrev / chessformers

This is a PyTorch implementation of a Transformer Decoder based model that plays chess.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chessformers

Description

This is a PyTorch implementation of a Transformer Decoder based model that plays chess.

Prerequisites

  • PyTorch
  • chess
  • Flask (Only for API service)

Installation

1. Clone the repo

git clone https://github.com/Atenrev/chessformers.git
cd chessformers

2. Data

  • Download the 3.5 Million Chess Games dataset. Put it in a "dataset" folder inside the root folder and rename the txt file to kaggle2.txt.
  • Run process_kaggle.py to pre-process the dataset.

You can also use your own dataset. In that case, you should adapt the dataset.py script accordingly.

3. Download the model

Here is an example of what the root should look like:

.
├── trainer.py
├── inference.py
├── web_server.py
├── process_kaggle.py
├── chessformers\
|   ├── dataset.py
|   ├── tokenizer.py
|   └── model.py
├── model\
|   └── chessformer_epoch_13.pth
└── dataset\
    ├── processed_kaggle2.txt
    └── kaggle2.txt

Train

Run trainer.py:

python trainer.py 

optional arguments:
  -h, --help                show this help message and exit
  --dataset DATASET         location of the dataset
  --vocab VOCAB             location of the vocabulary
  --batch_size BATCH_SIZE   training batch size
  --epochs EPOCHS           number of training epochs
  --lr LR                   learning rate
  --beta1 BETA1             adam beta
  --save_dir SAVE_DIR       save model directory
  --load_model LOAD_MODEL   model to load and resume training

Inference (play against the engine)

You can play against the engine through a web interface by running the web_server.py script.

Alternatively, you can play in the console using PGN notation by running inference.py:

python .\inference.py

optional arguments:
  -h, --help                show this help message and exit
  --load_model LOAD_MODEL   model to load and do inference

About

This is a PyTorch implementation of a Transformer Decoder based model that plays chess.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%