A dual-encoder + late-fusion system for single-cell transcriptomics that combines Cell2Sentence / C2S-Scale-Gemma with UHG-based graph learning.
This repository is now being extended toward an OKSM / OSKM reprogramming research workflow focused on:
The branch-level roadmap for that work lives in PROJECT_PLAN.md.
The near-term objective is to turn the current hybrid into a more explicit C2S + UHG platform for OKSM-driven cellular state analysis.
That means the codebase is evolving in phases:
src/ modules agree.Current branch work includes:
PROJECT_PLAN.mdsrc/eval/reprogramming_visuals.pytests/Select A100 GPU: Runtime β Change runtime type β GPU β A100
Run the complete pipeline: Real PBMC data + C2S-Scale-Gemma-2-27B model
Select A100 GPU: Runtime β Change runtime type β GPU β A100
Run the prototype: Dummy data + Gemma-9B model
# Clone repository
git clone https://github.com/zbovaird/C2S-Scale-Gemma.git
cd C2S-Scale-Gemma
# Install dependencies with uv
uv sync
# Download data
uv run scripts/download_data.py
# Build graphs
uv run scripts/build_graphs.py --cfg configs/colab_7b.toml
# Train model
uv run scripts/align_dual_encoder.py --cfg configs/colab_7b.toml
The C2S-Scale-Gemma hybrid model combines:
The branch is adding three specific capabilities for reprogramming work:
POU5F1, SOX2, KLF4, and MYCvandijklab/C2S-Scale-Gemma-2-27B - Full production modelgoogle/gemma-2-9b - Prototype modelvandijklab/C2S-Scale-Gemma-2-27B - Production scale# Core ML
torch>=2.3.0
transformers>=4.43.0
accelerate>=1.1.0
bitsandbytes>=0.43.0
peft>=0.11.0
# UHG Library (custom)
uhg
# Single-cell analysis
scanpy>=1.9.0
anndata>=0.10.0
umap-learn>=0.5.0
# Graph processing
networkx>=3.2.0
pynndescent>=0.5.0
# Training infrastructure
mlflow>=2.14.0
omegaconf>=2.3.0
wandb>=0.17.0
C2S-Scale-Gemma/
βββ src/ # Source code
β βββ data/ # Data loading and preprocessing
β βββ graphs/ # Graph construction (kNN, L-R, GRN)
β βββ hgnn/ # Hyperbolic GNN encoder
β βββ text/ # Gemma text encoder with LoRA
β βββ fusion/ # Dual-encoder alignment and fusion
β βββ eval/ # Evaluation tasks and metrics
β βββ uhg_adapters/ # UHG library adapters
βββ scripts/ # Executable workflows
βββ configs/ # TOML configuration files
βββ notebooks/ # Colab notebooks
β βββ c2s_scale_gemma_production.ipynb # Production notebook
β βββ colab_prototype.ipynb # Legacy prototype
βββ docs/ # Documentation
The data and graph pipeline now supports lightweight OKSM-aware configuration:
[knn_graph]
oskm_reweight_enabled = true
oskm_weight_multiplier = 1.5
oskm_score_threshold = 0.0
oskm_species = "human"
Dataset-side sentence anchoring is exposed in code through CellSentenceDataset and is intended to become config-driven in the training scripts as the branch progresses:
top_genesoskm_anchor_mode ("none" or "prepend_present")oskm_speciesconfigs/colab_7b.toml)[model.hgnn]
hidden_dim = 768
output_dim = 384
num_layers = 4
[model.text]
model_name = "vandijklab/C2S-Scale-Gemma-2-27B"
max_length = 1024
[training]
batch_size = 16
learning_rate = 2e-4
num_epochs = 10
gradient_accumulation_steps = 2
configs/colab_7b.toml)[model.hgnn]
hidden_dim = 512
output_dim = 256
num_layers = 3
[model.text]
model_name = "google/gemma-2-9b"
max_length = 512
[training]
batch_size = 8
learning_rate = 1e-4
num_epochs = 5
The production notebook (c2s_scale_gemma_production.ipynb) includes:
uv run scripts/download_data.py
uv run scripts/build_graphs.py --cfg configs/colab_7b.toml
uv run scripts/pretrain_hgnn.py --cfg configs/colab_7b.toml
uv run scripts/align_dual_encoder.py --cfg configs/colab_7b.toml
uv run scripts/finetune_lora.py --cfg configs/colab_7b.toml
uv run scripts/evaluate.py --cfg configs/colab_7b.toml
Generate an in silico perturbation dataset:
uv run scripts/perturb_oskm_expression.py \
--data-path data/raw/reprogramming.h5ad \
--mode overexpress \
--factor 2.0 \
--output-dir artifacts/oskm_perturbation
Compare baseline vs perturbed cells in the learned representation space:
uv run scripts/compare_oskm_perturbation_embeddings.py \
--config configs/colab_7b.toml \
--checkpoint-path artifacts/align_dual_encoder/final_model.pt \
--baseline-data-path data/raw/reprogramming.h5ad \
--perturbed-data-path artifacts/oskm_perturbation/oskm_overexpress.h5ad \
--output-dir artifacts/oskm_embedding_comparison
This exports:
embedding_shift_summary.jsonfused_embedding_shift_frame.jsonGenerate a static report with plots:
uv run scripts/generate_oskm_perturbation_report.py \
--comparison-dir artifacts/oskm_embedding_comparison \
--perturbation-summary artifacts/oskm_perturbation/oskm_overexpress_summary.json
This produces:
shift_histogram.pngoskm_score_vs_shift.pngshift_by_cell_type.pngOSKM_PERTURBATION_REPORT.mdTargeted CPU-friendly tests are included for the compatibility and OKSM groundwork:
pytest tests
The current tests focus on:
# Install dependencies
!pip install uhg torch transformers accelerate peft bitsandbytes scanpy
# Run the complete pipeline
# (See notebooks/c2s_scale_gemma_production.ipynb for full implementation)
@article{c2s_scale_gemma_hybrid,
title={C2S-Scale-Gemma Hybrid: Dual-Encoder + Late-Fusion for Single-Cell Transcriptomics},
author={Bovaird, Zach},
year={2024},
license={CC BY-NC-ND 4.0}
}
This project is licensed under CC BY-NC-ND 4.0. See LICENSE for details.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Ready to revolutionize single-cell transcriptomics? π
30 commits
Python
86.3%
Jupyter Notebook
13.3%
A dual-encoder + late-fusion system for single-cell transcriptomics that combines Cell2Sentence / C2S-Scale-Gemma with UHG-based graph learning.
This repository is now being extended toward an OKSM / OSKM reprogramming research workflow focused on:
The branch-level roadmap for that work lives in PROJECT_PLAN.md.
The near-term objective is to turn the current hybrid into a more explicit C2S + UHG platform for OKSM-driven cellular state analysis.
That means the codebase is evolving in phases:
src/ modules agree.Current branch work includes:
PROJECT_PLAN.mdsrc/eval/reprogramming_visuals.pytests/Select A100 GPU: Runtime β Change runtime type β GPU β A100
Run the complete pipeline: Real PBMC data + C2S-Scale-Gemma-2-27B model
Select A100 GPU: Runtime β Change runtime type β GPU β A100
Run the prototype: Dummy data + Gemma-9B model
# Clone repository
git clone https://github.com/zbovaird/C2S-Scale-Gemma.git
cd C2S-Scale-Gemma
# Install dependencies with uv
uv sync
# Download data
uv run scripts/download_data.py
# Build graphs
uv run scripts/build_graphs.py --cfg configs/colab_7b.toml
# Train model
uv run scripts/align_dual_encoder.py --cfg configs/colab_7b.toml
The C2S-Scale-Gemma hybrid model combines:
The branch is adding three specific capabilities for reprogramming work:
POU5F1, SOX2, KLF4, and MYCvandijklab/C2S-Scale-Gemma-2-27B - Full production modelgoogle/gemma-2-9b - Prototype modelvandijklab/C2S-Scale-Gemma-2-27B - Production scale# Core ML
torch>=2.3.0
transformers>=4.43.0
accelerate>=1.1.0
bitsandbytes>=0.43.0
peft>=0.11.0
# UHG Library (custom)
uhg
# Single-cell analysis
scanpy>=1.9.0
anndata>=0.10.0
umap-learn>=0.5.0
# Graph processing
networkx>=3.2.0
pynndescent>=0.5.0
# Training infrastructure
mlflow>=2.14.0
omegaconf>=2.3.0
wandb>=0.17.0
C2S-Scale-Gemma/
βββ src/ # Source code
β βββ data/ # Data loading and preprocessing
β βββ graphs/ # Graph construction (kNN, L-R, GRN)
β βββ hgnn/ # Hyperbolic GNN encoder
β βββ text/ # Gemma text encoder with LoRA
β βββ fusion/ # Dual-encoder alignment and fusion
β βββ eval/ # Evaluation tasks and metrics
β βββ uhg_adapters/ # UHG library adapters
βββ scripts/ # Executable workflows
βββ configs/ # TOML configuration files
βββ notebooks/ # Colab notebooks
β βββ c2s_scale_gemma_production.ipynb # Production notebook
β βββ colab_prototype.ipynb # Legacy prototype
βββ docs/ # Documentation
The data and graph pipeline now supports lightweight OKSM-aware configuration:
[knn_graph]
oskm_reweight_enabled = true
oskm_weight_multiplier = 1.5
oskm_score_threshold = 0.0
oskm_species = "human"
Dataset-side sentence anchoring is exposed in code through CellSentenceDataset and is intended to become config-driven in the training scripts as the branch progresses:
top_genesoskm_anchor_mode ("none" or "prepend_present")oskm_speciesconfigs/colab_7b.toml)[model.hgnn]
hidden_dim = 768
output_dim = 384
num_layers = 4
[model.text]
model_name = "vandijklab/C2S-Scale-Gemma-2-27B"
max_length = 1024
[training]
batch_size = 16
learning_rate = 2e-4
num_epochs = 10
gradient_accumulation_steps = 2
configs/colab_7b.toml)[model.hgnn]
hidden_dim = 512
output_dim = 256
num_layers = 3
[model.text]
model_name = "google/gemma-2-9b"
max_length = 512
[training]
batch_size = 8
learning_rate = 1e-4
num_epochs = 5
The production notebook (c2s_scale_gemma_production.ipynb) includes:
uv run scripts/download_data.py
uv run scripts/build_graphs.py --cfg configs/colab_7b.toml
uv run scripts/pretrain_hgnn.py --cfg configs/colab_7b.toml
uv run scripts/align_dual_encoder.py --cfg configs/colab_7b.toml
uv run scripts/finetune_lora.py --cfg configs/colab_7b.toml
uv run scripts/evaluate.py --cfg configs/colab_7b.toml
Generate an in silico perturbation dataset:
uv run scripts/perturb_oskm_expression.py \
--data-path data/raw/reprogramming.h5ad \
--mode overexpress \
--factor 2.0 \
--output-dir artifacts/oskm_perturbation
Compare baseline vs perturbed cells in the learned representation space:
uv run scripts/compare_oskm_perturbation_embeddings.py \
--config configs/colab_7b.toml \
--checkpoint-path artifacts/align_dual_encoder/final_model.pt \
--baseline-data-path data/raw/reprogramming.h5ad \
--perturbed-data-path artifacts/oskm_perturbation/oskm_overexpress.h5ad \
--output-dir artifacts/oskm_embedding_comparison
This exports:
embedding_shift_summary.jsonfused_embedding_shift_frame.jsonGenerate a static report with plots:
uv run scripts/generate_oskm_perturbation_report.py \
--comparison-dir artifacts/oskm_embedding_comparison \
--perturbation-summary artifacts/oskm_perturbation/oskm_overexpress_summary.json
This produces:
shift_histogram.pngoskm_score_vs_shift.pngshift_by_cell_type.pngOSKM_PERTURBATION_REPORT.mdTargeted CPU-friendly tests are included for the compatibility and OKSM groundwork:
pytest tests
The current tests focus on:
# Install dependencies
!pip install uhg torch transformers accelerate peft bitsandbytes scanpy
# Run the complete pipeline
# (See notebooks/c2s_scale_gemma_production.ipynb for full implementation)
@article{c2s_scale_gemma_hybrid,
title={C2S-Scale-Gemma Hybrid: Dual-Encoder + Late-Fusion for Single-Cell Transcriptomics},
author={Bovaird, Zach},
year={2024},
license={CC BY-NC-ND 4.0}
}
This project is licensed under CC BY-NC-ND 4.0. See LICENSE for details.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Ready to revolutionize single-cell transcriptomics? π
30 commits
Python
86.3%
Jupyter Notebook
13.3%