Code for the paper "Medical Interpretability and Knowledge Maps of Large Language Models" (ICLR 2026).
This repository provides tools to study how LLMs represent and process medical knowledge through four interpretability techniques:
These techniques are applied across multiple medical knowledge areas (patient age, symptoms, diseases, disease progression, drug treatments, drug dosages) to build LLM knowledge maps showing where medical knowledge is stored in the model.
| Model | Parameters |
|---|---|
| Llama-3.3-70B-Instruct | 70B |
| Gemma-3-27b-it | 27B |
| MedGemma-27b-text-it | 27B |
| Qwen3-32B | 32B |
| GPT-OSS-120B | 120B |
| Llama3-OpenBioLLM-70B | 70B |
| PMC-LLaMA-13B | 13B |
| ClinicalCamel-70B | 70B |
| Palmyra-Med-70B | 70B |
| Meditron-70B | 70B |
| HuatuoGPT-o1-70B | 70B |
conda create -n medical-interp python=3.10 -y
conda activate medical-interp
pip install -r requirements.txt
device_map for automatic multi-GPU sharding.
├── runAct.py # Main entry point — loads model, dispatches analyses
├── runActSomeGPUs.py # Variant for running on a subset of GPUs
├── act.py # Base Act class: hooks, UMAP, saliency, lesioning, patching
├── ageAct.py # Age analysis (1–100 year sweep)
├── genderAct.py # Gender representation analysis
├── diseaseAct.py # Disease representation by specialty
├── symptomAct.py # Symptom clustering analysis
├── drugAct.py # Drug analysis (mechanism & specialty clustering)
├── top100DrugAct.py # Top-100 US drugs analysis
├── dosageAct.py # Drug dosage analysis
├── progressionAct.py # Disease progression (9-stage trajectories)
├── maps.py # LLM map generation and metrics aggregation
├── saliency.py # Gradient-based weight saliency utilities
├── utils.py # Silhouette score computation with bootstrap CIs
├── Makefile # Convenience targets for running analyses
├── requirements.txt # Python dependencies
├── runall.sh # Bash script to run analyses across multiple models
├── gemma.py # Standalone test script for Gemma/MedGemma
└── l4.py # Standalone test script for Llama-4
# Example: download Llama-3.3-70B-Instruct
huggingface-cli download meta-llama/Llama-3.3-70B-Instruct \
--local-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct
All analyses are run via runAct.py. You select the model with --model-dir and enable analyses with flags:
# UMAP analysis on age and disease
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_umap --age --disease
# Saliency analysis on symptoms and drugs
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_saliency --symptom --drug
# Layer lesioning on diseases
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_lesioning --disease
# Activation patching on drugs and dosages
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_activation_patching --drug --dosage
# Generate LLM knowledge maps (requires previous analyses to be cached)
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_maps --age --disease --symptom --drug --dosage
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_umap --do_saliency --do_lesioning --do_activation_patching --do_maps \
--age --disease --symptom --drug --dosage
The Makefile provides shortcuts. Edit the MODEL_DIR variable at the top, then enable the desired knowledge areas by uncommenting them:
# Uncomment the analyses you want to run:
age=--age
disease=--disease
symptom=--symptom
drug=--drug
dosage=--dosage
Then run:
make umap # UMAP analysis
make saliency # Weight saliency
make lesioning # Layer lesioning
make activation_patching # Activation patching
make maps # Generate LLM maps (from cached results)
make all_analyses # Run everything
To produce LaTeX tables and per-layer metric plots from cached results (no GPU needed):
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.2-1B-Instruct --metrics_table
By default, results are cached in the results/ directory and reused on subsequent runs. To force re-computation:
python runAct.py --model-dir /path/to/model --do_umap --age --no_cache
| Flag | Description |
|---|---|
--do_umap | UMAP projections of intermediate activations |
--do_saliency | Gradient-based weight saliency |
--do_lesioning | Layer lesioning (replace layer with identity) |
--do_lesioning_finegrained | Fine-grained lesioning (per attention head / MLP) |
--do_activation_patching | Activation patching (per layer) |
--do_activation_patching_finegrained | Fine-grained activation patching |
--do_maps | Generate integrated LLM knowledge maps |
--do_heatmap | Generate heatmap visualizations |
--metrics_table | Generate LaTeX metrics tables from cached results |
--no_cache | Force re-computation (ignore cached results) |
| Flag | Description |
|---|---|
--age | Patient age (1-100 year sweep) |
--gender | Patient gender |
--disease | Diseases grouped by medical specialty |
--symptom | Medical symptoms grouped by category |
--drug | Drug treatments (mechanism of action & specialty) |
--prog | Disease progression (9-stage trajectories) |
--dosage | Drug dosage (safe vs. lethal dose ranges) |
@inproceedings{marinescu2026medical,
title={Medical Interpretability and Knowledge Maps of Large Language Models},
author={Marinescu, Razvan and Gruber, Victoria-Elisabeth and Fajardo, Diego},
booktitle={International Conference on Learning Representations (ICLR)},
year={2026}
}
This project is for research purposes. Please cite the paper if you use this code.
1 commits
1 commits
Python
98.3%
Makefile
1.7%
Code for the paper "Medical Interpretability and Knowledge Maps of Large Language Models" (ICLR 2026).
This repository provides tools to study how LLMs represent and process medical knowledge through four interpretability techniques:
These techniques are applied across multiple medical knowledge areas (patient age, symptoms, diseases, disease progression, drug treatments, drug dosages) to build LLM knowledge maps showing where medical knowledge is stored in the model.
| Model | Parameters |
|---|---|
| Llama-3.3-70B-Instruct | 70B |
| Gemma-3-27b-it | 27B |
| MedGemma-27b-text-it | 27B |
| Qwen3-32B | 32B |
| GPT-OSS-120B | 120B |
| Llama3-OpenBioLLM-70B | 70B |
| PMC-LLaMA-13B | 13B |
| ClinicalCamel-70B | 70B |
| Palmyra-Med-70B | 70B |
| Meditron-70B | 70B |
| HuatuoGPT-o1-70B | 70B |
conda create -n medical-interp python=3.10 -y
conda activate medical-interp
pip install -r requirements.txt
device_map for automatic multi-GPU sharding.
├── runAct.py # Main entry point — loads model, dispatches analyses
├── runActSomeGPUs.py # Variant for running on a subset of GPUs
├── act.py # Base Act class: hooks, UMAP, saliency, lesioning, patching
├── ageAct.py # Age analysis (1–100 year sweep)
├── genderAct.py # Gender representation analysis
├── diseaseAct.py # Disease representation by specialty
├── symptomAct.py # Symptom clustering analysis
├── drugAct.py # Drug analysis (mechanism & specialty clustering)
├── top100DrugAct.py # Top-100 US drugs analysis
├── dosageAct.py # Drug dosage analysis
├── progressionAct.py # Disease progression (9-stage trajectories)
├── maps.py # LLM map generation and metrics aggregation
├── saliency.py # Gradient-based weight saliency utilities
├── utils.py # Silhouette score computation with bootstrap CIs
├── Makefile # Convenience targets for running analyses
├── requirements.txt # Python dependencies
├── runall.sh # Bash script to run analyses across multiple models
├── gemma.py # Standalone test script for Gemma/MedGemma
└── l4.py # Standalone test script for Llama-4
# Example: download Llama-3.3-70B-Instruct
huggingface-cli download meta-llama/Llama-3.3-70B-Instruct \
--local-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct
All analyses are run via runAct.py. You select the model with --model-dir and enable analyses with flags:
# UMAP analysis on age and disease
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_umap --age --disease
# Saliency analysis on symptoms and drugs
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_saliency --symptom --drug
# Layer lesioning on diseases
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_lesioning --disease
# Activation patching on drugs and dosages
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_activation_patching --drug --dosage
# Generate LLM knowledge maps (requires previous analyses to be cached)
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_maps --age --disease --symptom --drug --dosage
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.3-70B-Instruct \
--do_umap --do_saliency --do_lesioning --do_activation_patching --do_maps \
--age --disease --symptom --drug --dosage
The Makefile provides shortcuts. Edit the MODEL_DIR variable at the top, then enable the desired knowledge areas by uncommenting them:
# Uncomment the analyses you want to run:
age=--age
disease=--disease
symptom=--symptom
drug=--drug
dosage=--dosage
Then run:
make umap # UMAP analysis
make saliency # Weight saliency
make lesioning # Layer lesioning
make activation_patching # Activation patching
make maps # Generate LLM maps (from cached results)
make all_analyses # Run everything
To produce LaTeX tables and per-layer metric plots from cached results (no GPU needed):
python runAct.py --model-dir /data/hf/meta-llama/Llama-3.2-1B-Instruct --metrics_table
By default, results are cached in the results/ directory and reused on subsequent runs. To force re-computation:
python runAct.py --model-dir /path/to/model --do_umap --age --no_cache
| Flag | Description |
|---|---|
--do_umap | UMAP projections of intermediate activations |
--do_saliency | Gradient-based weight saliency |
--do_lesioning | Layer lesioning (replace layer with identity) |
--do_lesioning_finegrained | Fine-grained lesioning (per attention head / MLP) |
--do_activation_patching | Activation patching (per layer) |
--do_activation_patching_finegrained | Fine-grained activation patching |
--do_maps | Generate integrated LLM knowledge maps |
--do_heatmap | Generate heatmap visualizations |
--metrics_table | Generate LaTeX metrics tables from cached results |
--no_cache | Force re-computation (ignore cached results) |
| Flag | Description |
|---|---|
--age | Patient age (1-100 year sweep) |
--gender | Patient gender |
--disease | Diseases grouped by medical specialty |
--symptom | Medical symptoms grouped by category |
--drug | Drug treatments (mechanism of action & specialty) |
--prog | Disease progression (9-stage trajectories) |
--dosage | Drug dosage (safe vs. lethal dose ranges) |
@inproceedings{marinescu2026medical,
title={Medical Interpretability and Knowledge Maps of Large Language Models},
author={Marinescu, Razvan and Gruber, Victoria-Elisabeth and Fajardo, Diego},
booktitle={International Conference on Learning Representations (ICLR)},
year={2026}
}
This project is for research purposes. Please cite the paper if you use this code.
1 commits
1 commits
Python
98.3%
Makefile
1.7%