Z-ICL: Zero-Shot In-Context Learning with Pseudo-Demonstrations

Xinxi Lyu, Sewon Min, Iz Beltagy, Luke Zettlemoyer, Hannaneh Hajishirzi

Abstract

Zero-Shot In-Context Learning (Z-ICL) is a novel approach that enhances the performance of Large Language Models (LLMs) on zero-shot tasks by automatically generating "pseudo-demonstrations" from unlabeled text. By retrieving semantically similar sentences and pairing them with random labels and synonyms, Z-ICL provides the necessary domain and format context to bridge the gap between zero-shot and few-shot learning.

Introduction

Large Language Models (LLMs) excel at In-Context Learning (ICL), where they perform tasks based on a few provided examples. However, in zero-shot scenarios where no labeled data exists, performance typically drops significantly. Recent findings suggest that ICL demonstrations serve primarily to specify the task's domain and format rather than providing a direct training signal.

Z-ICL leverages this insight by using raw, unlabeled corpora to create "fake" examples. A key challenge addressed is the "copying effect": LLMs tend to replicate the label of the most similar example in the prompt. If a demonstration is too similar to the test input, the model may bypass reasoning and simply copy the associated label, which is problematic when labels are randomly assigned.

Methodology

Z-ICL constructs pseudo-demonstrations through a three-step process:

  1. Retrieval: For each test input, the system identifies the $k$ nearest neighbors in a large unlabeled corpus (e.g., Wikipedia or web crawls) using sentence embeddings like SimCSE.
  2. Physical Neighbor Selection: To mitigate the copying effect, Z-ICL avoids using the retrieved sentence itself. Instead, it selects the "physical neighbor"—the sentence immediately following the retrieved one in the original document. This maintains domain relevance while introducing lexical diversity.
  3. Synonym Labeling: Each pseudo-demonstration is assigned a random label from the task's label space. To prevent the model from focusing on specific tokens, Z-ICL uses synonyms of the labels (e.g., "bad" instead of "terrible").
The three-step Z-ICL pipeline: retrieval of relevant sentences, construction of pseudo-demonstrations using physical neighbors and synonyms, and final inference.

Experimental Setup

The authors evaluated Z-ICL using the Demix corpus (16 diverse domains) across nine text classification datasets. These included "covered" datasets (e.g., Amazon and Yelp reviews) and "not covered" datasets (e.g., Movie Reviews and SST). The method was tested on models ranging from GPT-J (6B) to GPT-3 (175B).

Key Results and Insights

Z-ICL consistently outperformed standard zero-shot baselines, showing absolute accuracy gains of 5% to 30%. On datasets well-represented in the retrieval corpus, Z-ICL achieved performance parity with gold-standard few-shot learning.

Ablation studies highlighted the importance of the labeling strategy. Using synonyms significantly outperforms using the original labels or random words, especially when combined with physical neighbor retrieval.

Comparison of labeling strategies (Original, Random Words, Synonyms) across different retrieval methods, demonstrating the superiority of synonym labeling.

Key takeaways include:

  • Format over Accuracy: In zero-shot settings, providing the correct format and domain context is more critical than label accuracy.
  • Corpus Coverage: Performance is highly dependent on the similarity between the raw text corpus and the target task.
  • Scalability: The benefits of Z-ICL are consistent across different model architectures and sizes.

Conclusion and Future Work

Z-ICL demonstrates that unlabeled text can effectively replace human-labeled examples for in-context learning. While currently focused on single-sentence classification, future work could extend this to multi-sentence or generative tasks. Additionally, automating synonym selection and optimizing the retrieval pipeline remain areas for further development.

Summary updated

BibTeX
@inproceedings{lyu2023z,
  author = {Xinxi Lyu and Sewon Min and Iz Beltagy and Luke Zettlemoyer and Hannaneh Hajishirzi},
  title = {{Z-ICL: Zero-Shot In-Context Learning with Pseudo-Demonstrations}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.129},
}
Figure