A language model trained from scratch on chess games to learn chess-specific patterns and strategies. This project uses the Nanotron framework to train a SmolLM3-based model on Lichess game data.
Try the model with huggingface:
Disclaimer: The documentation in this readme is LLM generated and may contain mistakes.
This project trains a transformer language model on chess games represented in UCI (Universal Chess Interface) notation. The model learns to predict chess moves given game context, including player Elo ratings and game outcomes.
/nanotron_train_configs/ directory<BOG> (beginning of game), <EOG> (end of game)<WHITE:1500>, <BLACK:2000>, etc. (0-3500 in 100-point increments)<WHITE_WIN>, <BLACK_WIN>, <DRAW>chess-bot-3000/
├── data/ # Data processing scripts
│ ├── download_lichess.py # Download games from Lichess database
│ ├── preprocess_lichess.py # Convert PGN to UCI format
│ └── preprocess_add_elo_and_result.py # Add Elo and result tokens
├── nanotron/ # Nanotron framework (submodule/fork)
├── nanotron_train_configs/ # Training configuration files
│ └── 100m_smollm3_chess_leonardo_jan24.yaml
├── slurm_scripts/ # HPC job submission scripts
│ └── leonardo.sh # SLURM script for Leonardo supercomputer
├── tokenizer/ # Custom tokenizer
│ ├── tokenizer_with_special_tokens.py
│ ├── uci_tokenizer_with_special_tokens/ # Tokenizer files
│ └── pgn_tokenizer_with_special_tokens/ # Alternative PGN tokenizer
└── nanotron_venv/ # Python virtual environment
git clone <repository-url>
cd chess-bot-3000
python -m venv nanotron_venv
source nanotron_venv/bin/activate
cd nanotron
pip install -e .
cd ..
pip install transformers datasets pandas
Download games from the Lichess database:
python data/download_lichess.py
Convert PGN format to UCI notation:
python data/preprocess_lichess.py
This converts games from Standard Algebraic Notation (SAN):
1. e4 e5 2. Nf3 Nc6 ...
To UCI format with special tokens:
<BOG> e2e4 e7e5 g1f3 b8c6 ... <EOG>
Augment the data with player ratings and game outcomes:
python data/preprocess_add_elo_and_result.py
Final format:
<BOG> <WHITE:1600> <BLACK:1550> <WHITE_WIN> e2e4 e7e5 g1f3 ... <EOG>
cd nanotron
torchrun --nproc_per_node=4 run_train.py \
--config-file ../nanotron_train_configs/100m_smollm3_chess_leonardo_jan24.yaml
Key hyperparameters (see nanotron_train_configs/100m_smollm3_chess_leonardo_jan24.yaml):
34 commits
Hacker News (1)
Python
97.2%
C++
1.4%
A language model trained from scratch on chess games to learn chess-specific patterns and strategies. This project uses the Nanotron framework to train a SmolLM3-based model on Lichess game data.
Try the model with huggingface:
Disclaimer: The documentation in this readme is LLM generated and may contain mistakes.
This project trains a transformer language model on chess games represented in UCI (Universal Chess Interface) notation. The model learns to predict chess moves given game context, including player Elo ratings and game outcomes.
/nanotron_train_configs/ directory<BOG> (beginning of game), <EOG> (end of game)<WHITE:1500>, <BLACK:2000>, etc. (0-3500 in 100-point increments)<WHITE_WIN>, <BLACK_WIN>, <DRAW>chess-bot-3000/
├── data/ # Data processing scripts
│ ├── download_lichess.py # Download games from Lichess database
│ ├── preprocess_lichess.py # Convert PGN to UCI format
│ └── preprocess_add_elo_and_result.py # Add Elo and result tokens
├── nanotron/ # Nanotron framework (submodule/fork)
├── nanotron_train_configs/ # Training configuration files
│ └── 100m_smollm3_chess_leonardo_jan24.yaml
├── slurm_scripts/ # HPC job submission scripts
│ └── leonardo.sh # SLURM script for Leonardo supercomputer
├── tokenizer/ # Custom tokenizer
│ ├── tokenizer_with_special_tokens.py
│ ├── uci_tokenizer_with_special_tokens/ # Tokenizer files
│ └── pgn_tokenizer_with_special_tokens/ # Alternative PGN tokenizer
└── nanotron_venv/ # Python virtual environment
git clone <repository-url>
cd chess-bot-3000
python -m venv nanotron_venv
source nanotron_venv/bin/activate
cd nanotron
pip install -e .
cd ..
pip install transformers datasets pandas
Download games from the Lichess database:
python data/download_lichess.py
Convert PGN format to UCI notation:
python data/preprocess_lichess.py
This converts games from Standard Algebraic Notation (SAN):
1. e4 e5 2. Nf3 Nc6 ...
To UCI format with special tokens:
<BOG> e2e4 e7e5 g1f3 b8c6 ... <EOG>
Augment the data with player ratings and game outcomes:
python data/preprocess_add_elo_and_result.py
Final format:
<BOG> <WHITE:1600> <BLACK:1550> <WHITE_WIN> e2e4 e7e5 g1f3 ... <EOG>
cd nanotron
torchrun --nproc_per_node=4 run_train.py \
--config-file ../nanotron_train_configs/100m_smollm3_chess_leonardo_jan24.yaml
Key hyperparameters (see nanotron_train_configs/100m_smollm3_chess_leonardo_jan24.yaml):
Hacker News (1)
34 commits
Python
97.2%
C++
1.4%