Manuscript Offprint
arXiv:2610.28339HistoLoop: Iterative Contextual Inference with a Looped Transformer for Histology-Based Spatial Gene Expression Prediction
Abstract
Predicting spatial gene expression from H&E images offers a scalable complement to experimental spatial transcriptomics. However, despite progress in spatial context modeling, how to construct subsequent context from spot states updated by earlier contextual interactions remains underexplored. We introduce HistoLoop, a looped Transformer that formulates prediction as iterative contextual inference. At each refinement step, HistoLoop aggregates the current spot states into context tokens at the corresponding resolution, processes them with a shared spatial Transformer, and retrieves spot-specific contextual information through cross-attention. A memory-mediated update integrates this information into persistent spot states, which are then used to construct context at the next, finer resolution. Under the HEST-Bench HVG50 evaluation protocol, HistoLoop achieves the highest macro-averaged gene-wise Pearson correlation among the compared methods across six cancer-specific tasks spanning five organs in HEST-1K. Ablation studies support the importance of recurrent state refinement and reconstructing context from updated spot states at progressively finer resolutions. Expression-derived clustering further suggests that HistoLoop better captures spatially organized multigene patterns.
Introduction
Spatial transcriptomics (ST) profiles gene expression while preserving its spatial organization within tissue, enabling the characterization of spatial heterogeneity, tissue microenvironments, and cell–cell interactions (Stahl et al. 2016; Longo et al. 2021; Cang et al. 2023). However, current ST technologies remain costly and experimentally demanding, which limits their routine application to large cohorts and archival tissue collections (Moses and Pachter 2022). In contrast, hematoxylin and eosin (H&E)-stained whole-slide images are routinely acquired in clinical pathology and contain rich morphological signals associated with underlying molecular states (Schmauch et al. 2020). These complementary properties have motivated histology-based spatial gene expression prediction, which seeks to reconstruct spatially resolved transcriptomic profiles directly from standard H&E images (Zeng et al. 2022; Xie et al. 2023; Chung et al. 2024).
However, the mapping from local histological morphology to molecular state is inherently context dependent. Morphologically similar tissue regions may occur in distinct anatomical or pathological environments and exhibit different transcriptional programs, such that local appearance alone may provide an ambiguous basis for molecular prediction. Spatial context can help reduce this ambiguity by relating local morphology to its surrounding tissue organization. This motivates studying both the spatial evidence available to a predictor and how that evidence is incorporated into spot representations.
Recent methods have increasingly moved beyond isolated patch-level prediction by incorporating spatial relationships and broader tissue context. Hist2ST models both global and neighboring spatial dependencies through Transformer- and graph-based modules (Zeng et al. 2022), while TRIPLEX integrates target, neighborhood, and global tissue information across multiple resolutions (Chung et al. 2024). More recent hierarchical architectures further propagate information across spatial scales to enrich local representations (Wu et al. 2026). Together, these methods establish the importance of nonlocal context for histology-based spatial gene expression prediction. Building on these advances, we ask whether prediction benefits from coupling spot-state refinement with spatial context reconstruction. Specifically, updated spot representations can be reused to construct context at subsequent resolutions, allowing previously incorporated spatial evidence to influence later contextual messages. We investigate whether this recurrent coupling provides benefits beyond access to multiple spatial scales alone.
To investigate this question, we propose HistoLoop, a looped Transformer framework for iterative contextual inference. Starting from spot-level histological features and spatial coordinates, HistoLoop maintains a persistent representation for each spot. At each iteration, it constructs scale-specific context from the current spot states and processes this context with a shared spatial Transformer core. Spot-conditioned cross-attention retrieves the resulting contextual information, which is integrated into the persistent spot states through a memory-mediated update. These updated states provide the input for context construction at the next iteration, following a coarse-to-fine resolution schedule.
We evaluate HistoLoop on six cancer-specific tasks spanning five organs in HEST-1k (Jaume et al. 2024) under a
Corresponding author: Qinglin Wang (wangqinglin@nudt.edu.cn).
unified five-seed protocol. On the predefined 50-gene HEST-Bench subset, HistoLoop achieves a macro-averaged gene-wise Pearson correlation coefficient (PCC) of 0.480, compared with 0.435 for MoLF (Hu and Speidel 2026), the strongest evaluated baseline under the same protocol. Controlled ablations highlight the contributions of recurrent refinement, coarse-to-fine ordering, and state-dependent context reconstruction.
Our main contributions are summarized as follows:
• We introduce an iterative contextual inference perspective for histology-based spatial gene expression prediction, in which spot representations are recurrently refined and used to reconstruct spatial context for subsequent updates.
• We propose HistoLoop, a multi-resolution looped Transformer that couples spot-conditioned context retrieval with memory-mediated state updates under a coarse-to-fine refinement schedule.
• We evaluate HistoLoop on six cancer-specific tasks spanning five organs and conduct controlled ablations to examine the contributions of recurrent refinement, scale ordering, and state-dependent context reconstruction.
Histology-Based Spatial Gene Expression Prediction
Histology-based spatial gene expression prediction learns molecular profiles from paired histology and spatial transcriptomics data. ST-Net (He et al. 2020) established an early image-based prediction framework, while BLEEP (Xie et al. 2023) and mclSTExp (Min et al. 2024) explored cross-modal alignment for expression prediction. DKAN (Zhang et al. 2026) incorporates gene semantic knowledge into this alignment, and AGL (Shiku et al. 2026) exploits auxiliary genes to improve target-gene estimation. Generative approaches provide another direction: Stem (Zhu et al. 2025) uses conditional diffusion, STFlow (Huang et al. 2025a) models whole-slide expression through flow matching, and FLAG (Si et al. 2026) combines latent diffusion with spatial graph encoding and gene foundation model alignment. MoLF (Hu and Speidel 2026) further addresses pan-cancer heterogeneity through a mixture-of-experts latent flow. Broader efforts include HistoPrism (Hu et al. 2026), which emphasizes pan-cancer prediction and pathway-level evaluation, and STPath (Huang et al. 2025b), which learns transferable expression prediction through large-scale paired pretraining. These studies advance prediction objectives, biological supervision, and transfer; HistoLoop focuses on how spatial context is constructed from evolving tissue representations.
Spatial Context Modeling and Multi-Scale Refinement
Spatial modeling connects local morphology to broader tissue organization. Hist2ST (Zeng et al. 2022) combines global attention with graph-based neighborhood interactions, while TRIPLEX (Chung et al. 2024) integrates target, neighborhood, and global features. HiST (Wu et al. 2026) propagates information through a sparse hierarchical encoder–decoder with spatial coarsening, recovery, and skip connections. Spatial dependencies also enter generative models through local spatial attention in STFlow (Huang et al. 2025a) and graph encoding in FLAG (Si et al. 2026). These approaches offer different mechanisms for selecting spatial evidence and propagating it across locations and resolutions. Building on these advances, we investigate whether coupling persistent spot-state refinement with context reconstruction provides benefits beyond access to multiple spatial scales alone.
HistoLoop maintains persistent spot states and reconstructs context at subsequent resolutions from the states updated by earlier contextual interactions. This recurrent coupling allows previously incorporated spatial evidence to influence the construction of subsequent contextual messages.
Pathology Foundation Models
Pathology foundation models learn transferable representations from large-scale histology data. UNI (Chen et al. 2024) provides general-purpose patch-level features, while GigaPath (Xu et al. 2024) combines patch-level pretraining with whole-slide representation learning. Language supervision further enriches these representations: CONCH (Lu et al. 2024) learns from histopathology image-caption pairs, and TITAN (Ding et al. 2025) combines visual self-supervision with region-level caption and slide-level report alignment. HEST-Bench (Jaume et al. 2024) evaluates pretrained pathology representations through spatial gene expression prediction, connecting foundation model development to this task. Foundation models provide powerful histological representations, but they primarily define how visual features are encoded rather than how spatial evidence should be progressively interpreted during prediction. HistoLoop builds on pretrained histological features and investigates this downstream inference process through recurrent spot-state refinement, complementing advances in pathology representation learning.
Method
Overview
Given pretrained histological features and their spatial coordinates , HistoLoop predicts the spatial gene expression matrix . As illustrated in Fig. 1(a), HistoLoop consists of an input encoding stage, a recurrent multi-resolution spatial loop, and an output prediction stage.
In the input encoding stage, we fuse histological features with positional information and apply a full-resolution pre-spatial Transformer to obtain contextualized spot representations . Following MeSH (Yu et al. 2026), we initialize a persistent state and an S-slot memory buffer for each spot. The memory-mediated transition integrates retrieved spatial evidence into the persistent states through a write-read operation, enabling the states to evolve across refinement steps. Details of the initialization and memory operations are provided in the subsequent sections and appendix.
The recurrent core performs T refinement steps according to a coarse-to-fine context-token ratio schedule. At step t, the
(a) HistoLoop overview

(b) One spatial refinement step

N: spots : hidden dimension : genes
Figure 1: Overview of HistoLoop. (a) HistoLoop fuses pretrained histological features and 2D spatial coordinates, applies a full-resolution pre-spatial Transformer, initializes persistent spot states, performs T recurrent refinement steps following a coarse-to-fine context-token ratio schedule, and predicts gene expression after a full-resolution post-spatial Transformer. (b) At refinement step t, the current spot states are aggregated into context tokens , which are processed by a shared spatial Transformer to obtain contextualized representations . Spot-conditioned cross-attention then retrieves contextual information from for individual spots, yielding contextual updates . A MeSH-based write-read transition produces the next states , which are used for subsequent context construction.
current spot states are grouped into spatial cells, where state-dependent weights aggregate spot representations and their normalized coordinates to produce context tokens and weighted coordinates . A local spatial graph is constructed over the context coordinates, and a shared spatial Transformer produces contextualized representations . Spot-conditioned cross-attention then retrieves relevant spatial evidence for each spot, yielding an update . The MeSH write-read operation integrates this update into the persistent states and memory buffers, producing and .
The operations within one refinement step can be summarized as
(1)
where denotes the normalized spatial coordinates of the original spots, denotes the local spatial graph constructed over the context tokens, denotes the shared spatial Transformer, denotes spot-conditioned context retrieval, and denotes the memory-mediated state transition. The spatial Transformer and retrieval module share their parameters across refinement steps, whereas the resolution embeddings and MeSH routers are step-specific.
Crucially, although grid assignments are determined by spatial coordinates and the prescribed resolution, the aggregation weights depend on the current spot states. Consequently, the context features and weighted coordinates evolve with the states, affecting both spatial contextualization and subsequent context retrieval. After each update, the next context is reconstructed from the updated spot states, allowing spatial evidence incorporated at earlier resolutions to influence subsequent contextual inference. After T refinement steps, a full-resolution post-spatial Transformer and an expression prediction head produce the final prediction .
Spot Encoding and Persistent State Initialization
As shown in Fig. 1(a), HistoLoop first converts pre-trained histological features and spatial coordinates into full-resolution spot representations before entering the recurrent multi-resolution loop. Let denote the normalized spot coordinates. We fuse the visual and positional information as
(2) where E denotes the initial spot embeddings and is a full-resolution pre-spatial Transformer that produces locally contextualized spot representations. The pre-spatial Transformer has independent parameters from the spatial Transformer used in the recurrent loop. Details of coordinate normalization and positional encoding are provided in the appendix.
Following MeSH (Yu et al. 2026), each spot is equipped with an S-slot memory buffer and step-specific write-read routers. The initial recurrent states and memory buffers are obtained as
where denotes the initial recurrent spot states and denotes the associated memory buffers. Specifically, the initialization operation uses the input embeddings to construct the base memory, writes the pre-spatial representations into its slots, and reads from the updated memory to obtain the initial states. The slot-wise initialization and router equations are given in the appendix.
Recurrent Multi-Resolution Spatial Contextualization
State-dependent context construction. At refinement step t, let
denote the current spot-state matrix, where is the state of spot . The initial states are obtained from the MeSH-based initialization, while subsequent states are produced by the recurrent state updates.
We construct spatial context tokens according to a coarse-to-fine schedule of target context-token ratios , where specifies the target number of context tokens relative to the original number of spots . At step , an aspect-ratio-aware grid is constructed over the normalized spatial bounding box to target cells. Each spot is assigned to a grid cell according to its coordinates, and empty cells are discarded. Let denote the set of spots assigned to the -th occupied cell, and let denote the resulting number of occupied cells and context tokens.
Within each occupied cell, a shared scoring function assigns importance weights to the current spot states. The weights are normalized over the spots within the same cell and used to aggregate both spot states and spatial coordinates:
(4)
Here, is a step-specific resolution embedding associated with the ratio , and the Softmax operation is applied independently within each occupied cell. The resulting context tokens and their weighted coordinates are collected as
The grid assignments depend only on the spatial coordinates and the prescribed ratio , whereas the aggregation weights depend on the evolving states . Consequently, both the context features and their weighted coordinates depend on the current spot states. After each state update, context is reconstructed from the updated states at the next ratio in the coarse-to-fine schedule. Unless otherwise stated, we use and in the main experiments.
Spatial contextualization. At refinement step t, we construct a -nearest-neighbor graph over the context coordinates and apply local self-attention to model interactions between neighboring context tokens. The contextualized representations are computed as
where denotes a coordinate-aware spatial Transformer with learned relative-position biases.
The parameters are shared across all refinement steps, while the context tokens, weighted coordinates, and local graph are reconstructed from the current spot states at each prescribed coarsening level. Therefore, the Transformer operates on state-dependent spatial inputs even though its parameters remain fixed throughout the recurrent loop. The resulting representations are passed to the spot-conditioned retrieval module. Further attention details are provided in the appendix.
Spot-conditioned context retrieval. The contextualized tokens provide regional spatial representations that must be mapped back to individual spots before the recurrent state transition. For each spot , we select the nearest context tokens according to the Euclidean distance between its normalized coordinate and the weighted context coordinates . Let denote this candidate set.
We use the current spot state as the query and the contextualized tokens as keys and values. A local coordinate-aware cross-attention operator then produces the spot-wise contextual update:
where denotes the -th contextualized token and denotes multi-head cross-attention with a learned relative-position bias, normalized over the candidate set . Stacking the updates over all spots gives .
Because the query is computed from the current state , each spot retrieves contextual evidence according to its evolving representation. In contrast, the candidate set is determined by spatial proximity, which preserves local spatial connectivity. The retrieved update is not directly added to the current state; it is passed to the MeSH write–read transition to produce and . Further attention details are provided in the appendix.
Persistent State Transition
At refinement step t, the spot-conditioned retrieval module produces a contextual update for the current spot states . HistoLoop integrates this retrieved spatial evidence into persistent spot states and their associated memory buffers through the MeSH write-read operator (Yu et al. 2026):
For each spot, the operator maintains an S-slot memory buffer. Specifically, let denote the collection of memory slots, where . Step-specific write and read routers are computed from the current spot state. The retrieved update is first written into the memory slots according to the write distribution, after which the next spot state is read from the updated memory using the read distribution. Both routing distributions are evaluated from the pre-update state, while the read operation is applied to the post-write memory. The complete slot-wise update equations are provided in the appendix.
The memory is maintained independently for each spot and persists across refinement steps within a forward pass. Cross-spot information exchange occurs through state-dependent context construction, spatial contextualization, and spot-conditioned retrieval. The updated states are then used to reconstruct context at the next prescribed coarsening level, while is retained for the subsequent state transition.
Expression Prediction and Training Objective
After T refinement steps, HistoLoop applies a full-resolution post-spatial Transformer to the final spot states and predicts the expression profile of each spot:
where and . The post-spatial Transformer is applied once after the recurrent loop and provides a final full-resolution spatial refinement before prediction. Its parameters are independent of those of the spatial Transformer in the recurrent loop. The prediction head maps the final spot representations to -dimensional gene expression vectors, yielding the prediction matrix .
Let denote the set of valid spot–gene pairs with observed, finite targets. We train HistoLoop using the standard mean squared error over these pairs:
Entries unavailable for a tissue section are excluded from rather than treated as zero-expression targets. All trainable components are optimized jointly, while the pretrained histological features remain fixed.
Experiments
Experimental Setup
We evaluate HistoLoop on HEST-1K (Jaume et al. 2024), covering six cancer types. We construct two data splits while retaining the original hold-out test sets from HEST-Bench, and stratify the remaining samples by cancer type into training and validation sets. For each spot, the model takes a precomputed histology feature extracted by UNI (Chen et al. 2024) from the corresponding H&E image together with its two-dimensional spatial coordinate, and predicts a gene expression profile over a fixed vocabulary of 38,982 genes.
We compare HistoLoop with four recent methods: HiST (Wu et al. 2026), HistoPrism (Hu et al. 2026), MoLF (Hu and Speidel 2026), and STFlow (Huang et al. 2025a). All methods are evaluated using the same UNI features, spatial coordinates, fixed 38,982-gene vocabulary, and data partitions. For each baseline, we follow its official training configuration while keeping the input data and evaluation protocol consistent across methods. For the primary evaluation, we follow the HVG50 protocol of HEST-Bench (Jaume et al. 2024), using the corresponding predefined panel of 50 highly variable genes (HVG50) for each cancer type. The panel membership is fixed independently of the held-out test data and remains unchanged across splits and methods. For each run, we compute the gene-wise Pearson correlation coefficient (PCC) across valid spots for every benchmark gene on each held-out slide, average the resulting values over the benchmark genes and held-out slides to obtain a cancer-level score, and report the mean and standard deviation across five random seeds. The macro average is calculated as the unweighted mean of the six cancer-level mean PCCs.
For all experiments, HistoLoop uses a hidden dimension of 2048 and performs 4 recurrent refinement steps with context-token ratios of . The pre-spatial, recurrent regional, and post-spatial Transformer stages each contain 3 blocks with 8 attention heads. We train the model end-to-end with the mean squared error over valid spot–gene pairs, using AdamW with a learning rate of and a weight decay of 0.05 for up to 500 epochs.
Main Results
Table 1 summarizes the performance of all methods on the six cancer-specific tasks. HistoLoop achieves the highest macro-averaged HVG50 PCC of 0.480, outperforming the strongest baseline, MoLF, by 0.045 absolute PCC points. It obtains the best mean PCC on four of the six cancer types, indicating that the overall improvement is not driven by a single task. These results establish the effectiveness of HistoLoop under the two-split evaluation protocol.
The gains vary across cancer types. The largest improvements are observed on PAAD and IDC, where HistoLoop exceeds the strongest competing method by 0.074 and 0.044 PCC points, respectively. The advantage is smaller on READ, where HistoLoop and HistoPrism obtain nearly identical performance, while MoLF remains stronger on LUNG and marginally outperforms HistoLoop on SKCM. Thus, the main results support a consistent overall advantage across the evaluated tasks, rather than uniform superiority on every cancer type.
Ablation Study
We conduct controlled ablations to examine the contribution of the recurrent loop, the multi-resolution schedule, and the
Table 1: Comparison of HVG50 PCC on the six cancer-specific tasks. Each cancer-specific entry reports the mean over five random seeds, with the standard deviation shown as a lower-right subscript. Macro Avg. is the unweighted mean of the six cancer-specific mean PCCs. The best mean in each row is shown in bold.
| Cancer Type | HiST | HistoPrism | MoLF | STFlow | HistoLoop |
|---|---|---|---|---|---|
| COAD | |||||
| IDC | |||||
| LUNG | |||||
| PAAD | |||||
| READ | |||||
| SKCM | |||||
| Macro Avg. | 0.346 | 0.310 | 0.435 | 0.405 | 0.480 |
Table 2: Ablation study of HistoLoop on the six cancer-specific tasks. Each cancer-specific entry reports the mean HVG50 PCC over five random seeds, with the standard deviation shown as a lower-right subscript. Parameter counts are reported in millions. Macro Avg. is the unweighted mean of the six cancer-specific mean PCCs. The best mean in each cancer column is shown in bold.
| Variant | Params | COAD | IDC | LUNG | PAAD | READ | SKCM | Macro Avg. |
|---|---|---|---|---|---|---|---|---|
| Full HistoLoop | 674.8 | 0.480 | ||||||
| No loop | 477.6 | 0.381 | ||||||
| No loop, matched | 679.0 | 0.386 | ||||||
| Single scale | 674.8 | 0.457 | ||||||
| Reverse order | 674.8 | 0.463 | ||||||
| Parallel shared | 677.9 | 0.461 | ||||||
| Frozen message input | 674.8 | 0.470 |
state-dependent message pathway. The complete HistoLoop model serves as the reference setting. We first remove the recurrent loop, then construct a parameter-matched variant to distinguish architectural benefits from model capacity. We further replace the coarse-to-fine schedule with a single-scale schedule or reverse the scale order. Finally, we evaluate two variants that prevent the message pathway from using sequentially updated spot states. All variants are evaluated using the same protocol as the main experiments, and the results are summarized in Table 2.
Removing the loop decreases the macro-averaged PCC from 0.480 to 0.381. The parameter-matched variant remains at 0.386, despite using slightly more parameters than the complete model. This comparison indicates that the improvement is not explained by parameter count or by replacing the loop with additional full-resolution Transformer blocks. Replacing the coarse-to-fine schedule with a single scale reduces the score to 0.457, while reversing the scale order gives 0.463. These results support both the use of multiple resolutions and the prescribed coarse-to-fine ordering.
The state-dependent message pathway provides a further contribution. The parallel-shared variant, which constructs messages from the same initial state at all scales, obtains 0.461, while the frozen-message variant obtains 0.470. Both are below the complete model, supporting the need for sequential state updates and for reconstructing messages from evolving spot representations. The frozen-message variant performs slightly better on PAAD, but its lower macro average indicates that this gain does not generalize across the evaluated cancer types. Overall, the ablations support the complete design in which multi-resolution context is processed sequentially and conditioned on updated spot states.
Spatial Expression Recovery
Aggregate PCC provides a useful measure of spot-level expression agreement, but it does not reveal whether a model recovers the spatial organization of gene expression, such as localized high-expression regions, tissue boundaries, and regional intensity variation. We therefore complement the quantitative results with a qualitative visualization of marker genes. Following the biomarker visualization protocol used in DKAN (Zhang et al. 2026), we visualize LCN2, GATA3, GPRC5A, and UBE2C, whose relevance to the corresponding cancer contexts has been documented in prior studies (Feng et al. 2016; Deftereos et al. 2015; Lin et al. 2014; Wang et al. 2019). These genes provide biologically grounded probes for assessing spatial expression recovery.
Figure 2 compares the ground-truth and predicted expression maps on four held-out slides. For each method, we use the same fixed random seed, 42, to obtain a reproducible representative prediction. The seed is fixed uniformly across methods and is not tuned separately according to the marker-

Figure 2: Spatial expression recovery on representative held-out slides.
gene maps. The displayed examples are intended for qualitative inspection, whereas the quantitative claims in this paper are based on the five-seed aggregate results reported in Table 1. The values in parentheses denote the PCC computed for the corresponding slide–gene pair and are included only to provide local quantitative context.
Across the displayed examples, HistoLoop more closely preserves the large-scale localization and regional intensity variation of the ground-truth maps, especially for GATA3, GPRC5A, and UBE2C. It also obtains the highest slide-level PCC in all four shown cases. We do not introduce a separate marker-gene PCC table because the aggregate comparison has already been reported in the main results.
Spatial Structure Preservation
Gene-wise PCC evaluates the agreement of individual genes, but it does not directly measure whether the predicted profiles preserve multigene organization across spatial locations. Since expression-based clustering is commonly used to identify coherent tissue domains (Zhu et al. 2024; Xiao et al. 2025), we further evaluate the consistency of clusters derived from the predicted expression profiles.
For each held-out slide, we independently cluster the ground-truth and predicted expression profiles using the same clustering procedure and hyperparameters for every method. The resulting partitions are compared with the adjusted Rand index (ARI), adjusted mutual information (AMI), normalized mutual information (NMI), and homogeneity.
Table 3 shows that HistoLoop achieves the highest score on all four metrics. Compared with the strongest baseline, HiST, HistoLoop improves ARI from 0.319 to 0.329, AMI from 0.479 to 0.526, NMI from 0.482 to 0.530, and homogeneity from 0.522 to 0.611. The consistent gains across metrics indicate that HistoLoop predictions preserve the multigene partition structure more faithfully than the competing methods under the same clustering protocol. This result complements the gene-wise PCC comparison by testing agreement at the profile and tissue-domain level.
Table 3: Overall clustering consistency between ground-truth and predicted expression profiles.
| Model | ARI↑ | AMI↑ | NMI↑ | Homo.↑ |
|---|---|---|---|---|
| HiST | 0.319 | 0.479 | 0.482 | 0.522 |
| HistoPrism | 0.224 | 0.377 | 0.381 | 0.429 |
| MoLF | 0.276 | 0.433 | 0.436 | 0.468 |
| STFlow | 0.211 | 0.360 | 0.364 | 0.406 |
| HistoLoop | 0.329 | 0.526 | 0.530 | 0.611 |

Figure 3: Expression-derived clustering on two held-out slides.
Figure 3 provides a qualitative view of the partition-level comparison. On both displayed slides, HistoLoop recovers the major regional partitions of the ground-truth expression more coherently, whereas several competing predictions contain more fragmented or spatially mixed assignments. These maps are illustrative of the spatial organization reflected in the all-slide metrics and are not used to select checkpoints or compute the aggregate scores.
Conclusion
We presented HistoLoop, a looped Transformer for histology-based spatial gene expression prediction. HistoLoop progressively reconstructs multi-resolution spatial context from evolving spot states, allowing each refinement stage to use updated spatial evidence rather than relying on a fixed context representation. On HEST-1K, HistoLoop achieves the highest macro-averaged HVG50 PCC among the compared methods and obtains the best mean performance on four of the six cancer-specific tasks. Controlled ablations highlight the contributions of recurrent refinement, coarse-to-fine ordering, and state-dependent context reconstruction. Complementary marker-gene visualizations and expression-derived clustering analyses indicate that the improvement extends beyond isolated gene-wise agreement to the recov-ery of spatially organized multigene patterns.
The current evaluation is conducted within HEST-1K under the predefined HVG50 protocol, while the qualitative analyses cover a limited number of representative held-out slides. Future work will explore improving generalization across datasets for histology-based spatial gene expression prediction.
References
Cang, Z.; Zhao, Y.; Almet, A. A.; Stabell, A.; Ramos, R.; Plikus, M. V.; Atwood, S. X.; and Nie, Q. 2023. Screening cell–cell communication in spatial transcriptomics via collective optimal transport. Nature methods, 20(2): 218–228.
Chen, R. J.; Ding, T.; Lu, M. Y.; Williamson, D. F. K.; Jaume, G.; Song, A. H.; Chen, B.; Zhang, A.; Shao, D.; Shaban, M.; et al. 2024. Towards a general-purpose foundation model for computational pathology. Nat. Med., 30(3): 850–862.
Chung, Y.; Ha, J. H.; Im, K. C.; and Lee, J. S. 2024. Accurate spatial gene expression prediction by integrating multi-resolution features. In 2024 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 11591–11600. IEEE.
Deftereos, G.; Sanguino Ramirez, A. M.; Silverman, J. F.; and Krishnamurti, U. 2015. GATA3 Immunohistochemistry Expression in Histologic Subtypes of Primary Breast Carcinoma and Metastatic Breast Carcinoma Cytology. The American Journal of Surgical Pathology, 39(9): 1282–1289.
Ding, T.; Wagner, S. J.; Song, A. H.; Chen, R. J.; Lu, M. Y.; Zhang, A.; Vaidya, A. J.; Jaume, G.; Shaban, M.; Kim, A.; et al. 2025. A multimodal whole-slide foundation model for pathology. Nat. Med., 31: 3749–3761.
Feng, M.; Feng, J.; Chen, W.; Wang, W.; Wu, X.; Zhang, J.; Xu, F.; and Lai, M. 2016. Lipocalin2 suppresses metastasis of colorectal cancer by attenuating NF- B-dependent activation of snail and epithelial mesenchymal transition. Molecular Cancer, 15(1): 77.
He, B.; Bergensträhle, L.; Stenbeck, L.; Abid, A.; Andersson, A.; Borg, Å.; Maaskola, J.; Lundeberg, J.; and Zou, J. 2020. Integrating spatial gene expression and breast tumour morphology via deep learning. Nature biomedical engineering, 4(8): 827–834.
Hu, S.; and Speidel, S. 2026. MoLF: Mixture-of-Latent-Flow for Pan-Cancer Spatial Gene Expression Prediction from Histology. In Forty-third International Conference on Machine Learning.
Hu, S.; Zeng, Q.; Bhasker, N.; Kather, J. N.; and Speidel, S. 2026. HistoPrism: Unlocking Functional Pathway Analysis from Pan-Cancer Histology via Gene Expression Prediction. In Proceedings of the 14th International Conference on Learning Representations.
Huang, T.; Liu, T.; Babadi, M.; Jin, W.; and Ying, Z. 2025a. Scalable Generation of Spatial Transcriptomics from Histology Images via Whole-Slide Flow Matching. In Proceedings of the 42nd International Conference on Machine Learning, volume 267 of Proceedings of Machine Learning Research, 25550–25565. PMLR.
Huang, T.; Liu, T.; Babadi, M.; Ying, R.; and Jin, W. 2025b. STPath: a generative foundation model for integrating spatial transcriptomics and whole-slide images. NPJ Digital Medicine, 8(1): 659.
Jaume, G.; Doucet, P.; Song, A. H.; Lu, M. Y.; Almagro-Pérez, C.; Wagner, S. J.; Vaidya, A. J.; Chen, R. J.; Williamson, D. F. K.; Kim, A.; and Mahmood, F. 2024. HEST-1k: A Dataset For Spatial Transcriptomics and Histology Image Analysis. In Advances in Neural Information Processing Systems, volume 37, 53798–53833. Curran Associates, Inc.
Lin, X.; Zhong, S.; Ye, X.; Liao, Y.; Yao, F.; Yang, X.; Sun, B.; Zhang, J.; Li, Q.; Gao, Y.; Wang, Y.; Liu, J.; Han, B.; Chin, Y. E.; Zhou, B. P.; and Deng, J. 2014. EGFR phosphorylates and inhibits lung tumor suppressor GPRC5A in lung cancer. Molecular Cancer, 13: 233.
Longo, S. K.; Guo, M. G.; Ji, A. L.; and Khavari, P. A. 2021. Integrating single-cell and spatial transcriptomics to elucidate intercellular tissue dynamics. Nature Reviews Genetics, 22(10): 627–644.
Lu, M. Y.; Chen, B.; Williamson, D. F. K.; Chen, R. J.; Liang, I.; Ding, T.; Jaume, G.; Odintsov, I.; Le, L. P.; Gerber, G.; et al. 2024. A visual-language foundation model for computational pathology. Nat. Med., 30(3): 863–874.
Min, W.; Shi, Z.; Zhang, J.; Wan, J.; and Wang, C. 2024. Multimodal contrastive learning for spatial gene expression prediction using histology images. Briefings in Bioinformatics, 25(6): bbae551.
Moses, L.; and Pachter, L. 2022. Museum of spatial transcriptomics. Nature methods, 19(5): 534–546.
Schmauch, B.; Romagnoni, A.; Pronier, E.; Saillard, C.; Maillé, P.; Calderaro, J.; Kamoun, A.; Sefta, M.; Toldo, S.; Zaslavskiy, M.; et al. 2020. A deep learning model to predict RNA-Seq expression of tumours from whole slide images. Nature communications, 11(1): 3877.
Shiku, K.; Nishimura, K.; Matsuo, S.; Kojima, Y.; and Bise, R. 2026. Auxiliary Gene Learning: Spatial Gene Expression Estimation by Auxiliary Gene Selection. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 40, 9015–9023.
Si, Q.; Wang, P.; Wu, Y.; Jiao, Y.; Liu, X.; Guo, X.; Qi, Y.; and Cheng, Y. 2026. FLAG: Foundation model representation with Latent diffusion Alignment via Graph for spatial gene expression prediction. In Forty-third International Conference on Machine Learning.
Stahl, P. L.; Salmén, F.; Vickovic, S.; Lundmark, A.; Navarro, J. F.; Magnusson, J.; Giacomello, S.; Asp, M.; Westholm, J. O.; Huss, M.; et al. 2016. Visualization and analysis of gene expression in tissue sections by spatial transcriptomics. Science, 353(6294): 78–82.
Wang, X.; Yin, L.; Yang, L.; Zheng, Y.; Liu, S.; Yang, J.; Cui, H.; and Wang, H. 2019. Silencing ubiquitin-conjugating enzyme 2C inhibits proliferation and epithelial–mesenchymal transition in pancreatic ductal adenocarcinoma. The FEBS Journal, 286(24): 4889–4909.
Wu, W.; Xu, X.; Diao, X.; Li, S.; Wei, Z.; Andersson, A.; and Gui, J. 2026. HiST: A Hierarchical Sparse Transformer for
Cross-Modal Spatial Transcriptomics Modeling. In Forty-third International Conference on Machine Learning.
Xiao, Y.; Zhu, Y.; Tang, C.; Zheng, X.; Liu, Y.; Sun, K.; and Liu, X. 2025. Spatially resolved transcriptomics data clustering with tailored spatial-scale modulation. In Proceedings of the Thirty-Fourth International Joint Conference on Artificial Intelligence, 6669–6677.
Xie, R.; Pang, K.; Chung, S.; Perciani, C.; MacParland, S.; Wang, B.; and Bader, G. 2023. Spatially Resolved Gene Expression Prediction from Histology Images via Bi-modal Contrastive Learning. In Advances in Neural Information Processing Systems, volume 36, 70626–70637. Curran Associates, Inc.
Xu, H.; Usuyama, N.; Bagga, J.; Zhang, S.; Rao, R.; Naumann, T.; Wong, C.; Gero, Z.; González, J.; Gu, Y.; et al. 2024. A whole-slide foundation model for digital pathology from real-world data. Nature, 630(8015): 181–188.
Yu, C.; Shu, X.; Wang, Y.; Zhang, Y.; Wu, H.; Li, J.; Long, R.; Chen, Z.; Xu, Y.; Su, W.; and Zheng, B. 2026. MeSH: Memory-as-State-Highways for Recursive Transformers. In The Fourteenth International Conference on Learning Representations.
Zeng, Y.; Wei, Z.; Yu, W.; Yin, R.; Yuan, Y.; Li, B.; Tang, Z.; Lu, Y.; and Yang, Y. 2022. Spatial transcriptomics prediction from histology jointly through transformer and graph neural networks. Briefings in Bioinformatics, 23(5): bbac297.
Zhang, W.; Chu, J.; Liu, X.; Tong, C.; and Li, X. 2026. Dual-path knowledge-augmented contrastive alignment network for spatially resolved transcriptomics. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 40, 12807–12815.
Zhu, S.; Zhu, Y.; Tao, M.; and Qiu, P. 2025. Diffusion generative modeling for spatially resolved gene expression inference from histology images. In International Conference on Learning Representations, volume 2025, 19666–19690.
Zhu, Y.; He, X.; Tang, C.; Liu, X.; Liu, Y.; and He, K. 2024. Multi-view adaptive fusion network for spatially resolved transcriptomics data clustering. IEEE Transactions on Knowledge and Data Engineering, 36(12): 8889–8900.
Appendix
A Spot Encoding and Context Construction Coordinate Normalization and Spot Encoding
We normalize spatial coordinates using the tissue bounding box. Let and denote the coordinate-wise minimum and maximum, respectively. The normalized coordinates are computed as
where prevents division by zero.
For each normalized coordinate , we construct Fourier features by concatenating the original coordinates with sinusoidal features at multiple frequencies:
where is the number of Fourier frequency bands, and sine and cosine are applied element-wise. The positional encoding is mapped to the hidden dimension using a two-layer MLP . Histological features are projected as
(A.3)
The fused input embedding matrix is . Input dropout is applied to the fused embedding during training. The resulting embeddings are processed by the pre-spatial Transformer, which operates on a spatial -nearest-neighbor graph constructed from the normalized spot coordinates:
where collects the normalized coordinates of all spots, and denotes the i-th row of .
Multi-Resolution Context Construction
HistoLoop uses the coarse-to-fine target context-token ratios
defined relative to the original number of spots N. At refinement step t, the target number of grid cells is . An aspect-ratio-aware grid is constructed over the normalized tissue bounding box, and each spot is assigned to a grid cell according to its coordinates. Empty cells are discarded, so the actual number of occupied cells, denoted by , need not equal the target number exactly.
Let denote the set of spots assigned to the -th occupied cell. Within each cell, a shared scoring function assigns weights to the current spot states using the step-specific resolution embedding . A softmax over the spots within each cell produces the aggregation weights . These weights are used to aggregate both spot states and normalized coordinates. The resulting context features are augmented with , yielding the context tokens , while their weighted coordinates are collected in .
At a given resolution, grid assignments depend only on the normalized coordinates and the prescribed ratio . In contrast, the aggregation weights depend on the current states and the corresponding resolution embedding. Consequently, the context tokens and their weighted coordinates can change as the spot states evolve, even when the spatial partition remains fixed. After each state update, context is reconstructed from the updated states at the next resolution in the coarse-to-fine schedule.
B Attention Details
Spatial Transformer
The spatial Transformer processes the context tokens using the context coordinates and the graph . Let denote the number of Transformer blocks. We write for the output representation of context token after block , with . The input to block is therefore , and the output of the final block is , corresponding to the -th row of .
For each block and attention head m, queries, keys, and values are obtained through learned linear projections of the block input:
(B.1)
The attention logits incorporate a learned relative-position bias:
(B.2)
where is the attention-head dimension and denotes the set of nearest context tokens to token according to their coordinates in .
The relative-position bias is implemented as a learned affine projection followed by tanh:
The output of each attention head is
The head outputs are concatenated and linearly projected. Standard normalization, residual connections, feed-forward layers, and dropout complete each Transformer block.
The spatial Transformer parameters, including the attention projections and relative-position biases, are shared across refinement steps. The layer index distinguishes parameters belonging to different Transformer blocks, whereas the refinement index t specifies the current input representations and spatial graph. Thus, the same Transformer is applied to the state-dependent context at every refinement step.
Spot-Conditioned Context Retrieval
At refinement step , queries are projected from the current spot states , whereas keys and values are projected from the spatially contextualized context tokens . For each spot , we select the nearest context tokens according to the Euclidean distance between its normalized coordinate and the weighted context coordinates . Let denote this candidate set.
Let denote the number of retrieval attention heads. For head m, the query, key, and value projections are
(B.5)
The attention logits and normalized weights are computed as
(B.6)
where is the retrieval attention-head dimension and is the learned relative-position bias for head m.
The outputs of all heads are concatenated and linearly projected to obtain the spot-wise contextual update:
The retrieval parameters comprise the query, key, value, and output projections, together with the relative-position bias parameters. All these parameters are shared across refinement steps; the index t denotes the current spot states, context representations, coordinates, and attention weights, not step-specific retrieval parameters. The retrieved updates are passed to the MeSH-based memory update described below.
C MeSH Memory Initialization and Update Memory Initialization
Following the existing MeSH mechanism (Yu et al. 2026), each spot maintains an S-slot memory. Let denote the i-th row of the fused input embedding matrix E. The base memory is initialized by placing the input embedding in the first slot and setting the remaining slots to zero:
Initialization-specific affine routers produce write and read distributions over the memory slots:
where each router maps the input embedding to S logits and the softmax is taken over the slot dimension.
The pre-spatial representation is written into the base memory, after which the initial recurrent state is read from the updated memory:
(C.3)
Recurrent Write-Read Update
At refinement step , step-specific affine routers compute the write and read distributions from the current spot state:
(C.4)
Unlike the shared spatial Transformer and retrieval module, these MeSH routers are step-specific. Both routing distributions are computed from the pre-update state. The retrieved contextual evidence is written into each memory slot according to its write weight:
The next recurrent state is then read from the updated memory using the read weights computed from the pre-update state:
The collection of memory slots across all spots is denoted by . Memory is maintained independently for each spot and initialized anew for each forward pass; it is not carried across tissue sections. Cross-spot information exchange occurs through state-dependent context construction, spatial contextualization, and spot-conditioned retrieval.