Views
No views yet
1from tdc.multi_pred.anndata_dataset import DataLoader
2from tdc import tdc_hf_interface
3from tdc.model_server.tokenizers.scgpt import scGPTTokenizer
4import torch
5
6# an example dataset
7adata = DataLoader("cellxgene_sample_small",
8 "./data",
9 dataset_names=["cellxgene_sample_small"],
10 no_convert=True).adata
11
12# code for loading the model and performing inference
13scgpt = tdc_hf_interface("scGPT")
14model = scgpt.load() # This line can cause segmentation fault on inappropriate setup
15tokenizer = scGPTTokenizer()
16gene_ids = adata.var["feature_name"].to_numpy(
17) # Convert to numpy array
18tokenized_data = tokenizer.tokenize_cell_vectors(
19 adata.X.toarray(), gene_ids)
20mask = torch.tensor([x != 0 for x in tokenized_data[0][1]],
21 dtype=torch.bool)
22
23# Extract first embedding
24first_embed = model(tokenized_data[0][0],
25 tokenized_data[0][1],
26 attention_mask=mask)@inproceedings{
velez-arce2024signals,
title={Signals in the Cells: Multimodal and Contextualized Machine Learning Foundations for Therapeutics},
author={Alejandro Velez-Arce and Xiang Lin and Kexin Huang and Michelle M Li and Wenhao Gao and Bradley Pentelute and Tianfan Fu and Manolis Kellis and Marinka Zitnik},
booktitle={NeurIPS 2024 Workshop on AI for New Drug Modalities},
year={2024},
url={https://openreview.net/forum?id=kL8dlYp6IM}
}