[Paper Review] In-context Vectors: Making In Context Learning More Effective and Controllable Through Latent Space Steering
This paper proposes In-Context Vectors (ICV), a method that distills demonstration examples into a single latent vector to steer large language models during inference, enabling more effective, controllable, and efficient in-context learning without requiring prompt engineering or parameter updates. ICV outperforms standard in-context learning and LoRA fine-tuning across diverse tasks including safety, style transfer, and role-playing.
Large language models (LLMs) demonstrate emergent in-context learning capabilities, where they adapt to new tasks based on example demonstrations. However, in-context learning has seen limited effectiveness in many settings, is difficult to quantitatively control and takes up context window space. To overcome these limitations, we propose an alternative approach that recasts in-context learning as in-context vectors (ICV). Using ICV has two steps. We first use a forward pass on demonstration examples to create the in-context vector from the latent embedding of the LLM. This vector captures essential information about the intended task. On a new query, instead of adding demonstrations to the prompt, we shift the latent states of the LLM using the ICV. The ICV approach has several benefits: 1) it enables the LLM to more effectively follow the demonstration examples; 2) it's easy to control by adjusting the magnitude of the ICV; 3) it reduces the length of the prompt by removing the in-context demonstrations; 4) ICV is computationally much more efficient than fine-tuning. We demonstrate that ICV achieves better performance compared to standard in-context learning and fine-tuning on diverse tasks including safety, style transfer, role-playing and formatting. Moreover, we show that we can flexibly teach LLM to simultaneously follow different types of instructions by simple vector arithmetics on the corresponding ICVs.
Motivation & Objective
- To address the limitations of in-context learning (ICL), such as sensitivity to demonstration order, high context length usage, and lack of controllability.
- To develop a method that captures task-specific information from demonstrations without requiring prompt templates or fine-tuning.
- To enable efficient, scalable, and controllable adaptation of large language models using a single latent vector during inference.
- To demonstrate that ICV can combine multiple tasks through vector arithmetic and outperform standard ICL and LoRA fine-tuning.
Proposed method
- ICV computes a single in-context vector from the latent representations of demonstration examples using a forward pass through the LLM.
- During inference, the ICV is added to the latent states of all transformer layers and token positions, effectively steering the model’s generation without modifying the original activations.
- The magnitude of the ICV can be adjusted to control the strength of the task guidance, enabling fine-grained control over model behavior.
- The method operates entirely at inference time, requiring no parameter updates or fine-tuning, and avoids the need to store or process full demonstration sequences in context.
- ICV enables multi-task learning by combining task-specific vectors through arithmetic operations such as addition or negation.
- The approach is applied across multiple LLMs, including Falcon-7B and Llama, and validated on tasks like style transfer, safety filtering, and role-playing.
Experimental results
Research questions
- RQ1Can in-context learning be made more effective and controllable by replacing demonstrations with a distilled latent vector?
- RQ2Can the ICV method reduce context length usage while maintaining or improving performance compared to standard in-context learning?
- RQ3Can ICV be used to combine multiple distinct tasks through vector arithmetic without retraining?
- RQ4How does ICV compare to fine-tuning methods like LoRA in terms of performance and computational efficiency?
- RQ5Does ICV preserve the model’s original capabilities while effectively guiding it toward new task behaviors?
Key findings
- ICV significantly outperforms standard in-context learning and LoRA fine-tuning on tasks including dialogue safety, style transfer, and formatting, as shown in qualitative and quantitative evaluations.
- ICV enables flexible, controllable behavior adjustment by tuning the magnitude of the in-context vector, allowing for precise control over the degree of instruction following.
- The method reduces prompt length by eliminating the need to include demonstration examples in the input context, thus conserving valuable context window space.
- ICV supports multi-task learning through vector arithmetic: for example, adding or negating ICVs can combine or cancel out different instruction types.
- ICV maintains high performance even when the number of demonstrations exceeds the model’s context length, as the demonstrations are summarized into a single vector.
- The approach is computationally efficient, with negligible overhead during ICV computation, and does not require any parameter updates or fine-tuning.
Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.