Mission: To explain go ai neural networks for people to learn better from them.
Tighly integrated with https://github.com/lightvector/KataGo
Currently using SAE Approach: https://web.stanford.edu/class/cs294a/sparseAutoencoder.pdf open to best approach since this project is quite early.
Minimal Steps (n00b version)
- Collect positions: (see 1_collect_positions/) Grab a few thousand varied 7×7 board snapshots (early, fights, endgame) using any standard KataGo network.
- Pick one layer: (see 2_pick_layer/) Choose an intermediate layer of the general KataGo network (e.g. middle trunk block).
- Extract activations: (see 3_extract_activations/) For each 7×7 position, record that layer's output and average it down to one number list (channel-average).
- Run simple parts finder (NMF): (see 4_nmf_parts/) Factor those lists into ~50–70 "parts" using Non-negative Matrix Factorization. This creates interpretable parts that represent recurring patterns in the neural activations.
- Inspect parts: (see 5_inspect_parts/) For each part, look at the boards where it's strongest; note any clear pattern (e.g. ladders, atari, eyes). Generate HTML reports to visualize the top positions for each part and identify meaningful go concepts.
- Convert SGF to NPZ: (see 1_collect_positions/convert_human_games.py) Transform human SGF games into the format expected by the activation extraction pipeline.
- Pick one layer: Same as self-play pipeline.
- Extract activations: Same as self-play pipeline.
- Run NMF analysis: Same as self-play pipeline.
- Inspect parts: Same as self-play pipeline.
Quick Start for Human Games:
python human_games_docs/run_human_games_pipeline.py \
--input-dir games/go13 \
--output-dir human_games_analysis \
--model-path models/kata1-b28c512nbt-s9584861952-d4960414494/model.ckptQuick Start for Self-Play:
# Generate positions
katago selfplay -config selfplay.cfg -models-dir models/ -output-dir selfplay_out/
# Extract activations
python 3_extract_activations/extract_pooled_activations.py \
--positions-dir selfplay_out/ \
--ckpt-path models/your-model.ckpt \
--output-dir activations/
# Run NMF
python 4_nmf_parts/run_nmf.py \
--activations-file activations/pooled_rconv14.out.npy \
--output-dir nmf_parts/
# Inspect parts
python 5_inspect_parts/inspect_parts.py \
--activations-file activations/pooled_rconv14.out.npy \
--nmf-components nmf_parts/nmf_components.npy \
--nmf-activations nmf_parts/nmf_activations.npy \
--output-dir inspect_parts/# Test human games conversion
python human_games_docs/test_human_games_conversion.py
# Test device
python 3_extract_activations/verify_pytorch_device.py
# Test imports
python -c "import katago, torch; print('Setup OK')"Import Errors:
# KataGo not found
git clone https://github.com/lightvector/KataGo.git
export PYTHONPATH="${PYTHONPATH}:$(pwd)/KataGo/python"
# PyTorch not found
pip install torch torchvision torchaudioMemory Issues:
# Reduce batch size
--batch-size 32
# Use CPU
--device cpu
# Fewer NMF components
--num-components 25File Not Found:
# Create directories
mkdir -p games/go13 models/
# Download model
# Get the latest model from: https://katagotraining.org/networks/
# For this pipeline, we use: kata1-b28c512nbt-s9584861952-d4960414494
# Download the full checkpoint (includes model + training state):
wget https://media.katagotraining.org/uploaded/networks/zips/kata1/kata1-b28c512nbt-s9584861952-d4960414494.zip
# Extract and setup:
unzip kata1-b28c512nbt-s9584861952-d4960414494.zip
mkdir -p models/kata1-b28c512nbt-s9584861952-d4960414494
mv kata1-b28c512nbt-s9584861952-d4960414494/model.ckpt models/kata1-b28c512nbt-s9584861952-d4960414494/model.ckpt- Board Size:
--board-size 7(default),--board-size 19(for 19x19) - Batch Size:
--batch-size 256(default),--batch-size 64(if out of memory) - Device:
--device cuda(GPU, default),--device cpu(CPU, if no GPU) - NMF Components:
--num-components 50(default),--num-components 25(if memory issues)
- human_games_docs/HUMAN_GAMES_PIPELINE.md - Complete human games guide
- human_games_docs/TROUBLESHOOTING.md - Detailed troubleshooting
- human_games_docs/DOCUMENTATION.md - Complete documentation index
- Add tiny heuristics: Auto‑flag basics (atari present, ladder path, ko, eye forming) to see which parts match which flags.
- (If parts look real) Train sparse autoencoder: Replace NMF with a small sparse model on the same pooled data to get cleaner, fewer‑on features.
- Name good features: Only name those with a clear, repeatable pattern; leave the messy ones unnamed.
- Optional sanity check: For a named feature, see if positions "feel different" when you imagine that feature absent (qualitative is fine).
- Stop and use: Start using the named features to explain moves; only add complexity (spatial detail, more layers) if you later need finer distinctions.
KataGo's inputs include more than the current board arrangement—move history, komi, rules, ko state, and estimated score are all encoded. Therefore some internal channels capture contextual information rather than spatial shape. Typical triggers include:
- Move number / player to play
- Komi or handicap stones
- Ko threats or super-ko repetition state
- Current score lead / win-probability trend
- Recent tactical sequences (history-dependent)
- Board-holdout tests – Feed the same board position while varying one global input (e.g. komi) and record which channels change.
- History shuffling – Randomize move history that leads to identical final board states.
- Komi sweep – Vary komi ±N points while keeping board identical.
- Score perturbation – Modify estimated score/win-probability inputs.
- Ko toggles – Flip individual ko capture states.
✅ Variant Generation: 1_collect_positions/generate_variants.py supports zero_global mode
✅ Multi-Variant Extraction: 3_extract_activations/extract_pooled_activations.py processes multiple datasets
✅ Contextual Detection: 3_extract_activations/contextual_channel_detector.py analyzes variance
✅ Layer Analysis: Tested rconv14.out layer - found purely spatial (0 contextual channels)
Layer rconv14.out Analysis:
- Tested: Zeroing globalInputNC vs baseline
- Result: Identical activations (0 contextual channels)
- Conclusion: Layer is purely spatial - no global context sensitivity
- Action: Proceed with NMF using all 4608 channels
- Test earlier layers: Investigate layers closer to input for global sensitivity
- Additional variants: Implement
komi_sweep,history_shufflemodes - Multi-layer analysis: Systematic testing across network depth
- Direct correlation: Analyze correlation between globalInputNC values and activations
The contextual channel detection infrastructure is now ready and can be applied to any layer in the network.