Downloads · 30 days
0
leoncynn/paper9-qkv-surgical-correction
paper9-qkv-surgical-correction is a machine learning model from leoncynn. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Artifacts for the paper by Yeonseong Cynn (River Lab, May 2026).
Downloads · 30 days
0
Access
Public
Updated May 7, 2026
Repo size
28.4 MB
Likes
0
Public
Click a slice to open those files.
.pt28.4 MB · 95%
From the Hugging Face model README
Artifacts for the paper by Yeonseong Cynn (River Lab, May 2026).
A method for diagnosing transformer prediction errors and surgically correcting them through Q/K/V weight analysis.
Key findings:
gpt2_L10_routing_ffn_only.pt — Surgically corrected L10 layer weights (FFN-only retraining). Standard GPT-2 layer format, loadable directly into transformer.h[9].results/gpt2_qkv_full.json — Full QKV decomposition analysis (all layers × all heads)results/gpt2_qkv_xai.json — QKV-based explainability resultsresults/gpt2_surgical_fix.json — Surgical correction evaluation (capitals, general, side effects)results/gpt2_routing_test.json — Knowledge routing pathway tests (Attention/FFN/V-only)results/gpt2_weight_diagnosis.json — Weight-based diagnosis without inputresults/gpt2_separability.json — Layer separability analysis for GPT-2results/qkv_dashboard_data.json — QKV dashboard visualization dataresults/xai_validate.json — XAI validation resultsqkv_dashboard.html — Interactive QKV analysis dashboard. Open in browser, loads results/qkv_dashboard_data.json automatically.figures/fig1_paris_trace.png — Knowledge path: "The capital of France is ___" (Paris vs "the" logit trace)figures/fig2_k_response.png — W_k response by token type (K-norm heatmap)figures/fig3_surgical.png — Before/after surgical editing (2/8 → 8/8)figures/fig4_routing.png — Knowledge routing: all pathways succeed (8/8)figures/fig5_qk_overlap.png — QK overlap analysis (W_q ∩ W_k top-100 dimensions)import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer
model = GPT2LMHeadModel.from_pretrained("gpt2")
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
# Replace L10 with corrected weights
corrected = torch.load("gpt2_L10_routing_ffn_only.pt", map_location="cpu")
model.transformer.h[9].load_state_dict(corrected)
model.eval()
# Test
prompt = "The capital of France is"
ids = tokenizer.encode(prompt, return_tensors="pt")
with torch.no_grad():
logits = model(ids).logits[0, -1, :]
print(tokenizer.decode(logits.argmax())) # Paris
Original GPT-2: 2/8 capitals correct (Italy, Spain only)
After L10 edit: 8/8 capitals correct
General ability: 15/15 unchanged
PPL: 42.7 → 42.6
gpt2 (124M parameters, pre-trained)
MIT