Ultralytics YOLO27:
License YOLO
Back to Ultralytics Glossary

Steering Vectors

Steering vectors are directions in a model's activation space that shift its behavior when added during inference, with no retraining. Methods and code.

A steering vector is a direction in a neural network's activation space that corresponds to a concept or behavior, such as positive sentiment, refusal, or flattery. Adding a scaled copy of the vector to the network's hidden activations during the forward pass pushes the output toward that behavior, and subtracting it pushes the output away, while the model weights stay unchanged. The technique belongs to activation engineering and is mostly applied to large language models (LLMs), where it relies on the observation that many high-level concepts are represented as roughly linear directions in the residual stream, the running sum of activations that each transformer layer reads from and writes to.

How Steering Vectors Are Built and Applied#

The most common recipe is a difference of means. Researchers run pairs of contrasting inputs through the model, one that shows the behavior and one that does not, record the activations at a chosen layer, and average the differences. Activation Addition (ActAdd), introduced by Alexander Matt Turner and colleagues in 2023, showed that a single pair such as "Love" and "Hate" can steer the sentiment of GPT-2-XL. Contrastive Activation Addition (CAA) averages over many multiple-choice pairs to steer Llama 2 Chat toward or away from behaviors such as sycophancy, hallucination, and refusal, adding the vector at every token position after the user's prompt. Directions can also come from linear probes, from principal components of the differences, or from the features of a sparse autoencoder.

At inference, a hook adds the coefficient times the vector to the chosen layer's output. Intermediate layers usually steer best, and the coefficient sets the strength: too small has no visible effect, and too large degrades the text into repetition or nonsense.

The ActAdd experiment fits in a few lines of PyTorch with the 124-million-parameter GPT-2 from Hugging Face Transformers. A forward hook adds the "Love" minus "Hate" vector to the output of block 6 while the model completes a hostile prompt:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_pretrained("gpt2")
layer = 6


def activation(text):
    """Return the last token's activation at the output of the steering layer."""
    with torch.no_grad():
        outputs = model(**tokenizer(text, return_tensors="pt"), output_hidden_states=True)
    return outputs.hidden_states[layer + 1][0, -1]


# Steering vector: activation difference between a contrastive pair of prompts
steering_vector = activation(" Love") - activation(" Hate")
prompt = tokenizer("I hate you because", return_tensors="pt")

for coeff in [0.0, 1.0]:
    # Add the scaled vector to the layer's output at every position while generating
    hook = model.transformer.h[layer].register_forward_hook(
        lambda module, args, output: output + coeff * steering_vector
    )
    tokens = model.generate(**prompt, max_new_tokens=16, do_sample=False, pad_token_id=tokenizer.eos_token_id)
    hook.remove()
    print(f"coeff={coeff}: {tokenizer.decode(tokens[0])}")

Unsteered, the model continues "I hate you because I hate you. I hate you because I hate you." With the vector added at coefficient 1.0, the same greedy decoding continues "I hate you because you are a good person. I love you. I love you." The weights are identical in both runs; only the activations of one layer changed.

  • Task vectors: The difference between fine-tuned and original weights, added to a model to transfer a skill. Task vectors edit weights once, and steering vectors edit activations on every forward pass.
  • Representation engineering (RepE): The broader approach of reading and controlling a model through its internal representations. Steering vectors are its main control tool.
  • Prompt engineering: Guides behavior through the input text. Steering acts on internal activations, so it needs access to the model's internals and works only with open-weight models or the provider's own systems.
  • Fine-tuning: Changes behavior permanently by training the weights with gradient descent. Building a steering vector needs only forward passes on a handful to a few hundred examples.
  • Mechanistic interpretability: Explains how models compute. Steering is one of its tools for testing whether a direction it found actually causes a behavior.

Real-World Applications#

Steering vectors are a research tool for AI safety as much as a control method. In 13 open chat models up to 72 billion parameters, refusal is mediated by a single direction: erasing it stops the model from refusing harmful requests, and adding it makes the model refuse harmless ones, which shows how easily weight-level safety training can be undone in open models.

Truth-related directions reduce hallucinations. Inference-Time Intervention shifts the activations of a few attention heads along such directions, raising the Alpaca model's truthfulness on the TruthfulQA benchmark from 32.5% to 65.1%. Anthropic's persona vectors apply the same idea to character traits such as sycophancy, a propensity to hallucinate, and malicious intent, monitoring them in deployment, flagging training data that would strengthen them, and steering against them during fine-tuning. In reasoning models, vectors extracted from DeepSeek-R1-Distill models control reasoning behaviors such as expressing uncertainty, testing examples, and backtracking.

Vision models encode concepts as directions too, and the same recipe applies to the feature maps of a computer vision network. In Ultralytics YOLO26, model.embed() returns each image's average-pooled activations from any chosen layer, which gives the per-image activations needed to compute a mean-difference direction between two sets of images, such as daytime and nighttime scenes.

Limitations#

Steering is less reliable than its best demonstrations suggest. A study of the generalization and reliability of steering vectors by Daniel Tan and colleagues found that steerability varies widely from input to input, that spurious features of the contrastive prompts can drive the effect, and that small, reasonable changes to a prompt can make a vector stop working. Steering also costs fluency: in the ActAdd paper's sentiment experiments, the perplexity-based disfluency of steered text was 1.5 to 3 times that of unsteered text.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning