Chess AI (ResNet Policy & Value Network)

A neural network chess engine trained on master-level chess games from Lichess using supervised learning.

Architecture

  • Neural Network: Deep Residual Network (ResNet)
  • Input Representation: 8×8×18 tensor board state encoding
    • 12 piece planes (6 piece types × 2 player colors)
    • 6 game state planes (castling rights, en passant availability, active turn)
  • Residual Blocks: 3 residual blocks with 128 convolutional filters
  • Dual Output Heads:
    • Policy Head: Outputs move probabilities across 4,352 possible legal move representations
    • Value Head: Outputs position evaluation score between -1 (Black winning) and +1 (White winning)

Files in this Repository

  • best_model.pth (119 MB): The best-performing checkpoint evaluated on held-out validation games
  • checkpoint_epoch_1.pth through checkpoint_epoch_10.pth: Training progression checkpoints across 10 epochs
  • model.py: PyTorch neural network definition (ChessNet)
  • board_encoder.py: Fast board state to tensor conversion
  • play_engine.py: Engine move picker and evaluation logic

Quick Usage with PyTorch

import torch
from model import ChessNet
import chess

# Initialize model
model = ChessNet(num_res_blocks=3, num_channels=128)
checkpoint = torch.load("best_model.pth", map_location="cpu")
model.load_state_dict(checkpoint)
model.eval()

print("Chess AI model loaded successfully!")

Training Details

  • Dataset: ~100K-200K positions extracted from strong human games on Lichess
  • Loss: Cross-Entropy (policy) + Mean Squared Error (value)
  • Optimizer: Adam with learning rate scheduling
  • Framework: PyTorch with MPS (Apple Silicon) & CUDA support

Author

Created by Ahmet Dedeler. Full repository available on GitHub.

Downloads last month

-

Downloads are not tracked for this model. How to track
Video Preview
loading