Contrastive Activation Addition (CAA)
Representation engineering treats safety not as a prompt-engineering problem, but as an internal activation steering problem. Contrastive Activation Addition (CAA) calculates the difference in mean hidden states between pairs of positive and negative behaviors (e.g., honest vs deceptive, safe vs harmful) and injects this vector at inference time to steer model behavior without changing model weights.
Steering Vector Extraction
Given pairs of prompts (e.g., 'Be helpful and honest' vs 'Be deceptive'), activations are extracted at intermediate transformer layers. The steering vector v_steer is the difference between the mean positive activations and mean negative activations.
Inference-Time Activation Clamping
During the forward pass of generation, the hidden state h_l at target layer l is replaced with h_l' = h_l + coeff * v_steer. A positive coefficient amplifies the desired behavior (e.g., harmlessness), while a negative coefficient suppresses it.
Layer Specificity
Steering is most effective in middle-to-late transformer layers (e.g., layers 14–24 in a 32-layer model), where abstract semantic concepts and intent representations are synthesized before token detokenization.
Where D_pos and D_neg are contrastive prompt datasets, h_l(x) is the activation vector at layer l, and c is the steering multiplier. Adding c * v_steer shifts the latent trajectory in activation space toward the target safety concept.
- Calibrate the steering coefficient c carefully: too low (c < 0.5) has no effect; too high (c > 2.5) causes linguistic incoherence and gibberish generation.
- Extract steering vectors across a diverse dataset of at least 50–100 contrastive pairs to avoid overfitting to specific syntactic prompt artifacts.
- Use CAA in production inference serving engines via custom vLLM / PyTorch forward hooks to enforce safety policies with zero extra latency.