Analyzing Representation Differences in Cell Foundation Models: A Technical Framework

    This article presents a four-step framework for diagnosing representation differences across cell foundation models pretrained on single-cell transcriptomics. It covers unified embedding extraction, structural metrics such as neighborhood consistency and batch separability, linear probing and retrieval evaluation, and attribution analysis across layers and dimensions. Readers will learn how controlled-variable experiments help distinguish biological signal from technical noise and support more reliable model selection.

    1. Background: Why the Same Task Produces Different Results Across Models

    The number of foundation models pretrained on single-cell transcriptomics data has grown rapidly. These models often trade places on downstream leaderboards, but a more troubling pattern appears in engineering practice: with the same dataset and the same downstream task, swapping one set of pretrained weights can noticeably shift the conclusions. This shows that comparing metrics alone is not enough to support model selection. The real question is what biological information each model’s internal representation space actually encodes.

    If a cell foundation model is understood as an encoder that maps each cell to a high-dimensional vector, the differences between models can be reduced to three things: whether the geometric relationships between cells preserve real biological neighborhood structure; whether the loadings along the gene dimension correspond to pathways and regulatory modules; and whether these structures remain stable across cell types and sequencing depths. Diagnosing these three points is more valuable for engineering than chasing a single score.

    2. Overall Technical Path: A Four-Step Analysis Framework

    A reusable representation-difference analysis pipeline typically has four decoupled and independently replaceable stages:

    1. Representation extraction: fix the model and data, then export cell embeddings and gene embeddings;
    2. Structural measurement: quantify geometric structure with metrics such as neighborhood consistency, clustering alignment, and batch separability;
    3. Probe validation: test whether semantics are linearly readable using linear probes and retrieval tasks;
    4. Attribution and visualization: locate the sources of differences and produce an interpretable report.

    The key engineering constraint is controlling variables: data preprocessing, normalization, feature selection, and random seeds must be identical. Otherwise, the pipeline differences rather than the model differences are being measured.

    1. # Example: a unified entry point for embedding extraction that abstracts away model implementation differences
    2. def extract_embeddings(model, adata, layer="counts"):
    3. X = normalize(adata, layer=layer) # unified normalization
    4. cell_emb = model.encode_cells(X) # cell-level embeddings [N, D]
    5. gene_emb = model.encode_genes(X) # gene-level embeddings [G, D]
    6. return cell_emb, gene_emb

    3. Representation Extraction: Turning the Model Internals into Computable Matrices

    The most common mistake at the extraction stage is inconsistent preprocessing. A recommended setup is to keep one copy of the raw counts and one copy with library-size normalization plus log transformation, then run both in parallel to test the model’s sensitivity to the input distribution. On the output side, retain at least two objects: the cell embedding matrix and the gene embedding matrix. Also record which model layer was used, because shallow layers lean toward input statistics while deeper layers lean toward task semantics, and the layer-to-layer difference is itself an important finding.

    Operationally, extraction should be built as a batch job. Write embedding results to object storage and record metadata (model identifier, layer, data version, parameters) in a structured table to enable reproducible experiments and cross-model comparison.

    4. Structural Measurement: Four Metrics for the Cell World

    • Neighborhood consistency: using a high-confidence reference clustering as the baseline, compute the overlap between nearest neighbors in the embedding space and reference neighbors;
    • Clustering alignment: use mutual information or the adjusted Rand index to measure agreement between unsupervised clusters and known labels;
    • Batch separability: train a lightweight classifier to distinguish batches; accuracy close to random indicates that batch effects have been effectively canceled;
    • Trajectory fidelity: sample along an inferred differentiation trajectory and check whether the interpolated path in the embedding is monotonic and smooth.

    Together, these metrics answer one question: has the model learned biological signal or technical noise introduced by sequencing?

    5. Probes and Retrieval: Testing Whether Semantics Are Linearly Readable

    A linear probe is the most economical semantic test: freeze the embeddings and train only a linear classifier or regression head, avoiding a nonlinear head that could “fill in” information and inflate the estimate.

    1. # Example: frozen representation + linear probe
    2. probe = LogisticRegression(max_iter=2000)
    3. probe.fit(cell_emb[train_idx], labels[train_idx])
    4. score = probe.score(cell_emb[test_idx], labels[test_idx])

    Retrieval-based evaluation is closer to real usage: given a query cell, check whether its neighbors share the same type; given a gene, check whether its neighbors fall in the same pathway. If a model is strong at cell retrieval but weak at gene retrieval, it usually means its pretraining objective favors sample-level contrast while weakening gene semantics.

    6. Attribution: From “Which Is Better” to “Where It Is Better”

    Attribution should be decomposed at three levels: within-layer differences (metric gaps between models at the same layer), cross-layer differences (transfer ability across depths within one model), and dimension differences (whether a few principal components dominate similarity). If differences concentrate in very few dimensions, the representation has redundant compression and is prone to overfitting during fine-tuning; if differences are dispersed and stable, the representation is more likely to transfer well. The final output is a comparison table that places metrics, probe scores, and biological interpretation side by side, giving model-selection discussions a shared language.

    7. Engineering Implementation and Cloud Recommendations

    The full pipeline can be carried by a common combination: a container platform for batch jobs, object storage for embeddings, a message queue for task orchestration, and logging and monitoring with alerts to track failed jobs. If using relevant general capabilities from Baidu AI Cloud, keep the same layered decoupling and avoid coupling evaluation logic with storage and scheduling details. Evaluation results should be version-controlled, and any change to the model or data should trigger a regression run to prevent silent drift.

    8. Common Pitfalls

    The first is comparing only total scores without looking at structure; the second is inconsistent preprocessing that makes conclusions irreproducible; the third is using a high-capacity probe to mask representation flaws; the fourth is ignoring technical confounders such as sequencing depth and batch; the fifth is treating a single experiment’s conclusion as a universal rule. The way to avoid these is to write controlled variables, confidence-interval reporting, and cross-dataset verification into the process specification, so that representation-difference analysis becomes a continuously running diagnostic capability rather than a one-off script.