Skip to content
AI360XpertBeta

Steering Vectors in LLM Hidden States

Take the average hidden state of polite answers, subtract the average of rude ones, and the leftover arrow points at politeness. Add a little of it back during one forward pass and the model leans that way.

Two matched piles of hidden states average to two centers, and the steering vector is the arrow from the negative center to the positive one
Two matched piles of hidden states average to two centers, and the steering vector is the arrow from the negative center to the positive one

Why Does This Exist?

You want the model to lean one way. Warmer. More refusing. Less sycophantic. Prompting can ask for that, but text the user appends later can wash your instruction out. Training locks the change in, yet it rewrites weights permanently and bills you a full training run for what might be a session-level preference.

There is a middle tool: reach into one forward pass and nudge the hidden state along some direction. That is activation steering, and it only works if you know which direction to push. The hidden state is a list of thousands of numbers. You cannot guess which combination of them means politeness.

Steering vectors are how you find the arrow instead of guessing it. Run the model on piles of contrastive examples, average each pile, subtract. This page builds that arrow from scratch. The loop that injects it lives in activation steering. The test that proves a layer causes a behavior, rather than controlling it, is activation patching. Cleaner directions pulled from dictionary learning are in sparse autoencoders.

The one idea this page stands on. At each transformer layer the model carries a hidden state hh, a vector in Rd\mathbb{R}^d, meaning a list of dd real numbers summarizing everything read so far. Each layer reads that vector and writes an update back into it, which is why editors call the whole chain the residual stream. If that picture is new, start with embeddings and how LLMs work, then come back. Everything below is arithmetic on those lists of numbers.

Think of It Like This

Two crowds on a lawn, and the arrow between their middles

You run a festival and two crowds gather on the same lawn: choir fans on one side, drum-line fans on the other. You want the direction from drums to choir, so you can point latecomers the right way. You find the middle of each crowd, stand on the drums middle, and draw an arrow to the choir middle. A latecomer takes a few steps along that arrow and lands closer to the choir side.

The mapping runs point for point. Each person is one recorded activation. Each crowd is one contrastive pile. The middle of a crowd is the mean. The arrow is the steering vector, and the latecomer's few steps are the strength knob α\alpha (alpha), one plain number you choose.

It stops here. The trick only works because both crowds stood on the same lawn for the same event. If the choir had met on a hill and the drums in a pit, your arrow would point downhill, not at the choir. Matched piles are the whole game, which is exactly what the first pitfall below is about.

How It Actually Works

Pick a layer ll and a token position, usually the last prompt token, where the model has seen the whole request. Call the live hidden state there hh. Everything else is preparation you do once, offline.

Two matched piles, then one subtraction

Collect n+n^+ (n-plus) prompts where the model shows the behavior you want, and n−n^- (n-minus) prompts showing its exact opposite. Run them all through the frozen model and record the hidden state at your chosen layer and position. That gives you two piles of vectors: h1+,…,hn++h_1^+, \ldots, h_{n^+}^+ and h1−,…,hn−−h_1^-, \ldots, h_{n^-}^-.

Average each pile:

μ+=1n+∑i=1n+hi+,μ−=1n−∑j=1n−hj−\mu^+ = \frac{1}{n^+} \sum_{i=1}^{n^+} h_i^+, \qquad \mu^- = \frac{1}{n^-} \sum_{j=1}^{n^-} h_j^-

In plain words: μ+\mu^+ (mu-plus) is the center of the wanted pile, μ−\mu^- (mu-minus) the center of the opposite pile. Then subtract:

v=μ+−μ−,v^=v∥v∥v = \mu^+ - \mu^-, \qquad \hat{v} = \frac{v}{\lVert v \rVert}

The vector vv is your steering vector, and v^\hat{v} (v-hat) is the same arrow scaled to length 11. Subtraction is the step that matters. Whatever both piles share, grammar, topic, formatting, sits in both centers and cancels. What differs, the behavior, survives. Then scaling to unit length makes the strength knob mean the same step size for every vector you build.

The piles must match on everything except the target. Same prompt templates, same lengths, same topics, opposite behavior. Minimal pairs work best: two completions of one prompt, one polite and one rude, rather than polite poems against rude error logs. An unmatched pile hands you an arrow to the confound, and you will steer sentence length while the attitude stays put.

Worked example with small numbers

Toy hidden states with d=3d = 3 entries. Three polite recordings:

p1=[1.0, 2.0, 0.5],p2=[1.5, 1.5, 1.0],p3=[0.5, 2.5, 1.5]p_1 = [1.0,\ 2.0,\ 0.5], \quad p_2 = [1.5,\ 1.5,\ 1.0], \quad p_3 = [0.5,\ 2.5,\ 1.5]

Three rude ones:

n1=[2.0, 0.5, 1.5],n2=[2.5, 1.0, 0.5],n3=[1.5, 0.0, 1.0]n_1 = [2.0,\ 0.5,\ 1.5], \quad n_2 = [2.5,\ 1.0,\ 0.5], \quad n_3 = [1.5,\ 0.0,\ 1.0]

Average coordinate by coordinate. Polite center: [(1.0+1.5+0.5)/3, (2.0+1.5+2.5)/3, (0.5+1.0+1.5)/3]=[1.0, 2.0, 1.0]\left[(1.0 + 1.5 + 0.5)/3,\ (2.0 + 1.5 + 2.5)/3,\ (0.5 + 1.0 + 1.5)/3\right] = [1.0,\ 2.0,\ 1.0]. Rude center: [(2.0+2.5+1.5)/3, (0.5+1.0+0.0)/3, (1.5+0.5+1.0)/3]=[2.0, 0.5, 1.0]\left[(2.0 + 2.5 + 1.5)/3,\ (0.5 + 1.0 + 0.0)/3,\ (1.5 + 0.5 + 1.0)/3\right] = [2.0,\ 0.5,\ 1.0]. Subtract:

v=[1.0−2.0, 2.0−0.5, 1.0−1.0]=[−1.0, 1.5, 0.0]v = [1.0 - 2.0,\ 2.0 - 0.5,\ 1.0 - 1.0] = [-1.0,\ 1.5,\ 0.0]

Notice the third entry. Both piles averaged to 1.01.0 there, so the difference is exactly zero. That entry carried the shared topic, and subtraction deleted it. The arrow kept only what the piles disagreed on.

Its length is ∥v∥=1.0+2.25+0.0=3.25≈1.8028\lVert v \rVert = \sqrt{1.0 + 2.25 + 0.0} = \sqrt{3.25} \approx 1.8028, so the unit version is v^≈[−0.5547, 0.8321, 0.0]\hat{v} \approx [-0.5547,\ 0.8321,\ 0.0]. Same direction, length 11, ready for a knob measured in plain steps.

Inject it with a strength knob

During one forward pass, at your chosen layer, replace the live state hh with:

h′=h+αv^h' = h + \alpha \hat{v}

You run the rest of the pass from h′h' (h-prime). Weights never change, and the next prompt starts clean.

Take h=[0.5, 0.5, 2.0]h = [0.5,\ 0.5,\ 2.0] with α=1.0\alpha = 1.0. Then h′=[0.5−0.5547, 0.5+0.8321, 2.0+0.0]≈[−0.0547, 1.3321, 2.0]h' = [0.5 - 0.5547,\ 0.5 + 0.8321,\ 2.0 + 0.0] \approx [-0.0547,\ 1.3321,\ 2.0]. The second entry, the polite axis, rose from 0.50.5 to about 1.331.33 while the shared third entry sat still at 2.02.0. Score any state by its projection v^⋅h\hat{v} \cdot h: before it is about 0.140.14, after about 1.141.14. Adding αv^\alpha \hat{v} raises that score by exactly α\alpha, every time, because v^⋅v^=1\hat{v} \cdot \hat{v} = 1. That exactness is why unit length matters.

Sweep α\alpha upward from small values on held-out prompts and keep the smallest one that moves the behavior. Small α\alpha shifts register. Large α\alpha drags the state somewhere the later layers never saw during training, and grammar breaks before the attitude improves further.

This rests on one assumption, the linear representation hypothesis: the concept varies along a single straight direction. When a behavior is tangled across many directions or means different things in different contexts, one arrow cannot hold it, and that is when you reach for sparse autoencoders instead. And know what steering is not for. A per-pass nudge cannot teach facts the weights never learned, and it cannot hold a rule across sessions. Lasting change is fine-tuning or guardrails. Reading states without touching them is the logit lens.

Code

The snippet below replays the worked example: build the arrow from two piles, normalize it, steer one state. It needs only numpy.

import numpy as np
polite = np.array([[1.0, 2.0, 0.5], [1.5, 1.5, 1.0], [0.5, 2.5, 1.5]])rude = np.array([[2.0, 0.5, 1.5], [2.5, 1.0, 0.5], [1.5, 0.0, 1.0]])
v: np.ndarray = polite.mean(axis=0) - rude.mean(axis=0)v_hat: np.ndarray = v / np.linalg.norm(v)
h: np.ndarray = np.array([0.5, 0.5, 2.0])h_steered: np.ndarray = h + 1.0 * v_hat
print(np.round(v, 4))          # -> [-1.   1.5  0. ]print(np.round(v_hat, 4))      # -> [-0.5547  0.8321  0.    ]print(np.round(h_steered, 4))  # -> [-0.0547  1.3321  2.    ]

Three things to check in the output. The third entry of vv is 00, the shared topic cancelling exactly as the prose promised. The steered state's second entry moved while its third sat still. And the politeness projection rose by exactly 1.01.0, the α\alpha you chose, because v^\hat{v} has length 11.

Watch Out For

Your vector steers length, not the behavior

The classic bad pair: polite examples that are long against rude ones that are short, or refusals (two sentences) against helpful answers (ten paragraphs). Subtraction keeps whatever the piles differ on most, and length differences usually dwarf attitude differences. Your arrow points at verbosity.

The symptom is unmistakable once you know it. Steering changes answer length or formatting while the stance barely moves, and sweeping α\alpha just makes outputs longer or shorter until they break. Flip the sign of α\alpha as a test: if negative steering also mostly changes length, you built a length vector.

Fix it in the data, not the math. Rebuild the piles as minimal pairs: same template, same topic, same length, differing only in the target behavior. Then confirm on held-out prompts that α\alpha moves the attitude with length held roughly constant.

Cranking the strength until the model babbles

A small α\alpha does nothing visible, so the temptation is to keep turning it up. Past some point the steered state lands where later layers never trained, and the output falls apart: repetitions, broken grammar, then fluent text in the wrong register. It looks like the method failing when it is the dose failing.

The fix is a sweep, not a value. Start near zero, raise α\alpha in small steps on held-out prompts, and stop at the smallest strength that reliably moves the target behavior. Always steer with the unit vector v^\hat{v} so a strength of 1.01.0 means the same step for every arrow you build. And remember the effect lasts exactly one pass: if you need the rule to hold tomorrow, you need training or guardrails, not a bigger α\alpha.

The Quick Version

  • A steering vector is the center of a wanted pile of hidden states minus the center of its opposite pile.
  • Subtraction cancels what the piles share, like topic and grammar, and keeps what differs, the behavior.
  • Scale the arrow to length 1 so the strength knob means the same step size for every vector you build.
  • Inject it for one forward pass as h+αv^h + \alpha \hat{v}; the behavior score rises by exactly α\alpha.
  • Match your piles on everything except the target, or you will steer the confound instead.
  • Sweep the strength upward and keep the smallest value that works; large values break fluency first.