CoolFace
Modelpublic

felixmanojh/Qwen3-4B-Lichess-Chess-Puzzle-Tutor

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes8downloads
Model Card

Qwen3-4B-Lichess-Chess-Puzzle-Tutor

LoRA adapter for chess puzzle explanations ๐Ÿ“š

A LoRA adapter fine-tuned on Qwen3-4B-Instruct to generate educational explanations for tactical chess puzzles from the Lichess database.

๐ŸŽฏ Model Overview

  • โ€”Base Model: Qwen/Qwen3-4B-Instruct-2507 (4-bit quantized)
  • โ€”Adapter Type: LoRA (Low-Rank Adaptation)
  • โ€”Training Data: 5,020 high-quality Lichess puzzles with Claude-generated explanations
  • โ€”Best Checkpoint: Iteration 3900 (validation loss: 0.596)
  • โ€”Framework: MLX (Apple Silicon optimized)

๐Ÿ“Š Training Configuration

  • โ€”LoRA Rank: 32
  • โ€”LoRA Alpha: 64
  • โ€”Training Iterations: 6,000 (best @ 3900)
  • โ€”Batch Size: 4
  • โ€”Learning Rate: 3e-5
  • โ€”Optimizer: AdamW with warmup
  • โ€”Validation Loss: 0.596 (best checkpoint)

๐Ÿš€ Quick Start

Installation

bash
pip install mlx mlx-lm transformers

Using with MLX

python
from mlx_lm import load, generate

# Load base model with adapter
model, tokenizer = load(
    "mlx-community/Qwen3-4B-Instruct-2507-4bit",
    adapter_path="felixmanojh/Qwen3-4B-Lichess-Chess-Puzzle-Tutor"
)

# Example puzzle
prompt = """Explain this chess puzzle:

Position (FEN): r1bqkb1r/pppp1ppp/2n2n2/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 4 4
Solution: Nxe5 Nxe5 d4
Themes: fork pin
Rating: 1500"""

# Generate explanation
messages = [{"role": "user", "content": prompt}]
formatted_prompt = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

response = generate(
    model,
    tokenizer,
    prompt=formatted_prompt,
    max_tokens=512,
    verbose=False
)

print(response)

Using with Transformers + PEFT

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-4B-Instruct-2507",
    torch_dtype=torch.float16,
    device_map="auto"
)

# Load adapter
model = PeftModel.from_pretrained(
    base_model,
    "felixmanojh/Qwen3-4B-Lichess-Chess-Puzzle-Tutor"
)

tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-4B-Instruct-2507")

# Generate as usual...

๐Ÿ’ก Why Use the Adapter?

โœ… Small size โ€” ~150MB vs 8GB for merged model โœ… Training flexibility โ€” Continue fine-tuning or merge with other adapters โœ… MLX optimized โ€” Fast training and inference on Apple Silicon โœ… Version control โ€” Easy to experiment with different checkpoints

๐Ÿ“š Training Data

Data Source

  • โ€”Puzzles: Lichess puzzle database (CC0 1.0 Universal)
  • โ€”Explanations: Generated using Claude API (Anthropic)
  • โ€”Size: 5,020 training + 502 validation puzzles

Data Quality

Puzzles filtered for:

  • โ€”Popularity โ‰ฅ 90th percentile
  • โ€”Rating deviation โ‰ค 80 (consistent difficulty)
  • โ€”Minimum plays โ‰ฅ 500
  • โ€”Balanced across tactical themes (fork, pin, skewer, discovered attack, mate patterns, sacrifice, deflection, etc.)

Explanations generated using Claude API with consistent prompting for educational quality, focusing on:

  • โ€”Clear explanation of the tactical pattern
  • โ€”Step-by-step move analysis
  • โ€”Why alternatives don't work
  • โ€”Key learning points

Coverage

  • โ€”Rating Range: 1000-2500
  • โ€”Themes: 20+ tactical patterns
  • โ€”Format: FEN position + UCI solution + themes + rating โ†’ educational explanation

๐Ÿ“ˆ Performance Metrics

  • โ€”Best Validation Loss: 0.596 (iteration 3900)
  • โ€”Average Explanation Length: 659 characters (107 words)
  • โ€”Completeness: 96% (48/50 test puzzles)
  • โ€”Zero truncations or hallucinations

๐ŸŽ“ Intended Use

โœ… Recommended

  • โ€”Educational chess puzzle explanations
  • โ€”Learning tactical patterns
  • โ€”Automated puzzle commentary
  • โ€”Chess training applications
  • โ€”Interactive chess tutoring systems
  • โ€”Fine-tuning base for further specialization

โŒ Not Recommended

  • โ€”Full game analysis (puzzle-focused only)
  • โ€”Opening theory (not in training data)
  • โ€”Endgame tablebase analysis
  • โ€”Chess engine evaluation (explanation model, not engine)

๐Ÿ”„ Model Variants

ModelFormatSizeUse Case
This modelLoRA adapter~150MBTraining, fine-tuning, MLX
Qwen3-4B-Lichess-Chess-Puzzle-Tutor-MergedHuggingFace merged~8GBDeployment, Spaces, GPU
Qwen3-4B-Chess-Puzzle-Tutor-Fused-MLXMLX merged~4GBApple Silicon, local inference

๐Ÿ”ง GGUF Conversion

Step 1: Merge the LoRA Adapter

bash
pip install mlx mlx-lm

mlx_lm.fuse \
  --model mlx-community/Qwen3-4B-Instruct-2507-4bit \
  --adapter-path felixmanojh/Qwen3-4B-Lichess-Chess-Puzzle-Tutor \
  --save-path ./merged-chess-tutor \
  --dequantize

Step 2: Convert to GGUF

bash
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
pip install -r requirements.txt

python convert_hf_to_gguf.py ../merged-chess-tutor \
  --outtype f16 \
  --outfile chess-tutor-f16.gguf

# Optional: Quantize further
./llama-quantize chess-tutor-f16.gguf chess-tutor-q4_k_m.gguf Q4_K_M

๐ŸŒ Live Demo

Try it live: Chess Puzzle Tutor Space

๐Ÿ“ Citation

bibtex
@software{qwen3_chess_tutor_2025,
  author = {Felix Manojh},
  title = {Qwen3-4B-Lichess-Chess-Puzzle-Tutor},
  year = {2025},
  url = {https://huggingface.co/felixmanojh/Qwen3-4B-Lichess-Chess-Puzzle-Tutor},
  note = {LoRA adapter fine-tuned on Lichess puzzle database with Claude-generated explanations}
}

๐Ÿ“„ License

  • โ€”Model: Apache 2.0
  • โ€”Puzzle Data: Lichess puzzle database (CC0 1.0 Universal)
  • โ€”Explanations: Generated using Claude API for training purposes

๐Ÿ™ Acknowledgments

  • โ€”Lichess for the comprehensive puzzle database
  • โ€”Anthropic for Claude API used to generate training explanations
  • โ€”Qwen Team for the excellent Qwen3-4B base model
  • โ€”Apple MLX Team for the MLX framework

Built by Felix Manojh | Interactive Demo