Views
No views yet
TransformerGenerator) is a shared transformer over context-aware gene
token sequences, followed by context-specific projection heads (one per context in the table
below) trained with a context-specific contrastive objective.| Hyperparameter | Value |
|---|---|
Embedding dim (d_model) | 384 |
Attention heads (nhead) | 6 |
Transformer layers (nlayers) | 12 |
Feedforward dim (dim_embedding) | 384 |
| Dropout | 0.1 |
| Vocabulary size | 17028 |
| Cell embedding style | avg-pool |
| Contexts | disease, cell_type, tissue |
| Context-specific projections | True |
| Domain adaptation (Sinkhorn) | True |
| File | Purpose |
|---|---|
model.safetensors | Model weights only (stripped of optimizer/scheduler/scaler state) |
config.json | Architecture hyperparameters needed to reconstruct TransformerGenerator |
tokenizer_dictionary_AUTISM.pkl | Gene/context vocabulary (17028 tokens) used by the context-aware tokenizer |
metadata_dictionary_AUTISM.pkl | Obs-column metadata mapping preserved from the source AnnData |
median_genes_*_all_AUTISM.pkl | Per-context median expression reference used to derive up-/down-regulated gene tokens at tokenization time |
TransformerGenerator) is not a standard transformers class, so
loading it requires the cascade package from the GitHub repo rather than AutoModel:pip install git+https://github.com/mims-harvard/CASCADE1import json, pickle
2from huggingface_hub import hf_hub_download
3from safetensors.torch import load_file
4from cascade.model.cascade_model import TransformerGenerator
5
6repo_id = "<your-org>/CASCADE-AUTISM"
7
8config = json.load(open(hf_hub_download(repo_id, "config.json")))
9vocab = pickle.load(open(hf_hub_download(repo_id, f"tokenizer_dictionary_AUTISM.pkl"), "rb"))
10weights = load_file(hf_hub_download(repo_id, "model.safetensors"))
11
12model = TransformerGenerator(
13 d_model=config["d_model"],
14 nhead=config["nhead"],
15 ntoken=config["vocab_size"],
16 dim_embedding=config["dim_embedding"],
17 nlayers=config["nlayers"],
18 vocab=vocab,
19 nclass=config["nclass"],
20 dropout=config["dropout"],
21 pad_token=config["pad_token"],
22 cell_emb_style=config["cell_emb_style"],
23 context_specific_projections=config["context_specific_projections"],
24 constant_ctx=config["constant_ctx"],
25 only_contrastive=config["only_contrastive"],
26 DA=config["DA"],
27 lambda_sinkhorn=config["lambda_sinkhorn"],
28 merged_contexts=config["merged_contexts"],
29)
30model.load_state_dict(weights)
31model.eval()cascade/data/tokenizer.py in the GitHub repo,
using the tokenizer_dictionary_AUTISM.pkl and median_genes_*_all_AUTISM.pkl files
from this repo as the vocab and per-context median reference respectively.