AI觉醒星球
Awakening is here
Knowledge File / AI小生意项目库
2026-06-30 0 浏览 会员

DiScoFormer:一个用于密度和分数、跨分布的Transformer

介绍DiScoFormer,一种无需重新训练即可同时估计数据分布密度和分数的Transformer模型,通过注意力机制改进传统方法,并能适应分布外输入。

SOURCE / AI小生意项目库 MIN / 4 ACCESS / 会员 POST / 2026-06-30 02:02:48

原贴

查看原文
作者:Hugging Face Blog 来源站点:huggingface.co 原贴时间:

原文

Many problems in machine learning and the sciences come down to the same task: you have a collection of data points and want to recover the distribution they came from—which values are common, and which are rare. Pinning down that distribution means estimating two quantities: the distribution's density and, more useful as dimensionality grows, its score. The density is the smooth version of a histogram—high where points cluster and low where they're scarce. The score—the gradient of the log-density—points in the direction the density rises fastest: move a point along the score and it heads toward a more probable region. Diffusion-based generative models (the technology behind AI image generators like Stable Diffusion and DALL-E) start from random noise and repeatedly follow the score, turning that noise into a realistic image. The same score drives Bayesian sampling and the particle simulations used to model systems such as plasma. Extracting the density and score from a finite sample is challenging, and today's tools force a trade-off between generalizability and accuracy. One classical approach, kernel density estimation (KDE), computes the density at any location from the data points around it: the closer and more numerous they are, the higher the density. It needs no training and applies to any distribution, but its accuracy falls off sharply as dimensionality grows. Alternatively, neural score-matching models trained to predict the score stay accurate even in high dimensions, but each needs to learn the distribution and must be retrained from scratch for another. We introduce a new solution called the DiScoFormer (Density and Score Transformer) —one model that, given a set of data points, estimates both the density and the score of the distribution in a single forward pass without retraining. DiScoFormer maps an entire sample to the density and score of the distribution behind it using stacked layers of transformer blocks. The model utilizes cross-attention, which allows it to evaluate density and score at any point—not just where you have data. Score and density share a mathematical relationship: score is the gradient of the logarithm of density. We leverage this by having a shared backbone with two output heads, one for the density and one for the score. This coupling does more than save parameters. The score head has to match the gradient of the log-density head at every query, so any gap between them is a label-free consistency loss. We use this at inference—hold the context fixed, take a few gradient steps on that consistency loss, and DiScoFormer adapts itself to an out-of-distribution input on the spot, no ground-truth density or score required. There's a mathematical reason why the transformer architecture fits this task. Kernel density estimation has a single bandwidth—how far each point's influence reaches, fixed in advance and applied identically everywhere. Attention is a strict generalization of it: we analytically show that a single attention head's weights are nearly a Gaussian kernel over the data, so one cross-attention block can already reproduce KDE's density and score. From there the model goes further, learning several such scales at once and adapting them to the data. DiScoFormer doesn't discard the classical method for a black box but instead includes KDE as a special case and improves on it. What data did we use to train DiScoFormer? We relied on Gaussian Mixture Models for two primary reasons. Firstly, GMMs are universal density approximators—with enough components they match essentially any smooth distribution to arbitrarily small error. Secondly, GMMs have closed-form densities and scores, so we always have an exact target to supervise against. We employ both of these properties by drawing a new GMM for every batch, giving the model virtually unlimited examples of target distributions and supervising each against a given GMM's exact density and score. Across the board, DiScoFormer beats

中文翻译

机器学习和科学中的许多问题都归结为同一项任务:你有一组数据点,想要恢复它们所来自的分布——哪些值常见,哪些值罕见。确定该分布意味着估计两个量:分布的密度,以及在维度增加时更有用的分数。密度是直方图的平滑版本——在点聚集的地方高,在点稀少的地方低。分数——对数密度的梯度——指向密度上升最快的方向:沿着分数移动一个点,它会朝向更可能出现的区域。基于扩散的生成模型(如Stable Diffusion和DALL-E等AI图像生成器背后的技术)从随机噪声开始,反复跟随分数,将噪声转化为逼真的图像。同样的分数驱动贝叶斯采样和用于模拟等离子体等系统的粒子模拟。从有限样本中提取密度和分数具有挑战性,当今的工具迫使在泛化性和准确性之间权衡。一种经典方法,核密度估计(KDE),根据周围数据点计算任何位置的密度:数据点越近越多,密度越高。它无需训练,适用于任何分布,但其准确性随维度增加而急剧下降。另一种方法,神经分数匹配模型,训练后即使在维度较高时也能保持准确性,但每个模型都需要学习分布,并且必须从头开始重新训练才能应用于另一个分布。我们提出了一种新解决方案,称为DiScoFormer(密度和分数变换器)——一个模型,给定一组数据点,即可在一次前向传递中估计分布的密度和分数,无需重新训练。DiScoFormer使用堆叠的Transformer块层将整个样本映射到其背后的分布的密度和分数。该模型利用交叉注意力,可以在任何点评估密度和分数——而不仅仅是在有数据的点。分数和密度存在数学关系:分数是密度对数的梯度。我们通过共享骨干网络和两个输出头(一个用于密度,一个用于分数)来利用这一点。这种耦合不仅节省了参数。分数头必须在每个查询处匹配对数密度头的梯度,因此两者之间的任何间隙都是无标签的一致性损失。我们在推理时使用这一点——保持上下文固定,对一致性损失进行几步梯度更新,DiScoFormer就会即时适应分布外的输入,无需真实的密度或分数。Transformer架构适合此任务有一个数学原因。核密度估计只有一个带宽——每个点的影响范围,预先固定并统一应用。注意力是其严格泛化:我们分析表明,单个注意力头的权重几乎就是数据上的高斯核,因此一个交叉注意力块已经可以重现KDE的密度和分数。从那里开始,模型更进一步,同时学习多个这样的尺度并适应数据。DiScoFormer并没有将经典方法丢弃为黑箱,而是将KDE作为特例包含在内并加以改进。我们使用什么数据训练DiScoFormer?我们依赖高斯混合模型(GMM),主要有两个原因。首先,GMM是通用密度逼近器——只要有足够多的分量,它们就能以任意小的误差匹配任何平滑分布。其次,GMM具有封闭形式的密度和分数,因此我们总是有精确的目标进行监督。我们利用这两个特性,为每个批次抽取一个新的GMM,为模型提供几乎无限的目标分布示例,并针对给定GMM的精确密度和分数对每个进行监督。总体而言,DiScoFormer优于

核心信息

介绍DiScoFormer,一种无需重新训练即可同时估计数据分布密度和分数的Transformer模型,通过注意力机制改进传统方法,并能适应分布外输入。

  • 介绍DiScoFormer,一种无需重新训练即可同时估计数据分布密度和分数的Transformer模型,通过注意力机制改进传统方法,并能适应分布外输入。
  • 原贴提到:Many problems in machine learning and the sciences come down to the same
  • 来源:huggingface.co
试看内容

成为会员查看完整内容

你已经看到了这篇内容的前置整理,剩余深度部分仅对会员开放。

详细解读 信息差价值 参考来源
成为会员查看完整内容
上一篇 亚马逊工程师据报正蒸馏Anthropic模型以降低成本,新的代币计价即将生效 下一篇 Claude Opus 4.8(快速模式)现已在 GitHub Copilot 中预览