When and How Unlabeled Data Provably Improve In-Context Learning

Yingcong Li, Xiangyu Chang, Muti Kara, Xiaofeng Liu, Amit K. Roy-Chowdhury, Samet Oymak · OpenReview

Abstract

Recent research shows that in-context learning (ICL) can be effective even when demonstrations have missing or incorrect labels. To shed light on this capability, we examine a canonical setting where the demonstrations are drawn according to a binary Gaussian mixture model (GMM) and a certain fraction of the demonstrations have missing labels. We provide a comprehensive theoretical study to show that: (1) The loss landscape of one-layer linear attention models recover the optimal fully-supervised estimator but completely fail to exploit unlabeled data; (2) In contrast, multilayer or looped transformers can effectively leverage unlabeled data by implicitly constructing estimators of the form $\sum_{i\ge 0} a_i (X^\top X)^iX^\top y$ with $X$ and $y$ denoting features and partially-observed labels (with missing entries set to zero). We characterize the class of polynomials that can be expressed as a function of depth and draw connections to Expectation Maximization, an iterative pseudo-labeling algorithm commonly used in semi-supervised learning. Importantly, the leading polynomial power is exponential in depth, so mild amount of depth/looping suffices. As an application of theory, we propose looping off-the-shelf tabular foundation models to enhance their semi-supervision capabilities. Extensive evaluations on real-world datasets show that our method significantly improves the semisupervised tabular learning performance over the standard single pass inference.

Introduction

In-context learning (ICL) has revolutionized how we interact with Large Language Models (LLMs), allowing them to perform tasks based on a few labeled demonstrations provided in the prompt. However, high-quality labeled data is often scarce or expensive to obtain. This paper explores Semi-Supervised In-Context Learning (SS-ICL), where the prompt contains both labeled and unlabeled examples. While empirical evidence suggested that models could handle missing or noisy labels, the underlying mechanism was a "black box." We provide a theoretical and empirical foundation for SS-ICL, identifying architectural depth as the critical factor for leveraging unlabeled information.

Theoretical Framework: The Binary GMM Setting

We analyze SS-ICL through the lens of a binary Gaussian Mixture Model (GMM), a canonical setting for classification. In this setting, features are drawn from one of two Gaussian distributions. We consider a prompt containing $n$ samples, where only a fraction $p$ are labeled.

Our analysis reveals a stark contrast between shallow and deep architectures:

  1. Single-Layer Linear Attention: We prove that 1-layer models are "blind" to unlabeled data. While they can recover the optimal supervised "Plug-in" estimator from the labeled portion of the prompt, they cannot extract any additional signal from the unlabeled features.
  2. Multi-Layer Transformers: Depth is the "secret sauce." Deeper models can implement complex polynomial estimators of the feature covariance matrix ($X^\top X$). Specifically, an $L$-layer model can represent polynomials of degree $O(3^L)$. This allows the model to "look back" at the specific distribution of the current prompt and refine its task estimate.

Depth as Implicit Expectation-Maximization

A key insight of our work is the connection between Transformer depth and iterative semi-supervised algorithms. We demonstrate that multi-layer linear attention implicitly emulates the Expectation-Maximization (EM) algorithm. Each layer effectively generates "soft" pseudo-labels for the unlabeled data, which are then used in subsequent layers to sharpen the task estimate. Because the expressivity grows exponentially with depth, even a shallow model can achieve near-Bayes-optimal performance by approximating high-degree iterations of EM.

Empirical Validation

We validated our theoretical findings using synthetic GMM data and real-world benchmarks.

Comparison of 1-layer, 2-layer, and 5-layer Transformers on synthetic GMM data. (a) shows accuracy with varying labeled samples. (b) and (c) demonstrate that only multi-layer models improve with more unlabeled (in-context) samples, matching theoretical predictions.

As shown in the figure above, 1-layer models reach a performance plateau regardless of the amount of unlabeled data provided. In contrast, 2-layer and 5-layer models show significant accuracy gains as more unlabeled (in-context) samples are added, closely following the theoretical bounds derived in our work (Theorem 1 and Theorem 2).

Practical Application: LoopTabFM

Translating theory into practice, we propose LoopTabFM, a method to enhance tabular foundation models (like TabPFN). Instead of a single forward pass, LoopTabFM "loops" the model: it uses the model's own predictions as soft pseudo-labels for unlabeled data, then re-inserts these augmented examples into the prompt for a refined second pass.

Evaluations on 17 real-world binary classification benchmarks from OpenML showed:

  • An average relative improvement of 6.35% over standard single-pass inference.
  • Gains as high as 19.4% on specific datasets (e.g., OpenML ID 1464).
  • A clear performance hierarchy: Transformers with Softmax and MLP outperform Linear Attention, which in turn outperforms simple Softmax attention.

Conclusion

This work provides the first rigorous proof that Transformer depth is essential for semi-supervised in-context learning. By implicitly emulating iterative algorithms like EM, deep or looped architectures can effectively turn unlabeled data into a useful signal. While our theory focuses on linear attention and isotropic noise, the empirical success of LoopTabFM suggests these principles apply broadly to modern foundation models. Future work will explore more complex data distributions and "data-aware" looping strategies to further stabilize performance gains.

Summary updated

BibTeX
@inproceedings{li2025when,
  author = {Yingcong Li and Xiangyu Chang and Muti Kara and Xiaofeng Liu and Amit K. Roy-Chowdhury and Samet Oymak},
  title = {{When and How Unlabeled Data Provably Improve In-Context Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=4TUpqyDJbz},
}
Figure