Cell2Text: Multimodal LLM for Generating Textual Descriptions from Single-Cell RNA-Seq Profiles
Jupyter Notebook
1
265 commits
updated Oct 12, 2026
A Multimodal Large Language Model pipeline that translates single-cell transcriptomic data (gene expression) into comprehensive natural language descriptions.
Cell2Text bridges the gap between single-cell biology and natural language processing. By leveraging foundational models for both biology and language, it takes raw cell gene expression tokens, projects them into a language semantic space, and generates detailed biological descriptions of the cell (including cell type, tissue, disease state, and active pathways).
Thesis: Cell2Text: Multimodal LLM for Generating Textual Descriptions from Single-Cell RNA-Seq Profiles (https://artemis.ece.ntua.gr/server/api/core/bitstreams/a1eed1ad-50a7-4895-9e67-448b2c962b78/content)
The model uses a three-stage encoder-projector-decoder architecture:
Ensure you have the required dependencies installed (e.g., torch, transformers, scanpy, cellxgene_census, geneformer, peft).
Note: You will need the pretrained Geneformer weights, a LLaMA tokenizer/model, and necessary ontology files (like obo.json and GMT pathway files).
create_dataset.py)This script handles the end-to-end data processing pipeline directly from the CELLxGENE Census.
What it does:
TranscriptomeTokenizer.Execution:
python data_preprocess/create_dataset.py \
-N 100000 \
-BS 1000 \
-CS 1000
-N: Target sample size (total cells to extract).-BS: Batch size for saving .h5ad files.-CS: Chunk size for processing AUCell pathway enrichment.train_ddp.py & train_fsdp.py)The repository supports scalable distributed training using either Distributed Data Parallel (DDP) or Fully Sharded Data Parallel (FSDP).
What they do:
train_ddp.py: Ideal for Parameter-Efficient Fine-Tuning (PEFT). It freezes the Geneformer encoder, applies LoRA to the LLaMA decoder, and fully trains the Projector layer. Includes custom checkpointing that separates LoRA adapters from projector weights to save space.train_fsdp.py: Designed for memory-intensive full-parameter fine-tuning. Wraps the entire model (or massive decoders) using PyTorch's FSDP with Mixed Precision and CPU Offloading.--mode sanity flag to rapidly overfit on a small dataset to verify pipeline integrity.Execution (DDP with LoRA):
torchrun --nproc_per_node=<NUM_GPUS> cell2text_train/train_ddp.py \
--mode full \
--train_data_path /path/to/train \
--val_data_path /path/to/val \
--projector mlp \
--batch_size_per_device 4 \
--epochs 5
Execution (FSDP):
torchrun --nproc_per_node=<NUM_GPUS> cell2text_train/train_fsdp.py \
--mode full \
--train_data_path /path/to/train \
--projector qformer
run_evaluation.py & celltype_ontology_metric.ipynb)Evaluating multimodal biological text generation requires more than just standard NLP metrics.
What it does:
celltype_ontology_metric logic): Extracts the predicted cell types/diseases and computes an Ontology Similarity Score. Instead of strict string matching, this calculates the graph distance between the predicted cell type and the true cell type within the Cell Ontology (CL) or Disease Ontology (DOID) DAGs, providing a nuanced biological accuracy score.Execution:
python cell2text_eval/run_evaluation.py \
--checkpoint_path /path/to/checkpoint \
--test_data_path /path/to/test_dataset \
--tokenizer_path /path/to/llama_tokenizer \
--geneformer_path /path/to/geneformer \
--llama_path /path/to/llama \
--projector mlp \
--batch_size 8 \
--use_bertscore True \
--use_comprehensive_metrics True
(Add --load_from_fsdp if you are evaluating a checkpoint generated by the FSDP script).
/data_preprocess: Scripts for fetching from CELLxGENE, mapping ontologies, and tokenizing data./cell2text_model: Contains the core architecture (model.py), merging Geneformer, the Projector classes, and LLaMA./cell2text_train: PyTorch distributed training loops (train_ddp.py, train_fsdp.py)./cell2text_eval: Inference scripts and complex biological/NLP evaluation metrics.Cell2Text: Multimodal LLM for Generating Textual Descriptions from Single-Cell RNA-Seq Profiles
Jupyter Notebook
1
265 commits
updated Oct 12, 2026
A Multimodal Large Language Model pipeline that translates single-cell transcriptomic data (gene expression) into comprehensive natural language descriptions.
Cell2Text bridges the gap between single-cell biology and natural language processing. By leveraging foundational models for both biology and language, it takes raw cell gene expression tokens, projects them into a language semantic space, and generates detailed biological descriptions of the cell (including cell type, tissue, disease state, and active pathways).
Thesis: Cell2Text: Multimodal LLM for Generating Textual Descriptions from Single-Cell RNA-Seq Profiles (https://artemis.ece.ntua.gr/server/api/core/bitstreams/a1eed1ad-50a7-4895-9e67-448b2c962b78/content)
The model uses a three-stage encoder-projector-decoder architecture:
Ensure you have the required dependencies installed (e.g., torch, transformers, scanpy, cellxgene_census, geneformer, peft).
Note: You will need the pretrained Geneformer weights, a LLaMA tokenizer/model, and necessary ontology files (like obo.json and GMT pathway files).
create_dataset.py)This script handles the end-to-end data processing pipeline directly from the CELLxGENE Census.
What it does:
TranscriptomeTokenizer.Execution:
python data_preprocess/create_dataset.py \
-N 100000 \
-BS 1000 \
-CS 1000
-N: Target sample size (total cells to extract).-BS: Batch size for saving .h5ad files.-CS: Chunk size for processing AUCell pathway enrichment.train_ddp.py & train_fsdp.py)The repository supports scalable distributed training using either Distributed Data Parallel (DDP) or Fully Sharded Data Parallel (FSDP).
What they do:
train_ddp.py: Ideal for Parameter-Efficient Fine-Tuning (PEFT). It freezes the Geneformer encoder, applies LoRA to the LLaMA decoder, and fully trains the Projector layer. Includes custom checkpointing that separates LoRA adapters from projector weights to save space.train_fsdp.py: Designed for memory-intensive full-parameter fine-tuning. Wraps the entire model (or massive decoders) using PyTorch's FSDP with Mixed Precision and CPU Offloading.--mode sanity flag to rapidly overfit on a small dataset to verify pipeline integrity.Execution (DDP with LoRA):
torchrun --nproc_per_node=<NUM_GPUS> cell2text_train/train_ddp.py \
--mode full \
--train_data_path /path/to/train \
--val_data_path /path/to/val \
--projector mlp \
--batch_size_per_device 4 \
--epochs 5
Execution (FSDP):
torchrun --nproc_per_node=<NUM_GPUS> cell2text_train/train_fsdp.py \
--mode full \
--train_data_path /path/to/train \
--projector qformer
run_evaluation.py & celltype_ontology_metric.ipynb)Evaluating multimodal biological text generation requires more than just standard NLP metrics.
What it does:
celltype_ontology_metric logic): Extracts the predicted cell types/diseases and computes an Ontology Similarity Score. Instead of strict string matching, this calculates the graph distance between the predicted cell type and the true cell type within the Cell Ontology (CL) or Disease Ontology (DOID) DAGs, providing a nuanced biological accuracy score.Execution:
python cell2text_eval/run_evaluation.py \
--checkpoint_path /path/to/checkpoint \
--test_data_path /path/to/test_dataset \
--tokenizer_path /path/to/llama_tokenizer \
--geneformer_path /path/to/geneformer \
--llama_path /path/to/llama \
--projector mlp \
--batch_size 8 \
--use_bertscore True \
--use_comprehensive_metrics True
(Add --load_from_fsdp if you are evaluating a checkpoint generated by the FSDP script).
/data_preprocess: Scripts for fetching from CELLxGENE, mapping ontologies, and tokenizing data./cell2text_model: Contains the core architecture (model.py), merging Geneformer, the Projector classes, and LLaMA./cell2text_train: PyTorch distributed training loops (train_ddp.py, train_fsdp.py)./cell2text_eval: Inference scripts and complex biological/NLP evaluation metrics.