Abstract: In-context learning (ICL) is an effective approach to help large language models (LLMs) adapt to various tasks by providing demonstrations of the target task. Considering the high cost of labeling demonstrations, many methods propose synthesizing demonstrations from scratch using LLMs. However, the quality of the demonstrations synthesized from scratch is limited by the capabilities and knowledge of LLMs. To address this, inspired by transfer learning, we propose In-Context Transfer Learning (ICTL), which synthesizes target task demonstrations by transferring labeled demonstrations from similar source tasks. ICTL consists of two steps: source sampling and target transfer. First, we define an optimization objective, which minimizes transfer error to sample source demonstrations similar to the target task. Then, we employ LLMs to transfer the sampled source demonstrations to the target task, matching the definition and format of the target task. Experiments on Super-NI show that ICTL outperforms synthesis from scratch by 2.0% on average, demonstrating the effectiveness of our method.
1. Introduction
In-context learning (ICL) has emerged as a powerful paradigm for adapting large language models (LLMs) to new tasks without parameter updates. By providing a few input-output examples, or demonstrations, users can guide the model's behavior. However, the effectiveness of ICL is heavily dependent on the quality of these demonstrations. While human-labeled data is the gold standard, it is often prohibitively expensive or time-consuming to acquire at scale.
To mitigate this, researchers have explored "synthesis from scratch," where an LLM generates its own demonstrations based on a task definition. This approach, however, is limited by the model's internal knowledge; if the model lacks specific domain expertise or up-to-date information, the synthesized examples may be inaccurate or irrelevant. This paper introduces In-Context Transfer Learning (ICTL), a novel framework that synthesizes demonstrations by transferring knowledge from existing, labeled source tasks.
2. The ICTL Framework
ICTL treats demonstration synthesis as a transfer learning problem, leveraging the structure and labels of related tasks to ground the synthesis process. The framework consists of two primary stages: Source Sampling and Target Transfer.
2.1 Source Sampling
The first challenge is identifying which source tasks are most relevant to the target task. ICTL employs a mathematical optimization objective to minimize transfer error. By representing task definitions and demonstrations as vectors (embeddings), the system calculates the Wasserstein distance between distributions. This allows for the selection of source tasks that are semantically and structurally "closest" to the target, ensuring a high-quality foundation for transfer.
2.2 Target Transfer and Verification
Once similar source demonstrations are identified, an LLM is prompted to "transfer" or reformat this data to match the target task's definition and format. This step is crucial; simply providing source demonstrations directly often degrades performance (the "Direct Penalty"). The transfer process ensures that the logic of the source task is preserved while the context and formatting are aligned with the target.
Finally, a verification step is implemented. An LLM acts as a critic, evaluating whether the transferred demonstration accurately reflects the target task's requirements. Examples that fail this check are discarded, preventing "junk" data from polluting the context window.
3. Experimental Evaluation
The authors evaluated ICTL on the Super-NaturalInstructions (Super-NI) benchmark, which contains over 1,600 NLP tasks. The source pool consisted of 756 English tasks, while evaluation was conducted across 116 tasks spanning categories like Classification, Generation, and Extraction.
Key Results
- Overall Gains: ICTL outperformed "synthesis from scratch" by an average of 2.0% across all tasks.
- Model Agnostic: The benefits were consistent across different models, including Llama 3.1-8B and GPT-4o.
- Ablation Importance: Removing the Verification step caused the biggest performance drop (3.3%), suggesting that LLMs still produce a significant amount of low-quality data during the transfer process that needs to be filtered out.
4. Discussion and Insights
A significant finding is that "real" data from a source task provides a more reliable signal than "hallucinated" data from scratch. By grounding the synthesis in existing labels, ICTL overcomes the knowledge bottleneck inherent in standard synthesis. However, the method's effectiveness is tied to the diversity of the source pool. Performance was lower in niche categories like Dialogue and Extraction, which were underrepresented in the source data (making up only 5% of the pool).
5. Conclusion
In-Context Transfer Learning (ICTL) provides a scalable and effective alternative to manual labeling and naive synthesis. By intelligently transferring knowledge from similar tasks, it enhances the adaptability of LLMs. Future work will focus on expanding source task libraries and optimizing the computational efficiency of the transfer and verification pipeline to reduce inference latency.
Summary updated