# In-Context Learning Creates Task Vectors

**Authors:** Roee Hendel, Mor Geva, Amir Globerson  
**arXiv:** [2310.15916](https://arxiv.org/abs/2310.15916)  
**Date:** 2023-10-24  
**Summary page:** https://www.summarizepaper.com/en/paper/2310.15916v1/

## Key points

- In-context learning (ICL) in Large Language Models (LLMs) is a powerful learning paradigm.
- The functions learned by ICL have a simple structure.
- ICL compresses the training set into a task vector and uses it to modulate the transformer for producing output.
- Comprehensive experiments were conducted across various models and tasks, including LLaMA 7B, 13B, and 30B, GPT-J 6B, and Pythia 2.8B, 6.9B, and 12B.
- Different layers in the transformer were investigated for implementing ICL, with all models exhibiting a performance peak at a similar intermediate layer.
- The accuracy of hypothesis-based prediction using the (A,f) mechanism was compared to regular forward pass ICL.
- Three procedures were evaluated: Regular ICL, Hypothesis-based ICL, and Baseline machine learning framework.
- This study provides insights into the structure of functions learned through ICL in LLMs and highlights how they can be represented as task vectors derived from training sets.

## Summary

In-context learning (ICL) in Large Language Models (LLMs) is a powerful learning paradigm, but its underlying mechanism is not well understood. This study aims to shed light on this problem by demonstrating that the functions learned by ICL have a simple structure. Specifically, these functions correspond to the transformer LLM with inputs consisting of the query and a single "task vector" calculated from the training set. In other words, ICL compresses the training set into a task vector and uses it to modulate the transformer for producing output. To support this claim, comprehensive experiments were conducted across various models and tasks. Multiple open LLMs including LLaMA 7B, 13B, and 30B, GPT-J 6B, and Pythia 2.8B, 6.9B, and 12B were utilized in these experiments. The study also investigated the impact of choosing different layers in the transformer for implementing ICL. The accuracy on a development set was evaluated for different layer choices. Interestingly, all models exhibited a performance peak at a similar intermediate layer regardless of their parameters and layer count differences. Furthermore, the accuracy of hypothesis-based prediction using the (A,f) mechanism was compared to regular forward pass ICL. Three procedures were evaluated: Regular ICL which applies the LLM to demonstrations S and query x as usual; Hypothesis which utilizes A to generate θ using a dummy x' followed by f; Baseline which represents standard machine learning framework where one uses training set S to find best-fitting function f(x). Overall, this study provides insights into the structure of functions learned through ICL in LLMs and highlights how they can be represented as task vectors derived from training sets.
