xl2024/Interpretable-VLM

Jupyter Notebook

0

1,003 commits

updated Jul 2, 2026

See the code

README

This repository contains the code to reproduce all experimental results and figures from arXiv:2506.15871 using the nnsight library. A summary is available at Blog.

For a fast, interactive introduction to the codebase, please see demo.ipynb.


Getting Started

Installation

Clone the repository and install the required dependencies before running any scripts:

git clone https://github.com/xl2024/Interpretable-VLM.git
cd Interpretable-VLM
pip install -r requirements.txt

Running Experiments

All execution scripts for experiments and plotting are located in the src/plots/ directory. You can run them as Python modules from the root directory.

Example:

python -m src.plots.pca_1b

Project Structure

.
├── configs/
│   └── config.yaml
├── dataset/                  # Test datasets
│   ├── figure_29/            # Image pairs for Figure 29 reproduction
│   └── figure_3/             # PUG-style dataset for Figure 3 reproduction
├── outputs/                  # Experiment results
│   ├── cma/
│   ├── pca/
│   ├── rsa/
│   └── v0/                   # Historic reference outputs
├── src/
│   ├── data/                 # Dataset generation and experiment data records
│   │   ├── cma/
│   │   ├── test_samples/
│   │   ├── generate_pug_dataset.py
│   │   └── synthetic_generator.py
│   ├── math_core/
│   │   └── rsa.py            # Common RSA computations
│   ├── mech_interp/
│   │   ├── cma.py            # Common Causal Mediation tracking & patching
│   │   └── tracer.py
│   ├── model/
│   │   └── loader.py
│   ├── plots/
│   │   ├── cma_*.py          # Scripts to reproduce and plot CMA results
│   │   ├── pca_*.py          # Scripts to reproduce and plot PCA results
│   │   └── rsa_*.py          # Scripts to reproduce and plot RSA results
│   └── utils/
│       ├── hardware.py
│       └── tools.py
├── demo.ipynb                # Quickstart Jupyter Notebook

Reproduction Matrix

The following table details which script maps to which figure, alongside their datasets and output directories.

ScriptReproduced TargetDatasetRaw Data FilepathFigure/Table FilepathNotes
pca_1b.pyFigure 1(b)--outputs/pca/pca_fig_1b.png-
rsa_1c.pyFigures 1(c), 14–19--outputs/rsa/stage/-
cma_1d.pyFigures 1(d), 20–25-src/data/cma/scores/outputs/cma/scores/-
rsa_2.pyFigures 2, 26–28--outputs/rsa/pos/-
cma_3.pyFigures 3(b), 37–43dataset/figure_3/ ¹src/data/cma/sweeping/outputs/cma/sweeping/Does not repeat for standard errors (sweeping across all models is out of my budget).
cma_4.pyFigure 4-src/data/cma/color/outputs/cma/cma_fig_4.png-
cma_4_v2.pyAdditional experiment-src/data/cma/color_v2/-Patches on queries instead of keys and shows it is less effective.
cma_5.pyFigure 5-src/data/cma/reuse/outputs/cma/cma_fig_5.png-
rsa_6.pyFigures 6, 7, 30–36-src/data/cma/entr/fig_6_results.jsonoutputs/rsa/entr/-
rsa_6_v2.pyAdditional experiment-src/data/cma/entr_v2/fig_6_results.jsonoutputs/rsa/entr_v2/Includes the last object's color in the prompt.
cma_29.pyFigure 29dataset/figure_29/src/data/cma/fig_29_results.npzoutputs/cma/cma_fig_29.png-
cma_45.pyFigure 45dataset/coco/ ²src/data/cma/coco/outputs/cma/cma_fig_45.png-
cma_46.pyFigure 46dataset/figure_46/ ²-outputs/cma/count/-
cma_46_v2.pyAdditional experimentdataset/figure_46_v2/ ²-outputs/cma/count_v2/Improved prompt for better base accuracy
cma_tbl_1.pyTable 1-src/data/cma/entr/outputs/cma/entr/cma_tbl_1For images with a 3x3 grid and top_k=50.
cma_tbl_1_v2.pyTable 1-src/data/cma/entr_v2/src/data/cma/entr_v2/cma_tbl_1For images with a 2x2 grid and top_k=50.
pca_new_26.py³Figure 26--outputs/pca/Represents the May version of the paper (all other scripts track the January version for figure numbering).

Notes

¹ Generated using src/data/generate_pug_dataset.py. See dataset/figure_3/README.md for generation details.
² Created from running script.
³ pca_new_26_v2.py was used to generate results in the same output directory and pca_new_26.py requires less memory and more time.

xl2024/Interpretable-VLM

Jupyter Notebook

0

1,003 commits

updated Jul 2, 2026

See the code

README

This repository contains the code to reproduce all experimental results and figures from arXiv:2506.15871 using the nnsight library. A summary is available at Blog.

For a fast, interactive introduction to the codebase, please see demo.ipynb.


Getting Started

Installation

Clone the repository and install the required dependencies before running any scripts:

git clone https://github.com/xl2024/Interpretable-VLM.git
cd Interpretable-VLM
pip install -r requirements.txt

Running Experiments

All execution scripts for experiments and plotting are located in the src/plots/ directory. You can run them as Python modules from the root directory.

Example:

python -m src.plots.pca_1b

Project Structure

.
├── configs/
│   └── config.yaml
├── dataset/                  # Test datasets
│   ├── figure_29/            # Image pairs for Figure 29 reproduction
│   └── figure_3/             # PUG-style dataset for Figure 3 reproduction
├── outputs/                  # Experiment results
│   ├── cma/
│   ├── pca/
│   ├── rsa/
│   └── v0/                   # Historic reference outputs
├── src/
│   ├── data/                 # Dataset generation and experiment data records
│   │   ├── cma/
│   │   ├── test_samples/
│   │   ├── generate_pug_dataset.py
│   │   └── synthetic_generator.py
│   ├── math_core/
│   │   └── rsa.py            # Common RSA computations
│   ├── mech_interp/
│   │   ├── cma.py            # Common Causal Mediation tracking & patching
│   │   └── tracer.py
│   ├── model/
│   │   └── loader.py
│   ├── plots/
│   │   ├── cma_*.py          # Scripts to reproduce and plot CMA results
│   │   ├── pca_*.py          # Scripts to reproduce and plot PCA results
│   │   └── rsa_*.py          # Scripts to reproduce and plot RSA results
│   └── utils/
│       ├── hardware.py
│       └── tools.py
├── demo.ipynb                # Quickstart Jupyter Notebook

Reproduction Matrix

The following table details which script maps to which figure, alongside their datasets and output directories.

ScriptReproduced TargetDatasetRaw Data FilepathFigure/Table FilepathNotes
pca_1b.pyFigure 1(b)--outputs/pca/pca_fig_1b.png-
rsa_1c.pyFigures 1(c), 14–19--outputs/rsa/stage/-
cma_1d.pyFigures 1(d), 20–25-src/data/cma/scores/outputs/cma/scores/-
rsa_2.pyFigures 2, 26–28--outputs/rsa/pos/-
cma_3.pyFigures 3(b), 37–43dataset/figure_3/ ¹src/data/cma/sweeping/outputs/cma/sweeping/Does not repeat for standard errors (sweeping across all models is out of my budget).
cma_4.pyFigure 4-src/data/cma/color/outputs/cma/cma_fig_4.png-
cma_4_v2.pyAdditional experiment-src/data/cma/color_v2/-Patches on queries instead of keys and shows it is less effective.
cma_5.pyFigure 5-src/data/cma/reuse/outputs/cma/cma_fig_5.png-
rsa_6.pyFigures 6, 7, 30–36-src/data/cma/entr/fig_6_results.jsonoutputs/rsa/entr/-
rsa_6_v2.pyAdditional experiment-src/data/cma/entr_v2/fig_6_results.jsonoutputs/rsa/entr_v2/Includes the last object's color in the prompt.
cma_29.pyFigure 29dataset/figure_29/src/data/cma/fig_29_results.npzoutputs/cma/cma_fig_29.png-
cma_45.pyFigure 45dataset/coco/ ²src/data/cma/coco/outputs/cma/cma_fig_45.png-
cma_46.pyFigure 46dataset/figure_46/ ²-outputs/cma/count/-
cma_46_v2.pyAdditional experimentdataset/figure_46_v2/ ²-outputs/cma/count_v2/Improved prompt for better base accuracy
cma_tbl_1.pyTable 1-src/data/cma/entr/outputs/cma/entr/cma_tbl_1For images with a 3x3 grid and top_k=50.
cma_tbl_1_v2.pyTable 1-src/data/cma/entr_v2/src/data/cma/entr_v2/cma_tbl_1For images with a 2x2 grid and top_k=50.
pca_new_26.py³Figure 26--outputs/pca/Represents the May version of the paper (all other scripts track the January version for figure numbering).

Notes

¹ Generated using src/data/generate_pug_dataset.py. See dataset/figure_3/README.md for generation details.
² Created from running script.
³ pca_new_26_v2.py was used to generate results in the same output directory and pca_new_26.py requires less memory and more time.