In-Context Alignment: Chat with Vanilla Language Models Before Fine-Tuning

Xiaochuang HanarXiv 2023

Abstract

In this note, we explore inference-time alignment through in-context learning. We consider a vanilla pretrained language model Llama-2 before any fine-tuning and retrieve an average of 9 demonstration alignment examples when the model is prompted to follow chat-style instructions. Compared to direct prompting, the in-context alignment without changing model weights leads to a 7x increase in win-rate w.r.t. the text-davinci-003 model from OpenAI, making the vanilla language model comparable to strong baselines with alignment fine-tuning.

Introduction

Standard Large Language Models (LLMs) are typically pretrained on massive internet datasets to predict the next token. While this process creates a "world-class document completer," it often results in a mediocre assistant. When prompted with a question, a vanilla model might respond with more questions—mimicking a FAQ page—rather than providing a direct answer.

To bridge this gap, researchers usually employ Supervised Fine-Tuning (SFT) and Reinforcement Learning from Human Feedback (RLHF). However, these methods are resource-intensive, bake specific behaviors into model weights in a way that is difficult to reverse, and often lack transparency. This paper investigates whether alignment can be achieved entirely at inference time using In-Context Learning (ICL), bypassing the need for weight updates.

Methodology: In-Context Alignment (ICA)

The authors propose a training-free pipeline called In-Context Alignment (ICA). This approach leverages the inherent capabilities of the pretrained model by providing it with a "situational nudge" via few-shot demonstrations.

The In-Context Alignment pipeline vs. standard vanilla prompting. ICA uses a retriever to find relevant demonstrations, resulting in a 7x win-rate increase without changing model weights.

The ICA pipeline consists of three main stages:

  1. Retrieval: For any user prompt, a general-purpose retriever (Contriever) searches an alignment pool of approximately 9,000 examples for the most semantically similar prompt-response pairs.
  2. Prompt Construction: The system selects an average of 9 demonstrations that fit within the model's context window, formatted into a clear Question/Answer template.
  3. Generation: The vanilla model (e.g., Llama-2) receives the user's query prepended with these retrieved demonstrations.

This method requires zero changes to the model weights; the alignment occurs entirely within the context window, allowing for high transparency and agility.

Experimental Setup

The alignment pool was constructed using 9,716 prompts from Open Assistant 1 (OASST1), with responses "distilled" using GPT-3.5-turbo to ensure high-quality, consistent demonstrations. Evaluation was conducted on the LIMA test set, comprising 300 prompts across creative writing, technical QA, and brainstorming. The performance was benchmarked against OpenAI’s text-davinci-003 and ChatGPT, as well as fine-tuned models like Guanaco and Llama-2-chat.

Key Results

The results demonstrate that ICA can make a raw model perform comparably to those that underwent extensive fine-tuning.

Performance comparison of various models. Llama-2-vanilla (13B) with ICA achieves a 78.4% win rate against text-davinci-003, outperforming the fine-tuned Guanaco-13B.

As shown in the data, Llama-2-vanilla (13B) with zero-shot prompting achieved a mere 11.4% win rate against text-davinci-003. With ICA, this skyrocketed to 78.4%. Notably, the 13B vanilla model with ICA slightly outperformed Guanaco-13B, which was fine-tuned on similar data. When scaled to the 70B parameter model, ICA achieved an 88.5% win rate against text-davinci-003 and a 53.7% win-or-draw rate against ChatGPT.

Discussion and Analysis

The "Hidden" Capability

The success of ICA suggests that vanilla models already possess the knowledge and linguistic skill required to follow instructions. They simply need the right context to switch from "document completion mode" to "assistant mode."

Retrieval vs. Randomness

A critical finding in the ablation studies was the importance of relevance. Using 9 retrieved examples for Llama-2-13B resulted in a 78.4% win rate, whereas using 10 random examples yielded only 62.9%. This confirms that semantic similarity in demonstrations is a key driver of alignment quality.

Interpretability and Agility

Unlike fine-tuned models, ICA is inherently interpretable. If a model produces an undesirable response, researchers can inspect the retrieved examples to identify the source of the behavior. Furthermore, a model's "personality" or safety guidelines can be updated instantly by modifying the retrieval pool, requiring no new training runs.

Limitations and Conclusion

While powerful, ICA faces several challenges:

  • Context Constraints: The number of demonstrations is limited by the model's context window (e.g., 4k tokens for Llama-2), which may restrict performance on long-form tasks.
  • Inference Latency: Prepending thousands of tokens to every query increases the computational cost and latency for the first-token generation.
  • Safety Robustness: While demonstrations can guide a model toward safety, the authors noted instances where the model would still follow harmful instructions (e.g., "roasting" a user) if the retrieved examples were not strictly aligned.

In conclusion, In-Context Alignment provides a robust, training-free alternative to traditional fine-tuning, proving that the "alignment tax" can often be avoided by better utilizing the context window of pretrained models.

Summary updated

BibTeX
@misc{han2023context,
  author = {Xiaochuang Han},
  title = {{In-Context Alignment: Chat with Vanilla Language Models Before Fine-Tuning}},
  year = {2023},
  eprint = {2308.04275},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.04275},
}
Figure