netformer is a small transformer that treats each cell's genes as words, learns their grammar, and then asks: what happens if I switch this gene off?
See how it worksRead the docsView on GitHubEvery cell in your body reads from the same genome, but each cell type switches on a different set of genes. netformer learns that pattern in four plain steps.
Sort the genes from most to least active. The order is the sentence.
Hide some genes and ask the model to guess them from the rest.
Add a small head to the learned model and fine-tune it to label cells.
Delete a gene from the sentence and see how far the cell moves toward another type.
Two small interactive demos. The first is a toy; the second uses the project's real results.
Raw counts (scaled by depth)
Resulting sentence (genes ranked by activity vs. their typical level)
Bar = how far the alpha cell moves toward a beta cell. Real output of results/perturbation_*.csv.
Every number comes from make all β nothing is hand-copied.
| Starting point | Accuracy | Macro-F1 (14 types) | Macro-F1 (9 common types) |
|---|---|---|---|
| Pretrained | 0.971 | 0.713 | 0.931 |
| From scratch | 0.971 | 0.653 | 0.933 |






Limits: this is an engineering demo, not a biological result. Attention isn't causation, and the perturbation ranking is a hypothesis generator. See the model card.
Python 3.10+. The full pipeline takes about 90 minutes on a laptop CPU.
git clone https://github.com/ashokdwivedi/netformer && cd netformer
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
make data # download GSE84133 + tokenise (~3 min)
make pretrain # masked-gene pretraining (~60 min)
make finetune # cell-type head + control (~25 min)
make eval # metrics, perturbation, attention network
make figures # rebuild every figure
make smoke # 1-minute synthetic run to check your setup
Rank-value encoding, fit on the training split only so nothing leaks.
Pre-LN encoder with GEGLU, written from scratch; attention maps recoverable.
DDP, mixed precision, resumable checkpoints.
Slurm scripts for 4 nodes Γ 8 GPUs with auto-resume.
In-silico knock-out / activation and attention networks.
27 tests, including depth invariance and padding isolation.