Skip to content

Transformers as In-Context Samplers: From Closed-Form Diffusion to Estimation-Free Sampling

Sep 2026 · 0 citations · 48 references
Computer Science Mathematics

TL;DR

It is proved that in-context learning extends further to data generation: frozen transformers can simulate iterative generative samplers from in-context samples, and it is proved that transformers can approximate an energy-based sampler.

Abstract

A growing body of work establishes that large language models are not mere statistical memorizers, but are capable of in-context learning: performing inference at test time using only examples provided in the prompt, without any parameter updates. Prior theoretical work has shown that this capability extends to supervised learning tasks such as linear regression. We prove that in-context learning extends further to \emph{data generation}: frozen transformers can simulate iterative generative samplers from in-context samples. We first show that transformers can realize closed-form and smoothed closed-form diffusion samplers. The construction identifies a concrete generative role for softmax attention: it computes responsibility weights and weighted empirical averages, while feedforward layers implement Euler updates. To empirically relate these constructions to pretrained language models, we study \emph{semantic-topic sampling}: prompts consisting of words drawn from a common semantic category, such as animals, foods, or cities. Across transformer layers, the normalized hidden states exhibit a two-stage geometry: they move toward a uniform spherical reference in intermediate layers and then return to structured, topic-dependent representations near the output. We further measure an interacting-particle energy on these hidden-state clouds and observe the same U-shape pattern. We then prove that transformers can approximate an energy-based sampler, constructing the same U-shape energy across the layers.

View source

Similar papers

#machine learning Preprint Oct 2026

Diffusion Transformers are Provably Optimal In-context Generators

Generative foundation models are attracting interest for their ability to produce desired outputs from demonstrations given at inference time, without updating parameters. However, since a few demonstrations cannot uniquely identify the intended task, the challenge is how to learn and sample from an output distribution...

Guoji Fu, Tomoya Wakayama, Ryotaro Kawata et al. · 0 citations
#machine learning Preprint Sep 2026

Transformers as Cross-Task Learners: Shared Structure Drives Sample Efficiency in In-Context Learning

This work characterize task-space complexity through covering numbers under a prescribed metric, thereby quantifying the low-dimensional cross-task structure without requiring an explicit parametric representation and explicitly construct a Transformer that exploits their low-dimensional structure to perform ICL.

Zhong-Jie Shi, Rong-Jie Lai, Alexander Cloninger et al. · 1 citation
#machine learning Preprint Sep 2026

A Comparative Analysis of Attention versus State-Space Models for In-Context Learning

Transformers and state-space models (SSMs) are two prominent sequential learning architectures, yet their comparison remains largely empirical and existing theoretical analyses are typically task-specific or architecturally restricted. In this paper, we develop belief geometry, a unified analytical framework for compar...

Enes Arda, Semih Cayci, Atilla Eryilmaz · 0 citations
#artificial intelligence Preprint Oct 2026

Capturing In-Context Learning Dynamics with Task Operators

In-context learning (ICL) enables language models to perform new tasks from demonstrations without weight updates. However, every ICL inference requires processing the full set of examples, resulting in inefficient deployments, and how ICL works mechanistically is not fully understood. Prior work compresses ICL into fi...

Guang-Zhi Xiong, Zheng-Hao He, Bo-Han Liu et al. · 0 citations
#machine learning Preprint Oct 2026

Learning What to Imitate: Entropy-Aware Distribution Mixing

Small language models are often post-trained as students on reasoning traces from stronger teacher models to efficiently learn new skills. However, token-level imitation on traces that lie far outside the student's expected distribution often produces \textit{confident conflicts}, whereby the student is required to imi...

Juan Garcia Giraldo, Matteo Santelmo, E. Durech et al. · 0 citations
#artificial intelligence Preprint Oct 2026

Learning Style, Forgetting Semantics: A Case Study of SFT and RFT on Classification Tasks

Why does supervised fine-tuning (SFT) lead to more forgetting than reinforcement fine-tuning (RFT), even when all teacher demonstrations are semantically correct? We study this question on classification tasks where tokens within each semantic class express the same semantic answer in different styles. The tasks share...

Hao-Dong Liang, Yan-Hao Jin, K. Balasubramanian et al. · 0 citations

Related blog posts

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.