From Softmax to Score: Transformers Can Effectively Implement In-Context Denoising Steps

Paul Rosu, Lawrence Carin, Xiang ChengNeurIPS 2025

Summary

This paper mathematically proves that Transformers are not just sequence predictors, but powerful meta-learners capable of implementing complex denoising algorithms—like diffusion and manifold learning—directly within their forward pass. By linking attention mechanisms to score-based updates, the authors demonstrate how Transformers can perform "in-context denoising," utilizing a few clean examples to recover data from extreme noise.

Introduction & Motivation

Generative AI is currently dominated by two giants: Diffusion Models (which generate data by reversing noise) and Transformers (which excel at sequence modeling and "in-context learning"). While it is well-established that Transformers can learn to perform algorithms during inference without weight updates, our theoretical understanding of them as denoisers has been limited.

The authors tackle a fundamental question: Can the attention mechanism natively implement the iterative steps of a diffusion model? Specifically, they investigate how Transformers handle noisy or partially observed data in an unsupervised "in-context" setting—where the model must deduce the underlying structure of a dataset (the "manifold") on the fly to clean up a query.

Theoretical Framework & Methodology

The researchers developed a unified theoretical framework demonstrating that standard Transformer layers are algebraically equivalent to specific denoising algorithms. Their approach includes:

  • Theoretical Equivalence: They prove that Softmax attention can implement Laplacian-based manifold denoising and score-based diffusion. Essentially, one layer of a Transformer can represent one discrete step of a denoising differential equation.
  • Learnable Witness Tokens: Recognizing that attending to an entire massive training set is computationally infeasible, they introduce "witnesses"—a small set of learnable tokens that act as a "summary" of the data distribution. This makes the denoising process both efficient and better at generalizing.
  • Anisotropic Diffusion: They generalize the theory to "anisotropic" (direction-dependent) diffusion. By allowing the Query, Key, and Value matrices to be non-identity, the Transformer can learn geometry-aware denoising—for example, cleaning up an image patch-by-patch rather than uniformly.
  • Cross-Attention Construction: They demonstrate how cross-attention allows a "noisy" query to look at "clean" context tokens to guide the denoising process.

Core Insights

  • Attention is a Gradient Flow: The core realization is that the softmax update in a Transformer layer is effectively a step along a probability flow. Each layer pushes the noisy input closer to the "clean" data manifold.
  • The Power of Context: Adding just a few clean, same-class images as "context" in the prompt dramatically improves the model's ability to denoise a query. The Transformer "learns" the class-specific manifold in-context.
  • Generalization vs. Memorization: Interestingly, models using a small set of "witness tokens" outperformed models that had access to the full training set. Full-set models tended to "memorize" and copy training samples, whereas witness models learned a smoother, more generalizable representation of the data.
  • Interpretable Specialization: In anisotropic models, different layers (or heads) specialize in denoising non-overlapping semantic patches. One layer might focus on the top-left of an image, while the next handles the center.

Empirical Findings

The authors validated their theory using standard image benchmarks, including MNIST (28x28 handwritten digits) and CIFAR-10/100 (32x32 color images), evaluating performance via RMSE and FID scores.

Visual progression of denoising across Transformer layers for MNIST and CIFAR-10.
  • Monotonic Improvement: In a 6-layer Transformer, the reconstruction error decreases steadily with each layer, confirming that the model performs iterative denoising. The visual progression clearly shows the image sharpening layer by layer.
  • Contextual Boost: Providing context images reduced the test loss significantly compared to zero-context scenarios, especially when the noise level was high.
  • Anisotropic Advantage: Models that learned direction-dependent (anisotropic) updates consistently achieved lower RMSE and better FID scores than standard isotropic RBF-based models.
  • Efficiency: The "witness" approach allowed the model to approximate the score of a massive dataset using only a few hundred tokens, maintaining high accuracy with much lower computational cost.
Test loss as a function of context size (left) and intermediate layer index (right).

Limitations & Future Directions

  • Scale: The experiments were limited to small-scale image datasets (MNIST/CIFAR). It remains to be seen how these specific constructions behave on high-resolution images or massive language datasets.
  • Architecture Depth: The study focused on relatively shallow (6-layer) Transformers. Real-world LLMs and Diffusion Transformers are much deeper, and the dynamics might shift at that scale.
  • Modality: While the theory is general, the empirical tests were strictly on images. Applying this "in-context denoising" framework to audio or text sequences is a promising next step.

Summary updated

BibTeX
@inproceedings{rosu2025from,
  author = {Paul Rosu and Lawrence Carin and Xiang Cheng},
  title = {{From Softmax to Score: Transformers Can Effectively Implement In-Context Denoising Steps}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=4QRoLzD11x},
}
Figure