Improving Input-label Mapping with Demonstration Replay for In-context Learning

Zhuocheng Gong, Jiahao Liu, Qifan Wang, Jingang Wang, Xunliang Cai, Dongyan Zhao, Rui Yan

Introduction

In-context learning (ICL) has emerged as a powerful paradigm for Large Language Models (LLMs), enabling them to perform new tasks using only a few demonstrations. However, standard causal LLMs suffer from an "information asymmetry" during ICL. Because these models process tokens sequentially, earlier demonstrations cannot benefit from the context provided by later ones. For instance, in a 4-shot prompt, the first example is essentially processed in a zero-shot manner. This causal bottleneck hinders the model's ability to fully grasp the input-label mapping across the entire set of demonstrations.

Methods: RDSCA

To address this, researchers introduced RDSCA (Repeated Demonstration with Sliding Causal Attention). This method allows models to observe all demonstrations simultaneously without breaking the causal structure learned during pre-training.

Comparison of standard ICL and RDSCA attention mechanisms.

RDSCA consists of two main components:

  1. Repeated Demonstration (RD): Later demonstrations are duplicated and prepended to the sequence. For a 4-shot prompt ($d_1, d_2, d_3, d_4$), the input becomes $d'_2, d'_3, d'_4, d_1, d_2, d_3, d_4, q$. This ensures that when the model processes $d_1$, it has already seen the context of subsequent examples.
  2. Sliding Causal Attention (SCA): To prevent the model from exploiting simple shortcuts (like label repetition), a custom attention mask is used. This mask ensures the model only attends to a sliding window of $K$ unique demonstrations while keeping the <SOS> (Start of Sequence) token always visible as a necessary anchor. If the sliding window moves past the <SOS> token, the model loses its "anchor" and performance plummets.

Evaluation

The method was evaluated using Llama models (7B to 65B) on various benchmarks, including classification tasks (SST-2, RTE, AGNews) and general knowledge (MMLU). A key focus was "Semantically-Unrelated Label" (SUL) ICL, where labels are replaced with random words to force the model to rely strictly on the provided mapping rather than prior knowledge.

Key Results and Insights

RDSCA demonstrates significant performance improvements, particularly as model scale increases. On Llama-65B, the method achieved a 10.5% average improvement over standard ICL.

Performance comparison of RDSCA across different model sizes and settings.

Key findings include:

  • Emergent Benefits: Gains are more pronounced in larger models (30B and 65B), suggesting they are better at leveraging complex contextual mappings.
  • Synergy: RDSCA is compatible with other ICL enhancements like demonstration retrieval and calibration, leading to further performance boosts.
  • Efficiency: By utilizing KV-caching, the overhead of repeated demonstrations is minimized during inference.

Conclusion

RDSCA effectively breaks the causal bottleneck in ICL by allowing bidirectional-like context within a causal framework. While it increases sequence length, the substantial accuracy gains—especially in large-scale models—highlight its potential for improving LLM reasoning and task adaptation. Future work may explore its application to complex Chain-of-Thought reasoning and long-form generation.

Summary updated

BibTeX
@inproceedings{gong2023improving,
  author = {Zhuocheng Gong and Jiahao Liu and Qifan Wang and Jingang Wang and Xunliang Cai and Dongyan Zhao and Rui Yan},
  title = {{Improving Input-label Mapping with Demonstration Replay for In-context Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.995},
}
Figure