Correct README: 512-d shared space, fix package import + GitHub URL, fill in verified eval numbers
Browse filesFixes from end-to-end reproducer validation (zinagoodlab/spatialwhisperer PR #1):
- shared embedding dim: 2048 -> 512 (2048 was the pooled BioBERT feature dim, not the projected shared space)
- code example: from spatialwhisperer import load_spatialwhisperer_model (was cellwhisperer.utils.model_io.load_cellwhisperer_model, pre-rename)
- GitHub URL: zinagoodlab/spatialwhisperer (was Good-Lab, which is the HF org only)
- removed reference to non-existent examples/zero_shot_celltype.py
- dropped "private repo access" framing + pass api_keys/huggingface_write shell example
- evaluation table: filled in Lizard (0.764) and PanNuke (0.689) AUROCs with verified-reproduced numbers; dropped the suspect +XX% column (baseline comparisons live in the paper)
- ckpt size: ~530 MB (was ~505 MB)
|
@@ -1,94 +1,119 @@
|
|
| 1 |
---
|
| 2 |
license: cc-by-nc-4.0
|
| 3 |
tags:
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
library_name: pytorch
|
| 11 |
-
pipeline_tag: zero-shot-image-classification
|
| 12 |
---
|
| 13 |
|
| 14 |
# SpatialWhisperer
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
This
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
| Modality
|
| 25 |
-
|----------
|
| 26 |
-
| Image (H&E)
|
| 27 |
-
| Transcriptome
|
| 28 |
-
| Text
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
## Training data
|
| 33 |
|
| 34 |
-
Three paired
|
| 35 |
|
| 36 |
- **HEST-1K** — H&E ↔ spatial gene expression (Visium-style spots)
|
| 37 |
-
- **
|
| 38 |
- **ARCHS4/GEO** — gene expression ↔ free-text sample descriptions
|
| 39 |
|
| 40 |
-
Training
|
| 41 |
|
| 42 |
-
##
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|-----------|------------------|-------------------------|---------|
|
| 48 |
-
| PathoCell | **0.630** | 0.554 | +13.7% |
|
| 49 |
-
| Lizard | (see paper) | — | +15.9% |
|
| 50 |
-
| PanNuke | (see paper) | — | +13.7% |
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
|
| 60 |
```python
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
```
|
| 68 |
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
``
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
## Intended use & limitations
|
| 78 |
|
| 79 |
-
**Intended
|
| 80 |
|
| 81 |
-
**Not intended
|
| 82 |
|
| 83 |
-
**
|
| 84 |
- Trained on Visium-scale spots (~55 μm); finer-grained image–expression alignment is not guaranteed.
|
| 85 |
- BioBERT vocabulary constrains the text tower; rare technical terms may be out-of-distribution.
|
| 86 |
- The image tower (UNI2) is locked; performance on tissue types poorly represented in UNI2's pretraining will be lower.
|
| 87 |
|
| 88 |
-
##
|
| 89 |
|
| 90 |
-
-
|
| 91 |
-
- `README.md` — this card.
|
| 92 |
|
| 93 |
## Citation
|
| 94 |
|
|
@@ -106,7 +131,3 @@ To compute image–text similarities for zero-shot cell-type annotation, encode
|
|
| 106 |
url = {https://openreview.net/forum?id=Ze7U293Zw4}
|
| 107 |
}
|
| 108 |
```
|
| 109 |
-
|
| 110 |
-
## License
|
| 111 |
-
|
| 112 |
-
CC BY-NC 4.0 (research use). Foundation model weights (UNI2, Geneformer, BioBERT) carry their own licenses; please consult upstream repositories.
|
|
|
|
| 1 |
---
|
| 2 |
license: cc-by-nc-4.0
|
| 3 |
tags:
|
| 4 |
+
- biology
|
| 5 |
+
- histopathology
|
| 6 |
+
- spatial-transcriptomics
|
| 7 |
+
- multimodal
|
| 8 |
+
- pathology
|
| 9 |
+
- gene-expression
|
| 10 |
+
- biobert
|
| 11 |
+
- vision-language
|
| 12 |
library_name: pytorch
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
# SpatialWhisperer
|
| 16 |
|
| 17 |
+
A trimodal embedding model that aligns hematoxylin & eosin (H&E) image patches, gene-expression profiles, and free-text descriptions into a shared 512-dimensional space. Enables zero-shot cell-type annotation of H&E patches and natural-language querying over histopathology and spatial transcriptomics data.
|
| 18 |
|
| 19 |
+
This checkpoint (seed 0) is from the ICML 2026 paper *[Transitive Representation Learning Enhances Histopathology Annotation](https://openreview.net/forum?id=Ze7U293Zw4)* (Schaefer et al., PMLR vol. 306). The paper refers to this configuration as the **Trimodal** model: three encoders trained on two paired-modality datasets (transcriptome↔text and image↔transcriptome) that together span three modalities.
|
| 20 |
|
| 21 |
+
- **Code & reproduction pipeline:** <https://github.com/zinagoodlab/spatialwhisperer>
|
| 22 |
+
- **Paper:** <https://openreview.net/forum?id=Ze7U293Zw4>
|
| 23 |
|
| 24 |
+
## Architecture
|
| 25 |
|
| 26 |
+
| Modality | Encoder | Status |
|
| 27 |
+
|----------|---------|--------|
|
| 28 |
+
| Image (H&E) | UNI2 (`MahmoodLab/UNI2-h`) | locked |
|
| 29 |
+
| Transcriptome | Geneformer-12L-30M | locked |
|
| 30 |
+
| Text | BioBERT v1.1 | trained |
|
| 31 |
|
| 32 |
+
Three projection heads map each encoder's pooled features into a shared 512-dimensional space. Only the text tower and the three projection heads are trained.
|
| 33 |
|
| 34 |
## Training data
|
| 35 |
|
| 36 |
+
Three paired-modality datasets:
|
| 37 |
|
| 38 |
- **HEST-1K** — H&E ↔ spatial gene expression (Visium-style spots)
|
| 39 |
+
- **CellxGene Census** — gene expression ↔ free-text cell/sample metadata
|
| 40 |
- **ARCHS4/GEO** — gene expression ↔ free-text sample descriptions
|
| 41 |
|
| 42 |
+
Training: 4 epochs, AdamW (lr 1e-5), cosine schedule (3% warmup), batch size 512, single H100. This checkpoint is from epoch 3, global step 14624.
|
| 43 |
|
| 44 |
+
## What this checkpoint contains
|
| 45 |
+
|
| 46 |
+
- `spatialwhisperer.ckpt` — Lightning state-dict (~530 MB, 236 tensors: trained BioBERT text tower + three projection heads) plus the `hyper_parameters` block. Optimizer/scheduler state is stripped.
|
| 47 |
|
| 48 |
+
**The locked foundation-model weights are NOT included.** UNI2 and Geneformer are re-instantiated at load time from their original providers. The `load_spatialwhisperer_model()` convenience wrapper fetches both on first call.
|
| 49 |
|
| 50 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
Install the [code repository](https://github.com/zinagoodlab/spatialwhisperer) (pixi env), then:
|
| 53 |
|
| 54 |
+
```python
|
| 55 |
+
from spatialwhisperer import load_spatialwhisperer_model
|
| 56 |
+
|
| 57 |
+
model, tokenizer, transcriptome_processor, image_processor = load_spatialwhisperer_model()
|
| 58 |
+
# model: TranscriptomeTextDualEncoderLightning (frozen, eval mode, on CUDA if available)
|
| 59 |
+
```
|
| 60 |
|
| 61 |
+
First call downloads the SpatialWhisperer checkpoint plus UNI2 and Geneformer weights; subsequent calls load from cache.
|
| 62 |
|
| 63 |
+
Each `get_<modality>_features` call returns `(pooled_features, projected_embed_in_shared_space)`. The second element is the 512-D shared-space embedding to compare across modalities.
|
| 64 |
|
| 65 |
```python
|
| 66 |
+
import torch
|
| 67 |
|
| 68 |
+
prompts = ["cytotoxic T cells", "plasma cells"]
|
| 69 |
+
text_inputs = tokenizer(prompts, return_tensors="pt", padding=True).to(model.device)
|
| 70 |
+
|
| 71 |
+
with torch.no_grad():
|
| 72 |
+
_, text_emb = model.model.get_text_features(normalize_embeds=True, **text_inputs)
|
| 73 |
+
print(text_emb.shape) # (2, 512)
|
| 74 |
```
|
| 75 |
|
| 76 |
+
Image and transcriptome embeddings follow the same pattern; see the [GitHub README](https://github.com/zinagoodlab/spatialwhisperer#use-the-model) for complete examples covering all three modalities.
|
| 77 |
|
| 78 |
+
## Foundation-model setup
|
| 79 |
+
|
| 80 |
+
UNI2 (`MahmoodLab/UNI2-h`) is a gated HuggingFace model. Before first use:
|
| 81 |
+
|
| 82 |
+
1. Accept the terms at <https://huggingface.co/MahmoodLab/UNI2-h>.
|
| 83 |
+
2. Make a read token visible to your environment — the loader checks `HF_TOKEN` / `HUGGINGFACE_TOKEN`, otherwise falls back to `huggingface_hub`'s on-disk cache. The simplest setup is:
|
| 84 |
+
```bash
|
| 85 |
+
huggingface-cli login # paste your read token
|
| 86 |
+
```
|
| 87 |
|
| 88 |
+
Geneformer downloads without gating.
|
| 89 |
+
|
| 90 |
+
## Evaluation
|
| 91 |
+
|
| 92 |
+
The accompanying [code repository](https://github.com/zinagoodlab/spatialwhisperer) reproduces every paper benchmark with one command: `pixi run snakemake -j N paper_all`. Verified end-to-end on a fresh ILC ampere4 clone (2026-05-31):
|
| 93 |
+
|
| 94 |
+
| Benchmark | Macro AUROC (this ckpt, seed 0) |
|
| 95 |
+
|-----------|-----------------|
|
| 96 |
+
| PathoCell CRC (13-class) | 0.630 |
|
| 97 |
+
| Lizard (3-class reduced) | 0.764 |
|
| 98 |
+
| PanNuke (4-class reduced) | 0.689 |
|
| 99 |
+
| Kriegsmann Skin Conditions (16-class, clinical labels) | 0.698 |
|
| 100 |
+
|
| 101 |
+
These match the paper's reported Trimodal seed-0 numbers exactly. Comparisons to CONCH, PLIP, OmiCLIP, and other baselines are in the paper.
|
| 102 |
|
| 103 |
## Intended use & limitations
|
| 104 |
|
| 105 |
+
**Intended:** research on multimodal histopathology, zero-shot cell-type annotation, spatial transcriptomics analysis, and natural-language querying over H&E and gene-expression data.
|
| 106 |
|
| 107 |
+
**Not intended:** clinical diagnosis or treatment decisions. The model was trained on academic datasets and is not validated for clinical use.
|
| 108 |
|
| 109 |
+
**Limitations:**
|
| 110 |
- Trained on Visium-scale spots (~55 μm); finer-grained image–expression alignment is not guaranteed.
|
| 111 |
- BioBERT vocabulary constrains the text tower; rare technical terms may be out-of-distribution.
|
| 112 |
- The image tower (UNI2) is locked; performance on tissue types poorly represented in UNI2's pretraining will be lower.
|
| 113 |
|
| 114 |
+
## License
|
| 115 |
|
| 116 |
+
**CC BY-NC 4.0** (research use). Foundation-model weights (UNI2, Geneformer, BioBERT) carry their own licenses; consult the upstream repositories.
|
|
|
|
| 117 |
|
| 118 |
## Citation
|
| 119 |
|
|
|
|
| 131 |
url = {https://openreview.net/forum?id=Ze7U293Zw4}
|
| 132 |
}
|
| 133 |
```
|
|
|
|
|
|
|
|
|
|
|
|