KEditVis: Interactive Visual Analytics for Human-in-the-Loop Knowledge Editing in Large Language Models
Grounded in human-in-the-loop visual analytics for autoregressive Transformer editing.
- Overview
- System Architecture
- Key Empirical Findings
- Core Differences: 2603.29689v1.pdf vs. Our Implementation
- Repository Structure
- Quickstart & Installation
- Running the Test Suites
- Cloud GPU Backend Deployment
- Benchmarking & Reproduction
- Academic Reconciliation
- References
Large Language Models (LLMs) store vast amounts of factual knowledge within their feedforward weight matrices (W_out). When facts become outdated or require correction, retraining the entire network is computationally prohibitive. Locate-then-edit techniques—principally ROME (Rank-One Model Editing) and MEMIT (Mass-Editing Memory in a Transformer)—treat feedforward layers as linear associative memories, modifying weights to store new associations:
Production editing pipelines typically rely on rigid, model-wide layer presets (e.g., layers [13..17] for GPT-2-XL, layers [3..7] for GPT-J-6B). However, factual representations do not localize identically across different entities and semantic categories:
- Mislocated Edits: Editing outside the factual storage locus fails to generalize or destroys model coherence.
- Parameter Explosion: Unconstrained random layer selection induces up to 11.3x higher relative Frobenius parameter drift (
||ΔW||_F / ||W_0||_F), destabilizing nearby knowledge. - Paraphrase Fragility: Standard single-context MEMIT often succeeds on the literal target prompt but fails under varied phrasing.
KEditVis is an end-to-end interactive visual analytics system that integrates human domain judgment directly into the editing loop. By extracting layer-wise residual variance Var_dim(h_l[t]), directional cosine similarity dips, and logit-lens vocabulary projections in real time, KEditVis guides practitioners to stable layer bands, monitors parameter drift, and provides instantaneous, zero-drift transactional rollback.
+------------------------------------------+
| KEditVis React Dashboard |
| (Vite + TailwindCSS + D3.js Visuals) |
+---------------------+--------------------+
|
| REST API (HTTP / JSON)
v
+---------------------------------------------------------------------------------------+
| FastAPI Backend (Modal A100) |
| |
| +------------------------+ +------------------------+ +-----------------------+ |
| | Telemetry Extraction | | Editing Engine | | Transactional State | |
| | - Residual Variance | | - ROME | | - Weight Snapshots | |
| | - Cosine Similarity | | - Standard MEMIT | | - Zero-Drift Rollback | |
| | - Logit-Lens Projection| | - Context-Robust MEMIT | | - Frobenius Tracking | |
| +------------------------+ +------------------------+ +-----------------------+ |
| | |
| v |
| HuggingFace Transformer Architecture |
| - GPT-2-XL (1.5B, 48 Transformer Layers) |
| - GPT-J-6B (6.0B, 28 Transformer Layers) |
+---------------------------------------------------------------------------------------+
- Layer Telemetry Strip: Displays layer-by-layer residual variance and cosine similarity dips across subject tokens, pinpointing the critical information-processing layers.
- Multi-Context Vocabulary Projections: Traces top-1 greedy token predictions across all layers via unembedding matrix projection (
h_l · W_U). - Multi-Metric Comparative Workspace: Evaluates candidate layer selections and optimization profiles side-by-side across:
- Efficacy Score (ES): Preference probability
P(target) > P(original). - Paraphrase Score (PS): Generalization across unseen rephrasings.
- Neighborhood Score (NS): Locality preservation on unedited sibling subjects.
- Efficacy Score (ES): Preference probability
- Frobenius Parameter Drift & KL Scatter: Plots tensor weight deviation (
||ΔW||_F) against hidden state representation divergence (D_KL), detecting localized over-fitting before committing changes.
Controlled paired evaluations across the first 10 facts of the CounterFact manifest (prototype/data/benchmark_manifest.json, which holds 25 evaluation facts plus 1 development fact) on NVIDIA A100-SXM4-40GB hardware yielded concrete insights. Values are means over those 10 evaluation facts; bootstrap 95% CIs and per-fact records are in EVALUATION.md and prototype/audit/evaluation/summary.json.
| Configuration | Layer Range | Efficacy (ES) | Paraphrase (PS) | Locality (NS) | Mean Score (S) | Relative Drift (‖ΔW‖_F / ‖W_0‖_F) |
|---|---|---|---|---|---|---|
| Static Preset (MEMIT) | [13..17] |
0.800 | 0.850 | 0.733 | 0.631 | 0.0095 |
| Telemetry-Guided | per-fact window | 0.800 | 0.800 | 0.733 | 0.621 | 0.0097 |
| Seeded Random | per-fact window | 1.000 | 0.600 | 0.733 | 0.544 | 0.1071 (11.3x explosion) |
| Context-Robust MEMIT | [13..17] |
1.000 | 0.900 | 0.700 | 0.756 | 0.0169 (+77.9% budget) |
- Telemetry Layer Selection Acts as a Critical Safety Filter: While heuristic telemetry selection achieves parity with the static preset (S = 0.621 vs 0.631, p = 0.343), its primary function is preventing catastrophic failure bands. Seeded-random layer selection causes an 11.3x explosion in mean parameter drift (Rel-Frob = 0.1071) and cuts paraphrase generalization to PS = 0.600. Note the random arm also scores the highest raw efficacy (ES = 1.000), so drift and generalization—not efficacy alone—are what separate the policies.
- Context-Robust MEMIT Rescues Fragile Edits: Expanding the latent update budget (40 steps, clamp 1.5) and applying multi-context fitting raises efficacy from 0.800 to 1.000, paraphrase generalization from 0.850 to 0.900, and the composite score from 0.631 to 0.756, successfully resolving previously impossible hard edits (e.g., Wellington → Sheffield, PS 0.0 → 0.5). It costs +77.9% relative parameter drift (0.0169 vs 0.0095).
- Transactional Rollback Guarantees Safe Exploration: In-memory transactional weight snapshots guarantee 0.000 residual weight drift upon rollback, verified across all tests and live runs.
The theoretical foundation of this project originates from the base paper:
Z. Chen et al., "KEditVis: A Visual Analytics System for Knowledge Editing of Large Language Models," IEEE Transactions on Visualization and Computer Graphics (TVCG), vol. 32, no. 6, pp. 4818–4828, June 2026 (arXiv:2603.29689v1).
While Chen et al. introduced the visual analytics workflow, our capstone project extends their theoretical design into an operational, mathematically validated, and open-source full-stack platform. Below are the core technical, algorithmic, and empirical differences:
| Dimension | Base Paper (2603.29689v1.pdf) |
Our Implemented System (KEditVis) |
|---|---|---|
| Code Availability & Reproduction | Theoretical academic publication. Full interactive dashboard and backend were unreleased / proprietary. | Complete production open-source system: React 18 + Vite frontend, FastAPI backend on NVIDIA A100 GPU, automated test suites, and standalone CLI probe. |
| Telemetry Signals | Cosine similarity only (cos(x_in, x_out)) and logit-lens token ranks. |
Cosine similarity + Layer-wise Residual Variance (Var_dim(h_l[t]) and delta variance Var_dim(h_l - h_{l-1})) with interactive signal switching. |
| Editing Algorithms | Standard ROME and standard MEMIT only. | Standard ROME, standard MEMIT, and Context-Robust MEMIT (multi-context fitting, consistency loss, expanded update budget). |
| Paraphrase Generalization | Fragile under standard MEMIT. If an edit fails generalization, user must hunt for different layers. | Context MEMIT rescues fragile edits: mean paraphrase generalization rises from 0.850 to 0.900 across the 10-fact evaluation run, and from 1/5 to 4/5 on the reported Eiffel Tower phrasing set (including hard facts like Wellington → Sheffield, PS 0.0 → 0.5). |
| Drift & Safety Measurement | Relied purely on stochastic 2D t-SNE plots for "global impact" (qualitative, visual only). | Exact Frobenius norm parameter drift (‖ΔW‖_F, relative drift) + hidden-state L2 distance and KL divergence on a quantitative scatter plot. |
| Transactional Rollback | Conceptual concept; no concrete state-management or memory guarantees specified. | Bit-exact in-memory weight snapshots guaranteeing verified 0.000 residual parameter drift upon rollback. |
| Empirical Discovery | Implied that dynamic/human layer selection consistently beats fixed presets. | Scientific Reality Reconciled: Telemetry acts as a safety filter preventing catastrophic failure (11.3x parameter explosion on random layers), achieving parity with static presets (S = 0.621 vs 0.631). |
| Diagnostic Diagnostics | No root-cause analysis for facts that fail under every layer scheme. | Implemented prototype/error_analysis.py proving Windows → Apple fails due to flat subject representations (mean abs(cos) = 0.762). |
- Residual Variance Operationalization: The base paper measured layer activity exclusively through cosine similarity between MLP inputs and outputs. Our implementation operationalized feature-wise hidden channel variance
Var_dim(h_l[t])and delta varianceVar_dim(h_l - h_{l-1}), providing mathematically sound, scale/shift-invariant signals with interactive toggle controls in the UI. - Context-Robust Optimization: To address single-context MEMIT brittleness, we engineered a local CORE-inspired multi-context optimization engine in
editing_optimizations.pythat fits across multiple diverse prefixes and applies consistency regularization. - Rigorous Parameter Drift Quantification: While the paper relied on stochastic t-SNE projections that mask weight matrix destruction, our system computes exact tensor Frobenius norms (
||ΔW||_F), proving that unconstrained layer selection causes an 11.3x explosion in parameter corruption. - Empirical Grounding: Rather than claiming speculative superiority, our controlled 10-fact CounterFact evaluation run scientifically demonstrates that telemetry layer selection functions primarily as an essential guardrail against destructive out-of-band layers.
.
├── 2603.29689v1.pdf # Base paper (Chen et al., KEditVis, TVCG 2026)
├── EVALUATION.md # Comprehensive empirical evaluation & claim reconciliation
├── LICENSE # MIT
├── README.md # Repository documentation (this file)
└── prototype/
├── modal_app.py # FastAPI backend on Modal A100 (telemetry, editing, rollback)
├── editing_optimizations.py # Context-robust MEMIT objective & covariance solve
├── layer_selection.py # Static / telemetry / seeded-random layer policies
├── local_probe.py # Standalone CLI probe for local GPU/CPU inspection
├── prepare_benchmark.py # Builds the pinned CounterFact manifest
├── run_experiments.py # CounterFact benchmark pipeline + paired statistics
├── analyze_schemes.py # Signal-vs-success correlation analysis (single fact)
├── analyze_batch.py # Pooled multi-fact correlation analysis
├── error_analysis.py # Diagnostic for facts that fail under every scheme
├── verify_manifest.py # Verifies / regenerates the SHA-256 artifact manifest
├── export_doc.py # Rewrites the abstract paragraph of a source .docx
├── requirements.txt # Local probe, test-suite and benchmark dependencies
├── data/
│ ├── benchmark_manifest.json # CounterFact manifest: 25 eval facts + 1 dev fact
│ └── facts.json # Demo facts for the batch sweep
├── test_backend.py # Core backend unittests (FastAPI routes, rollback, invariance)
├── test_optimizations.py # Optimization unittests (multi-context fitting, projections)
├── test_live.py # Live GPU A/B evaluation against the deployed backend
├── test_live_backend.py # Live GPU integration verification (ROME + MEMIT)
├── OPTIMIZATION_NOTES.md # Context-v3 design notes and measured limits
├── THIRD_PARTY_NOTICES.md # EasyEdit / MEMIT attribution
├── audit/ # Evidence trail (index: audit/README.md)
│ ├── README.md # Evidence index + frozen-build caveat
│ ├── evaluation/ # verification.json, summary.json, raw_results.json
│ ├── development/ # CLI-run outputs behind the published correlations
│ ├── live/ # Per-model live GPU request/response records
│ ├── optimization/ # Context-v3 development trials and browser evidence
│ ├── before/ # Pre-audit source snapshot for the first-pass findings
│ └── references/ # Pinned EasyEdit / AlphaEdit / AnyEdit clones (gitignored)
└── frontend/ # Interactive React 18 visual analytics dashboard
├── src/ # TypeScript dashboard components (D3 charts, controls)
├── package.json # Frontend dependencies
└── tests/ # Automated browser regression suites (Puppeteer)
Clone the repository and prepare a Python virtual environment:
git clone https://github.com/umran666/KEditVis-LLM-Editing.git
cd KEditVis-LLM-Editing/prototype
python -m venv .venv
# On Windows:
.\.venv\Scripts\activate
# On Linux/macOS:
source .venv/bin/activate
# torch must come from PyTorch's own wheel index, not plain PyPI
# (CUDA 12.4 shown; substitute the CPU index if you have no NVIDIA GPU)
pip install --index-url https://download.pytorch.org/whl/cu124 torch==2.6.0
# Everything else: the local probe, the CPU test suite and the benchmark runner
pip install -r requirements.txtrequirements.txt deliberately omits modal and the pinned upstream memit/rome packages: those are only needed to deploy or run against the Modal GPU backend, and the CPU test suite does not import them.
You can run the layer-inspection probe locally on CPU or any consumer GPU (e.g., RTX 3050):
python local_probe.py --model gpt2-medium --prompt "{} is located in the city of" --subject "Eiffel Tower"This will output an ASCII chart of layer-by-layer cosine similarities and logit-lens top token predictions.
Navigate to the frontend directory, install packages, and launch the development server:
cd prototype/frontend
npm ci
npm run dev -- --host 127.0.0.1 --port 5187Open http://127.0.0.1:5187 in your browser.
Run the complete regression suite covering route validation, transactional rollback, numerical invariance, and context optimizations:
cd prototype
python -m unittest test_backend.py test_optimizations.py -vExpected output: Ran 38 tests in ~5s ... OK
Run the full end-to-end browser regression suite:
cd prototype/frontend
node tests/audit.mjsExpected output: All 15 browser test groups passed with 0 errors.
The backend runs on Modal utilizing an NVIDIA A100-SXM4-40GB GPU instance.
# 1. Install modal and authenticate
pip install modal
modal setup
# 2. Deploy the FastAPI app to production
cd prototype
modal deploy modal_app.pyThe deployed endpoint will be output in the console and should be configured in prototype/frontend/.env.local:
VITE_API_URL=https://<your-username>--keditvis-memit-web-app.modal.runTo reproduce the committed evidence set -- the first 10 evaluation facts, across static, telemetry and seeded-random selection plus the four optimization profiles:
cd prototype
# --num-facts 10 reproduces the committed evidence exactly; omit it to sweep all 25
# --url defaults to the reference deployment; point it at your own Modal app
python run_experiments.py --mode full --num-facts 10 --url https://<your-username>--keditvis-memit-web-app.modal.run--mode accepts smoke, full, selection, optimization, or analyze-only (recompute statistics from an existing audit/evaluation/raw_results.json without any GPU calls). Live runs incur Modal GPU usage and resume from the checkpointed raw_results.json.
To verify the SHA-256 manifest of the tracked artifacts:
# Read-only check; exits non-zero if any tracked artifact hash is stale or missing
python verify_manifest.py
# Accept the current hashes and rewrite the manifest
python verify_manifest.py --updateThe initial project proposal set ambitious benchmarks for automated layer selection. Through rigorous empirical testing on real A100 hardware, our findings provide a more nuanced, scientifically honest contribution:
- Rather than outperforming optimized static baselines across every single metric, telemetry-guided selection operates as a robust guardrail, preventing the catastrophic drift and failure modes caused by arbitrary layer choice.
- For complete claim-by-claim analysis, bootstrap confidence intervals, and failure case diagnostics, see
EVALUATION.md.
- Meng, K., et al. (2022). Locating and Editing Factual Associations in GPT. Advances in Neural Information Processing Systems (NeurIPS 2022). arXiv:2202.05262.
- Meng, K., et al. (2023). Mass-Editing Memory in a Transformer. International Conference on Learning Representations (ICLR 2023). arXiv:2210.07229.
- Chen, Z., Zhan, H., Huang, Y., Wu, X., Deng, D., Weng, D., & Wu, Y. (2026). KEditVis: A Visual Analytics System for Knowledge Editing of Large Language Models. IEEE Transactions on Visualization and Computer Graphics (TVCG), vol. 32, no. 6, pp. 4818–4828. arXiv:2603.29689v1.
- Geva, M., et al. (2021). Transformer Feed-Forward Layers Are Key-Value Memories. Empirical Methods in Natural Language Processing (EMNLP 2021). arXiv:2012.14913.
This project is licensed under the MIT License - see the LICENSE file for details.