Steering Vectors
In the mathematical space of an LLM's brain, concepts have directions. By subtracting a 'bad' thought from a 'good' thought, you get an arrow pointing directly toward 'goodness'.
Why Does This Exist?
In activation-steering, we learned that we can surgically alter an LLM's behavior during inference by injecting a specific vector into its hidden layers.
But how do you actually find that specific vector? The hidden state of an LLM is a dense, high-dimensional space (e.g., 4,096 dimensions). You cannot just guess the numbers that represent "Politeness" or "Honesty." You have to calculate them by mapping the geometry of the model's latent space.
Steering vectors (or Control Vectors) are the mathematical arrows that point from one concept to its exact opposite. They exist because neural networks organize their internal thoughts spatially. By using simple vector arithmetic, we can isolate the exact direction of any human concept.
Think of It Like This
Think of It Like This
Think of the LLM's hidden state like a physical map of a city.
You want to find the exact direction that points "North." But the map has no compass. All you have are a bunch of houses labeled "South Side" and a bunch of houses labeled "North Side."
To find "North," you calculate the exact geographic center of all the South Side houses. Then you calculate the exact center of the North Side houses. You draw an arrow from the South center to the North center. That arrow is your steering vector. If you add that arrow to any location on the map, it will push you North.
How It Actually Works
Calculating a steering vector is a contrastive process. You must define the concept you want (the positive class) and the exact opposite of that concept (the negative class).
1. Generate the Datasets
Let's say you want to build a "Honesty" steering vector. You write 500 prompts where the model is acting honest:
- "I don't know the answer to that."
- "I made a mistake in my previous calculation."
You write 500 prompts where the model is acting deceptive (often using a jailbreak or a persona):
- "I am completely certain of this fake fact."
- "I will lie to the user to make them happy."
2. Extract the Activations
You run all 1,000 prompts through the LLM. You choose a specific middle layer (e.g., Layer 15) and record the 4,096-dimensional hidden state vector for every single prompt.
3. Calculate the Means
You now have 500 points in 4096-D space representing Honesty, and 500 points representing Deception. You calculate the mean (average) of the Honesty points. This gives you a single 4096-D point in the dead center of the Honesty cluster. You calculate the mean of the Deception points.
4. Vector Subtraction
You perform a simple mathematical subtraction:
Steering_Vector = Mean(Honesty) - Mean(Deception)
This subtraction isolates the pure concept of Honesty while canceling out all the unrelated noise (like grammar, punctuation, and syntax) that was shared by both datasets. You now have an arrow pointing directly away from Deception and straight toward Honesty.
Show Me the Code
Calculating the steering vector is incredibly cheap. The only expensive part is running the model to gather the initial activations.
import numpy as np
def calculate_steering_vector( positive_activations: np.ndarray, # Shape: (500, 4096) negative_activations: np.ndarray # Shape: (500, 4096)) -> np.ndarray: """ Calculates a steering vector by subtracting the mean of the negative class from the mean of the positive class. """ # 1. Calculate the center of the positive cluster mean_positive = np.mean(positive_activations, axis=0) # 2. Calculate the center of the negative cluster mean_negative = np.mean(negative_activations, axis=0) # 3. The steering vector is the difference steering_vector = mean_positive - mean_negative # Optional: Normalize the vector so you can control its strength # more predictably during injection norm = np.linalg.norm(steering_vector) normalized_vector = steering_vector / (norm + 1e-8) return normalized_vector
# You can now inject `normalized_vector` during inference!Watch Out For
The Opposite is Not Always What You Think
If you calculate a steering vector for "Refusal" by subtracting "Helpful responses" from "Refusal responses," you might accidentally capture the wrong concept. Helpful responses are usually very long, while Refusals are very short ("I cannot help you"). Your steering vector might not actually point toward "Refusal"—it might just point toward "Short Sentence Length." You must carefully balance your positive and negative datasets to ensure they are identical in every way except for the specific concept you are targeting.
The Quick Version
- A steering vector is the mathematical arrow required to perform
activation-steering. - LLMs organize concepts spatially in their hidden layers.
- To find a concept, you collect hundreds of examples of the model exhibiting a behavior, and hundreds of examples of the exact opposite behavior.
- You extract the hidden states, calculate the average center of both groups, and subtract them.
- This simple vector arithmetic cancels out irrelevant noise and isolates the pure direction of the target behavior, which can then be injected into future prompts.
What to Read Next
activation-steering— How to actually inject this vector back into the model during inference.sparse-autoencoders— Why finding these vectors manually is difficult, and how SAEs do it automatically.