Disentangling Latent Shifts of In-Context Learning with Weak Supervision

Josip Jukić, Jan Šnajder

In-context learning (ICL) enables Large Language Models (LLMs) to adapt to new tasks simply by conditioning on a few examples in a prompt. However, as practitioners often discover, this flexibility comes with significant drawbacks. Model performance is highly sensitive to the choice and order of examples, and adding too many demonstrations causes inference costs to skyrocket while the model risks getting "lost in the middle."

To address the inherent instability and inefficiency of ICL, researchers have proposed a novel framework: WILDA (Weakly-supervised In-context Learning Disentanglement via Adapters). Instead of relying on the prompt to hold task knowledge during inference, WILDA treats ICL as a source of weak supervision, moving that knowledge into lightweight, reusable model parameters.

The Problem with Standard ICL

While prepending demonstrations to a query is the standard approach for few-shot learning, it suffers from three major flaws:

  1. Instability: Accuracy can fluctuate wildly depending on which examples are chosen and how they are ordered.
  2. Inefficiency: Every single query requires the model to reprocess the same long list of demonstrations, wasting compute and quickly hitting context window limits.
  3. The "Latent Shift" Problem: Demonstrations induce a "latent shift" in how the model processes a query. Previous attempts to disentangle this shift often involved hacking the model's internal attention heads, which fails to capture the complex non-linearities of the full transformer architecture.

The WILDA Framework

To solve these issues, the authors introduce a teacher-student framework that distills the prompt's task knowledge into a parameter-efficient adapter.

The WILDA teacher-student framework.
  1. The Teacher: A standard LLM (such as Llama 3) is provided with a traditional few-shot prompt containing demonstrations and a query. It generates "pseudo-labels" (predictions) for a small set of unlabeled queries.
  2. The Student: The same base LLM is equipped with a LoRA adapter (a tiny set of trainable weights). Crucially, the student only sees the query—no demonstrations are included in its prompt.
  3. The Training: The student is trained using cross-entropy loss to match the teacher’s output distribution. By doing this, the adapter "internalizes" the latent shift that the demonstrations would have otherwise caused.

The researchers tested several variants, but WILDA-S (which shuffles the demonstration order during the teacher's pseudo-label generation) proved most effective at neutralizing the order sensitivity of standard ICL.

Key Mechanisms: Why It Works

Surprisingly, even though the student learns from a "weak" teacher (the noisy few-shot prompt), it often ends up outperforming the teacher. This phenomenon is driven by a few key mechanisms:

  • Weak-to-Strong (W2S) Generalization: Because the student is trained on a broader set of queries, it learns the underlying task pattern and "smooths out" the teacher's occasional mistakes or inconsistencies (Pseudo-label Correction).
  • Coverage Expansion: The student generalizes the narrow patterns found in the few-shot examples to a wider range of inputs, effectively filling in the gaps that the original prompt couldn't cover.
  • Local Consistency: WILDA models exhibit a much lower "Lipschitz constant"—meaning their outputs are significantly more robust and less "jittery" when inputs change slightly compared to standard ICL.

Key Results: Stability and Performance

The researchers evaluated WILDA across standard benchmarks including GLUE, MMLU, and ARC-Challenge using models like Llama 3 (8B) and Phi 3 (mini 4k).

  • Performance Boost: WILDA-S consistently outperformed standard 16-shot ICL, showing gains of 2.6% to 11.9% on Llama 3 across various tasks.
  • Rock-Solid Stability: In tests where the order of demonstrations was shuffled 50 times, standard ICL showed high variance. WILDA-S drastically reduced this instability. For example, on the RTE task, standard ICL had a standard deviation of 4.81, while WILDA-S slashed it to 0.22.
Standard deviation of model performance across 50 demonstration permutations.
  • Inference Efficiency: While fine-tuning the adapter takes time upfront, it pays dividends in deployment. For a 16-shot setup, the authors estimate that after about 2,100 inferences, the compute time saved by not processing long prompts outweighs the initial training cost.
  • Adapter Arithmetic: Because task knowledge is stored in an adapter, users can train multiple adapters on different data subsets and simply add their weights together. This fuses the knowledge without ever needing to fit all demonstrations into a single context window.

Limitations and Conclusion

WILDA does require a small pool of unlabeled data (roughly 100 samples) to generate pseudo-labels, which is an extra step compared to pure zero-shot or few-shot prompting. Additionally, the upfront computational cost of training the adapter means it may not be the best fit for one-off, ad-hoc queries.

However, for tasks that will be run repeatedly, WILDA represents a powerful paradigm shift. Instead of endlessly tweaking the "perfect prompt," practitioners can use prompts as temporary scaffolds to build permanent, efficient, and highly stable parametric representations of a task.

Summary updated

Abstract

In-context learning (ICL) enables large language models to perform few-shot learning by conditioning on labeled examples in the prompt. Despite its flexibility, ICL suffers from instability -- especially as prompt length increases with more demonstrations. To address this, we treat ICL as a source of weak supervision and propose a parameter-efficient method that disentangles demonstration-induced latent shifts from those of the query. An ICL-based teacher generates pseudo-labels on unlabeled queries, while a student predicts them using only the query input, updating a lightweight adapter. This captures demonstration effects in a compact, reusable form, enabling efficient inference while remaining composable with new demonstrations. Although trained on noisy teacher outputs, the student often outperforms its teacher through pseudo-label correction and coverage expansion, consistent with the weak-to-strong generalization effect. Empirically, our method improves generalization, stability, and efficiency across both in-domain and out-of-domain tasks, surpassing standard ICL and prior disentanglement methods.
BibTeX
@inproceedings{jukic2025disentangling,
  author = {Josip Jukić and Jan Šnajder},
  title = {{Disentangling Latent Shifts of In-Context Learning with Weak Supervision}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=tAq9Gxdhr0},
}
Figure