arXiv:2506.19125cs.LGcs.AI2025-06被引 1

Transformer可精确实现k-means聚类算法,还能学习出更优的聚类模型。

Transformer Circuits Can Realize Clustering Algorithms

  • 基于注意力、残差连接等机制,构建可执行Lloyd算法的k-means Transformer
  • 训练后模型聚类质量优于传统Lloyd算法,且具备泛化能力
  • 通过可解释修改,可衍生软k-means等新聚类算法,适合算法研究者

尽管Transformer通常被优化为统计序列模型,但其在实现精确算法计算方面的潜力尚不明确。本文从原理出发,设计了一种Transformer架构,可精确执行广泛使用的k-means聚类基础算法——Lloyd算法。我们理论证明并实证表明,该架构(称作k-means Transformer)利用现代Transformer的标准电路机制(注意力模块、残差连接、前馈块),能精确实现Lloyd算法。在训练实验中,该基础架构在k-means聚类任务上表现出泛化能力,生成的聚类算法在聚类质量上超越了传统Lloyd算法。此外,通过可解释的结构修改(如引入层归一化),可衍生出软k-means、球面k-means、截断k-means等多种新颖聚类算法。结果表明,Transformer电路机制不仅能实现精确算法流程,同时可作为可学习的有效模型。

原文摘要 · Abstract (English)

Although transformers are most commonly optimized as statistical sequence models, it is unclear to what extent they can implement and learn exact algorithmic computations. Here, we specify a transformer implementation from first principles that executes a fundamental and widely used method for $k$-means clustering: Lloyd's algorithm. We theoretically prove and empirically demonstrate that this implementation of a transformer architecture, which we term the $k$-means transformer, exactly implements Lloyd's algorithm for $k$-means clustering using the standard circuit mechanisms of modern transformers: attention block, residual connections, and feed-forward block. In learning experiments, we find that training this base architecture on $k$-means clustering yields a generalizable clustering algorithm that surpasses Lloyd's algorithm in terms of clustering quality. Finally, we demonstrate that interpretable alterations (e.g., inclusion of layer normalizations) to this architecture yields diverse and novel variants of clustering algorithms, including soft $k$-means, spherical $k$-means, trimmed $k$-means. Overall, our results show that transformer circuit mechanisms can instantiate exact algorithmic routines for clustering, while simultaneously providing an effective learnable model.

Transformer聚类算法可学习模型算法实现

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。