Pre-Training to Learn in Context

Yuxian Gu, Li Dong, Furu Wei, Minlie Huang

Abstract

In-context learning (ICL) has emerged as a powerful capability of large language models, yet standard pre-training objectives do not explicitly optimize for this skill. We present PICL (Pre-training for In-Context Learning), a framework designed to enhance a model's ability to learn from examples by leveraging "intrinsic tasks" found within raw web text. By retrieving and concatenating paragraphs with shared task semantics, PICL encourages models to infer and solve tasks from context during the pre-training phase. Our experiments demonstrate that a 770M parameter model trained with PICL outperforms significantly larger models on few-shot benchmarks and exhibits superior generalization to unseen task formats compared to traditional meta-training approaches.

1. Introduction

The ability of Large Language Models (LLMs) to perform new tasks simply by observing a few examples in a prompt—known as in-context learning (ICL)—is one of the most significant advancements in natural language processing. However, standard pre-training, which focuses on next-token prediction within single documents, does not explicitly teach a model how to utilize context to solve novel tasks.

Existing attempts to improve ICL often rely on "meta-fine-tuning" models on collections of human-annotated datasets. While helpful, this approach is limited by the diversity of human-labeled data and often introduces "task bias," where models become rigid in their handling of specific formats or label spaces. This paper introduces PICL, a method that treats the vast, diverse, and "free" data available on the internet as a massive collection of unlabeled tasks to teach models how to learn in context.

2. The PICL Framework

The core philosophy of PICL is that the internet naturally contains task-like structures. For example, a series of movie reviews in a blog post is essentially a natural sentiment analysis task. PICL formalizes this by structuring pre-training data to mirror the few-shot evaluation setting.

2.1 Task-Semantics Retrieval

To construct meaningful meta-training instances, the framework must identify paragraphs that share the same "intrinsic task." We employ a retriever (based on RoBERTa) trained via contrastive learning on 37 diverse downstream datasets. Unlike standard retrievers that prioritize topical similarity (e.g., finding two articles about "dogs"), our retriever focuses on task semantics (e.g., finding two different lists of facts or two different translations).

2.2 Data Construction and Filtering

For any given paragraph $z_0$ in a large corpus (such as OpenWebText), the retriever identifies $k$ similar paragraphs. These are concatenated to form a meta-training instance: `[Example 1] + [Example 2] + ...

  • [Target Paragraph]`.

To ensure the quality of these sequences, we apply an "Informativeness Filtering" step. Using a perplexity-based score, we discard instances where the preceding context does not significantly improve the model's ability to predict the target paragraph. This ensures the model trains on high-quality signals where the context is genuinely useful for the task at hand.

2.3 Pre-Training Objective

The model is trained on these concatenated sequences using a standard language modeling objective. To maintain general language proficiency and prevent the model from specializing solely on concatenated formats, we also include original, non-concatenated documents in the training mix.

3. Experimental Evaluation

We pre-trained a 770M parameter GPT-2 style model using a 30GB corpus comprising OpenWebText, WikiCorpus, and BookCorpus.

3.1 Few-Shot Classification

We evaluated PICL on seven classification datasets, including SST-2 (sentiment), RTE (entailment), and AgNews (topic). In a 4-shot setting, the 770M parameter PICL model achieved an average accuracy of 64.4%. Notably, this outperformed a vanilla GPT-Neo model with 2.7B parameters (59.9%), demonstrating that PICL significantly improves the efficiency and effectiveness of ICL relative to model size.

3.2 Instruction Following and Generalization

To test generalization to unseen tasks, we utilized the Super-NaturalInstructions benchmark, featuring 105 evaluation tasks. We compared PICL against MetaICL, a model meta-trained on human-annotated datasets. While MetaICL performed well on simple classification tasks similar to its training data, PICL showed significantly better performance on complex text generation and entirely unseen task formats. This suggests that the diversity of "intrinsic tasks" in web text provides a more robust foundation for generalization than curated datasets.

4. Discussion and Key Insights

Our analysis reveals several critical insights into the nature of in-context learning:

  • Task Semantics vs. Topic: The success of PICL hinges on the retriever's ability to find task-similar rather than topic-similar content. Standard retrieval does not provide the necessary signal for ICL.
  • Diversity through Web Text: Because the "tasks" are sourced from free-form web text, the model learns to handle a much wider variety of formats and domains than it would from human-labeled data alone.
  • Scaling Laws of Context: ICL performance improves steadily as the size of the retriever's search library increases, indicating that more data directly translates to better in-context reasoning.

5. Conclusion and Future Work

PICL demonstrates that the ability to learn in context can be explicitly cultivated during pre-training using unlabeled web data. By structuring the pre-training process to mirror the few-shot setting, we create models that are more adaptable and efficient than those trained on standard objectives or limited human datasets. Future research will explore the integration of human instructions into the PICL framework and the development of fully unsupervised retrievers to further scale this approach.

Summary updated

BibTeX
@inproceedings{gu2023pre,
  author = {Yuxian Gu and Li Dong and Furu Wei and Minlie Huang},
  title = {{Pre-Training to Learn in Context}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.267},
}
Figure