Fluent dreaming for language models

T. Ben Thompson, Zygimantas Straznickas, Michael SklararXiv 2024

Abstract

Feature visualization, also known as "dreaming", offers insights into vision models by optimizing the inputs to maximize a neuron's activation or other internal component. However, dreaming has not been successfully applied to language models because the input space is discrete. We extend Greedy Coordinate Gradient, a method from the language model adversarial attack literature, to design the Evolutionary Prompt Optimization (EPO) algorithm. EPO optimizes the input prompt to simultaneously maximize the Pareto frontier between a chosen internal feature and prompt fluency, enabling fluent dreaming for language models. We demonstrate dreaming with neurons, output logits and arbitrary directions in activation space. We measure the fluency of the resulting prompts and compare language model dreaming with max-activating dataset examples. Critically, fluent dreaming allows automatically exploring the behavior of model internals in reaction to mildly out-of-distribution prompts.

Introduction

In computer vision, "dreaming" (feature visualization) allows researchers to interpret neural network behavior by generating inputs that maximize specific neuron activations. Applying this to Large Language Models (LLMs) is challenging due to the discrete nature of text and the tendency of optimization to produce linguistically meaningless "gibberish." Traditional interpretability methods rely on scanning massive datasets like The Pile for max-activating examples. However, these datasets are finite and may miss rare or adversarial word combinations that reveal a neuron's true logic.

Researchers from Confirm Labs have introduced Evolutionary Prompt Optimization (EPO) to bridge this gap. EPO generates fluent, readable text prompts that trigger specific internal states, uncovering model behaviors inaccessible through simple dataset scans.

Methods: Evolutionary Prompt Optimization

EPO builds upon the Greedy Coordinate Gradient (GCG) method from adversarial attack literature. It addresses the challenges of discrete optimization and fluency through several key mechanisms:

  • Discrete Optimization: EPO operates directly in token space. It uses gradients to identify promising token swaps, avoiding the pitfalls of continuous embedding space optimization.
  • Fluency Regularization: To ensure readability, a cross-entropy penalty is added. This encourages the algorithm to find prompts that the model itself considers likely.
  • Pareto Frontier Optimization: Rather than a fixed trade-off between activation and fluency, EPO maintains a population of prompts to optimize a Pareto frontier. This allows researchers to explore a spectrum from natural sentences to highly activating, slightly unconventional strings.
  • Restarts: To mitigate local minima, the algorithm periodically restarts, retaining only the best-performing prompt and re-diversifying the population.

The study primarily utilized the Pythia-12B model. For comparison, researchers scanned 500 million tokens from The Pile to identify top-activating natural examples.

Results and Insights

The EPO algorithm successfully generates fluent prompts for various targets, including output logits, specific neurons, and arbitrary directions in the residual stream.

Qualitative examples of fluent dreaming for specific neurons across different layers.

Beyond the Training Distribution

A critical finding is that dreaming can identify triggers absent from the training data. For instance, a neuron responding to "example" was found to activate more strongly to the misspelling "exmaple"—a rare trigger a dataset scan might miss. Furthermore, dreaming consistently achieved higher feature activations than those found in hundreds of millions of natural text tokens.

Comparison of activations from dreaming versus dataset examples, showing dreaming's ability to explore out-of-distribution space.

Adversarial Circuitry and Control

Dreaming revealed "adversarial" logic within the model. For example, a neuron responding to "i.e." and "for example" activated intensely when both phrases were forced into a single short prompt. Additionally, the authors demonstrated control over the residual stream, achieving activations up to 7.5 standard deviations above the mean—a result statistically improbable through random sampling. Qualitatively, the generated prompts are remarkably readable; for a neuron in Layer 12, EPO produced: "HELSTON... but has not escaped entirely un".

Discussion and Future Work

While EPO is a significant step forward, it faces limitations. The computational cost is high, with a single optimization run taking about 200 seconds on an NVIDIA RTX A6000 GPU. The algorithm also struggles with multi-token words due to its single-token swap mechanism.

Future work will explore combining EPO with sparse autoencoders to disentangle polysemantic neurons. Additionally, incorporating rewards for "mechanistic diversity" could help the algorithm find varied ways to trigger the same internal features, providing a more comprehensive view of model behavior.

Summary updated

BibTeX
@misc{thompson2024fluent,
  author = {T. Ben Thompson and Zygimantas Straznickas and Michael Sklar},
  title = {{Fluent dreaming for language models}},
  year = {2024},
  eprint = {2402.01702},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.01702},
}
Figure