DiScoFormer estimates density and score with a transformer
DiScoFormer is a transformer that estimates a distribution's density and score from its data without retraining for each case. In tests of up to 100 dimensions, it substantially outperformed KDE, although it still needs to be validated in real-world applications.

DiScoFormer is a new model that takes a dataset and estimates, in one pass, the density and score of the distribution that generated it, without having to retrain for each problem.
Density indicates which values are common and which are rare. It is a continuous version of a histogram: it rises where data is concentrated and falls where data is sparse. The score is the gradient of the logarithm of that density, a signal pointing toward the area where the data is most likely to occur.
This may sound like a mathematical distinction, but it appears in technologies you already use. Diffusion models, such as those that generate images, start with noise and follow the score step by step until they turn it into something realistic. The same calculation is also used to sample hypotheses in Bayesian statistics or simulate physical systems such as plasma.
The problem with current tools
Estimating a distribution from a limited amount of data is not easy, especially when each data point has many dimensions. The two most common options have different advantages.
KDE, or kernel density estimation, calculates density based on the distance and number of nearby points. It requires no training and works with many distributions.- Neural score models usually maintain better accuracy in high-dimensional spaces, but they must learn each distribution separately and be retrained for every new case.
DiScoFormer attempts to combine both advantages. It uses transformer blocks and cross-attention to query the density and score at any point, even if that point is not part of the original data.
The model shares a common backbone and adds two outputs: one for density and one for score. Since both quantities are mathematically connected, the score must match the density gradient. This relationship makes it possible to detect errors without having a correct answer available during use.
Adaptation without labeled data
When it receives a distribution different from those seen during training, DiScoFormer can keep the context data fixed and perform a few adjustment steps to reinforce consistency between its two outputs. It does not need to know the true density or score of that new distribution.
This is a form of adaptation at inference time. In practice, the model can adjust to a new case without starting a complete training process from scratch.
The architecture also has a direct connection to a classical method. The researchers show that the weights of an attention head behave similarly to a Gaussian kernel, the function KDE uses to give more importance to nearby points.
That is why DiScoFormer does not eliminate this method and replace it with a black box. It includes KDE as a special case, but it can learn multiple influence scales and adjust them to the data instead of using a single fixed configuration.
Results in up to 100 dimensions
To train it, the team generated mixtures of Gaussians, known as GMMs. Each mixture defines a distribution with several concentrations of data and makes it possible to calculate both its density and score exactly. A new mixture was created in each training batch, giving the model a wide variety of examples.
According to the tests presented:
- In 100 dimensions, DiScoFormer reduced score error by about 6.5 times compared with the best manually tuned
KDE. - In the same test, it reduced density error by more than 37 times.
- It continued to improve as more samples were added, while
KDEeventually ran out of memory. - It also worked with mixtures that had more modes than those seen during training and with non-Gaussian distributions such as Laplace and Student-t.
KDE retains an important advantage: it is usually faster when datasets are small. In addition, these results come from research and do not automatically make DiScoFormer a tool ready for every application.
The importance of this work is that a single estimator could be reused for content generation, Bayesian inference, and scientific simulation. If it maintains its accuracy beyond the training examples, the next step will be to determine how much of that performance holds up on real problems, with imperfect data and much more complex distributions.