arXiv:2610.23783cond-mat.dis-nnOct 2026

Manuscript Offprint

arXiv:2610.23783

Sampling the XY model with an attention-based neural network

Piotr Białas, Christian D. Morales, Tomasz Stebel, Dawid Zapolski

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We present a transformer-based variational autoregressive network for sampling lattice systems with continuous degrees of freedom and apply it to the two-dimensional XY model near the Berezinskii–Kosterlitz–Thouless transition. The architecture is combined with physics-informed ingredients: locality-informed attention and approximate probabilities. The resulting sampler significantly outperforms existing neural samplers. We train the model on lattices up to 96×9696 \times 96, verify with a mode-dropping estimator that no parts of the configuration space are missed, and reproduce the energy, magnetization and helicity modulus obtained with the traditional Markov Chain Monte Carlo algorithm.

Keywords: Variational Autoregressive Neural Networks, transformers, Spin Systems, Markov Chain Monte Carlo

1. Introduction

Markov Chain Monte Carlo (MCMC) remains the method of choice for computing observables in statistical physics and lattice field theory. Its efficiency, however, is limited by autocorrelations between consecutive configurations, which grow rapidly in the vicinity of phase transitions (critical slowing down). For some systems this problem can be alleviated by cluster algorithms [1, 2], but such algorithms are model-specific and are not available for many systems of interest, e.g., frustrated magnets, spin glasses or gauge theories. In addition, MCMC does not give direct access to the partition function and hence to the free energy and entropy, which require dedicated techniques such as thermodynamic integration or the Wang–Landau algorithm [3].

In recent years, generative neural networks have been proposed as an alternative approach. A neural sampler is a model that provides both independent configurations and the exact, normalized probability qθq_{\theta} with which each of them was generated. The network is trained to approximate the Boltzmann distribution p, typically by minimizing the reverse Kullback–Leibler divergence, which does not require any previously generated training data. Knowledge of qθq_{\theta} allows one to remove the remaining bias between qθq_{\theta} and p, either by Neural Importance Sampling (NIS) or by using the network as an independent proposal in the Metropolis–Hastings algorithm (Neural Markov Chain Monte Carlo, NMCMC) [4]. Both approaches are asymptotically exact, and also give a direct estimate of the free energy. Two families of architectures dominate this field: Variational Autoregressive Networks (VAN) [5], which factorize the probability into a product of conditional distributions of consecutive spins, and normalizing flows (NF) [6], which transform a simple prior distribution by a sequence of invertible maps.

For discrete spin systems, autoregressive networks have advanced considerably. Hierarchical Autoregressive Networks (HAN) [7, 8] and RiGCS [9] exploit the locality of interactions to reduce the number of spins on which each conditional distribution depends, physics-informed approximate probabilities [10, 11] inject an analytical approximation of the conditionals directly into the network, and transformer-based architectures [12, 13, 14] replace convolutional or dense layers with the attention mechanism [15]. Systems with continuous degrees of freedom are usually treated with normalizing flows, but the focus has mostly been on lattice field theories [6, 16, 17, 18, 19, 20].

Email addresses: piotr.bialas@uj.edu.pl (Piotr Białas), m.c.demetrio@student.karazin.ua (Christian D. Morales), tomasz.stebel@uj.edu.pl (Tomasz Stebel), dawid.zapolski@doctoral.uj.edu.pl (Dawid Zapolski)

The two-dimensional XY model is the natural benchmark for samplers of systems with continuous degrees of freedom: it is the simplest model with a continuous O(2)O(2) symmetry, it exhibits the Berezinskii–Kosterlitz–Thouless (BKT) transition [21, 22] driven by the unbinding of vortices, and it shares its compact, U(1)U(1)-valued variables with lattice gauge theories. Existing neural samplers for this model include: Continuous-mixture Autoregressive Networks (CAN) [23], normalizing flows [24], and flows trained with adversarial learning (AdvNF) [25]. As we show in this work, their sampling quality degrades quickly with the system size.

In this paper, we follow an approach similar to CAN and sample the XY model with an autoregressive architecture, spin by spin. The probability distribution is parameterized by a linear combination of simple distributions that are easy to sample from. The parameters of this combination are given by the output of the neural architecture. Two crucial differences between our approach and CAN are: (i) instead of a convolutional network, we use a transformer architecture; and (ii) we use von Mises functions that are more physically justified than the beta distributions used in [23]. We combine this architecture with three physics-motivated ingredients: locality-informed attention [14], which restricts the attention span according to the geometry of the lattice and the Hammersley–Clifford theorem [26]; approximate probabilities [11] in the lowest ( t1t^{1}) order, which for the XY model stay within the von Mises family and can therefore be combined analytically with the network output; and averaging the model probability over a group of lattice symmetries, applied after training.

The paper is organized as follows. In Section 2, we review neural samplers, asymptotically unbiased estimators, and diagnostics of mode collapse, and we describe the XY model and the tVAN architecture together with its physics-informed modifications. Section 3 presents the numerical results: a comparison with other neural samplers, the effect of approximate probabilities and gauge fixing, scaling with the lattice size, physical observables, post-training symmetrization, and tVAN as a normalizing flow prior. We summarize in Section 4. Derivations of the t1t^{1} approximate probabilities, the proof that symmetrization does not decrease the ESS, and a study of hyperparameters are collected in the Appendices.

References (34)