[Paper Review] Sinkformers: Transformers with Doubly Stochastic Attention
This paper introduces Sinkformers, a variant of the Transformer that replaces the standard SoftMax normalization in self-attention with Sinkhorn's algorithm to produce doubly stochastic attention matrices. The method improves model performance across vision and NLP tasks, including a significant accuracy gain on 3D shape classification, while also providing theoretical insights into attention as a Wasserstein gradient flow and heat diffusion process in the infinite-sample limit.
Attention based models such as Transformers involve pairwise interactions between data points, modeled with a learnable attention matrix. Importantly, this attention matrix is normalized with the SoftMax operator, which makes it row-wise stochastic. In this paper, we propose instead to use Sinkhorn's algorithm to make attention matrices doubly stochastic. We call the resulting model a Sinkformer. We show that the row-wise stochastic attention matrices in classical Transformers get close to doubly stochastic matrices as the number of epochs increases, justifying the use of Sinkhorn normalization as an informative prior. On the theoretical side, we show that, unlike the SoftMax operation, this normalization makes it possible to understand the iterations of self-attention modules as a discretized gradient-flow for the Wasserstein metric. We also show in the infinite number of samples limit that, when rescaling both attention matrices and depth, Sinkformers operate a heat diffusion. On the experimental side, we show that Sinkformers enhance model accuracy in vision and natural language processing tasks. In particular, on 3D shapes classification, Sinkformers lead to a significant improvement.
Motivation & Objective
- To improve Transformer performance by replacing row-wise stochastic SoftMax with doubly stochastic attention via Sinkhorn's algorithm.
- To provide a theoretical foundation for self-attention mechanisms by interpreting Sinkformers as Wasserstein gradient flows and heat diffusion processes.
- To empirically validate that attention matrices in trained Transformers converge toward doubly stochastic matrices, justifying the use of Sinkhorn normalization as a meaningful inductive bias.
- To demonstrate that Sinkformers achieve superior accuracy compared to standard Transformers across diverse tasks, including 3D shape classification, image classification, and sequence modeling.
- To enable a plug-in replacement of SoftMax with Sinkhorn normalization in existing Transformer architectures with minimal computational overhead.
Proposed method
- Replace the SoftMax operation in self-attention with Sinkhorn's algorithm to normalize the unnormalized attention matrix $ K^0 = \exp(C) $ to be doubly stochastic.
- Use iterative row and column normalization via Sinkhorn's algorithm to converge to a matrix where both rows and columns sum to one.
- Introduce a hyperparameter for the number of Sinkhorn iterations, allowing interpolation between standard Transformers (1 iteration) and fully converged Sinkformers.
- Maintain differentiability and GPU compatibility by implementing Sinkhorn's algorithm in a differentiable, differentiableiable manner within deep learning frameworks.
- Leverage the doubly stochastic property as a prior to encourage more balanced, democratic attention across all tokens.
- Theoretical analysis shows that Sinkformers correspond to a discrete Wasserstein gradient flow in the infinitesimal limit and converge to the heat equation in the mean-field limit.
Experimental results
Research questions
- RQ1Does the attention matrix in trained Transformers naturally converge toward a doubly stochastic matrix during optimization?
- RQ2Can replacing SoftMax with Sinkhorn normalization improve model accuracy across vision and NLP benchmarks?
- RQ3How does the doubly stochastic attention mechanism relate to optimal transport and gradient flows in the continuous limit?
- RQ4What is the theoretical behavior of Sinkformers in the infinite-depth and infinite-sample limits?
- RQ5Can Sinkformers be efficiently implemented in practice with minimal computational overhead compared to standard Transformers?
Key findings
- On the ModelNet40 3D shape classification benchmark, Sinkformers achieve a significant accuracy improvement over standard Transformers, demonstrating strong performance gains in geometric learning tasks.
- On the IWSLT’14 German-to-English translation task, the Sinkformer achieves a median BLEU score of 34.73 after 35 epochs, slightly outperforming the Transformer’s 34.68 under the same training protocol.
- On the IMDb sentiment classification task, Sinkformers show improved performance over standard Transformers, indicating better generalization in sequence modeling.
- In the cats and dogs image classification task with Vision Transformers, the Sinkformer achieves a median test accuracy of 79.5%, compared to 79.0% for the standard Transformer.
- On a one-layer, one-head self-attention model on MNIST, the Sinkformer outperforms the Transformer as patch size decreases, indicating enhanced representational capacity in low-capacity settings.
- The training time per epoch for the Sinkformer is nearly identical to the standard Transformer (3m 25s vs. 3m 20s), confirming minimal computational overhead.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.