Parallel Structures in Pre-training Data Yield In-Context Learning

Yanda Chen, Chen Zhao, Zhou Yu, Kathleen R. McKeown, He He

Abstract

Pre-trained language models (LMs) are capable of in-context learning (ICL): they can adapt to a task with only a few examples given in the prompt without any parameter update. However, it is unclear where this capability comes from as there is a stark distribution shift between pre-training text and ICL prompts. In this work, we study what patterns of the pre-training data contribute to ICL. We find that LMs’ ICL ability depends on parallel structures in the pre-training data—pairs of phrases following similar templates in the same context window. Specifically, we detect parallel structures by checking whether training on one phrase improves prediction of the other, and conduct ablation experiments to study their effect on ICL. We show that removing parallel structures in the pre-training data reduces LMs’ ICL accuracy by 51% (vs 2% from random ablation). This drop persists even when excluding common patterns such as n-gram repetitions and long-range dependency, showing the diversity and generality of parallel structures. A closer look at the detected parallel structures indicates that they cover diverse linguistic tasks and span long distances in the data.

Introduction

One of the most striking emergent properties of Large Language Models (LLMs) is In-Context Learning (ICL): the ability to adapt to a new task simply by seeing a few examples in a prompt. However, there is a significant "distribution shift" between how these models are trained and how they are used. LLMs are pre-trained on natural text (like Wikipedia or web crawls), which rarely resembles the structured few-shot prompts used during inference (e.g., "Apple -> Fruit, Carrot -> Vegetable, Potato -> ?"). This research identifies "parallel structures"—pairs of phrases following similar templates within the same context window—as the primary driver of ICL.

Identifying Parallel Structures

The researchers introduce the concept of Parallel Structures (PS) as natural language's version of a few-shot example. A PS consists of two phrases in the same context window that follow the same distribution. For instance, a news article might mention "infant mortality in 2015" and then "infant mortality in 2013."

To detect these structures, the authors developed a novel loss-based algorithm. They take a pre-trained model and "test" a pair of phrases. If fine-tuning the model on the first phrase significantly improves its ability to predict the second phrase, the pair is flagged as a Parallel Structure. This suggests the model recognizes they share a common "template" or underlying task.

Figure 2: Detection of parallel structures. If training on one phrase (e.g., "mortality rates again in 2015") improves the log probability of a similar phrase later in the context (e.g., "2013 | Infant mortality in"), it is identified as a parallel structure.

Experimental Methodology

To prove the causal link between PS and ICL, the authors performed ablation experiments on the OpenWebText dataset. They identified the top $p\%$ of parallel structures and "noised" the data by replacing the target token of the second phrase with a random word. They then continued training GPT-2 models on this ablated data and compared their ICL performance against models trained on clean data or data with random noise.

Evaluation was conducted across two categories of tasks:

  1. Natural Language Tasks: Including verb inflection, adjective-to-noun conversion, case changing, and synonym/antonym classification.
  2. Symbolic Reasoning Tasks: Including string copying, identifying the last token, searching for tokens, palindrome detection, and pattern completion.

The Impact of Parallel Structures on ICL

The results were stark. Removing parallel structures led to a 51% relative decrease in ICL accuracy across various model sizes. In contrast, removing an equal number of random tokens only caused a 2% drop. This suggests that these "mini-tasks" hidden in natural text are the essential components that allow models to learn from examples without weight updates.

Figure 6: ICL performance of GPT2-S on various tasks. The -PS row shows a significant drop in accuracy compared to the CLEAN and -RAND baselines across almost all tasks.

Crucially, the authors found that ablating PS did not diminish the models' underlying knowledge of the tasks. When the models were fully fine-tuned on a task, they performed just as well as the baseline. This confirms that the loss was specifically in their ability to learn from the prompt, not their fundamental task capability.

Key Insights

  • Beyond Long-Range Dependency: While previous theories suggested ICL was a byproduct of learning long-range dependencies, this work shows that PS are far more influential. Removing PS hurts ICL significantly more than removing general long-range dependencies.
  • Diversity and Distance: Parallel structures in the wild cover a vast range of skills, from world knowledge to complex syntactic constructions. On average, the two parts of a parallel structure are 343 tokens apart, explaining why LLMs are proficient at utilizing long prompts.
  • Generality: The effect was consistent across the entire GPT-2 family (from 117M to 1.6B parameters), suggesting it is a fundamental property of transformer-based language modeling.

Conclusion

This study provides a concrete explanation for the emergence of in-context learning by identifying parallel structures as the training signal. While the study was limited to models up to 1.5 billion parameters, it opens the door for investigating whether similar structures drive more complex emergent behaviors like chain-of-thought reasoning or exist in multi-modal data.

Summary updated

BibTeX
@inproceedings{chen2024parallel,
  author = {Yanda Chen and Chen Zhao and Zhou Yu and Kathleen R. McKeown and He He},
  title = {{Parallel Structures in Pre-training Data Yield In-Context Learning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=Ebm95wAYNe},
}
Figure