Inferensys

Glossary

Function Vector

A compact representation derived from in-context examples that can be injected into a model's activations to trigger a specific input-output task behavior without the original prompt.
Engineer reviewing vector database search results on laptop, embeddings visualization on screen, home office coding session.
MECHANISTIC INTERPRETABILITY

What is a Function Vector?

A function vector is a compact representation of a task derived from in-context examples that can be injected into a model's activations to trigger a specific input-output behavior without the original prompt.

A function vector (FV) is a compact, causal representation of a specific input-output task extracted from the internal activations produced by a set of in-context learning (ICL) examples. Rather than requiring the original few-shot prompt, this vector summarizes the algorithmic function the model has inferred—such as a grammatical transformation or a lexical mapping—into a single activation direction. When this vector is added to the model's residual stream during a forward pass on a novel query, it causally triggers the target task behavior, effectively acting as a compressed, injectable program.

The discovery of function vectors emerged from causal mediation analysis on transformer attention heads, particularly by identifying a small set of heads whose outputs encode the task function independently of the specific example tokens. By averaging the activations of these heads across diverse ICL demonstrations, researchers produce a robust vector that generalizes to unseen inputs. This technique demonstrates that in-context learning compiles explicit examples into an internal, reusable task representation, bridging the gap between prompting and activation engineering.

MECHANISTIC INTERPRETABILITY

Core Characteristics of Function Vectors

Function vectors are compact, causal internal representations that summarize a task from in-context examples and can be injected into a model to trigger that behavior without the original prompt.

01

In-Context Task Compression

A function vector (FV) is formed by extracting and aggregating the activation deltas produced by a set of in-context examples. It compresses the input-output mapping demonstrated in the prompt into a single, compact representation. This vector captures the abstract function rather than the specific tokens, allowing the model to apply the task to novel inputs.

02

Causal Intervention Mechanism

Function vectors are applied via activation engineering: they are added directly to the residual stream at specific token positions during a forward pass. This is a causal intervention that hijacks the model's computation. Key properties include:

  • Summation: The FV is simply added to existing activations.
  • Position: Typically applied at the final token position before generation.
  • Layer Specificity: Effective FVs are often extracted from and applied to a narrow range of middle layers.
03

Robustness to Input Variation

Unlike prompt-based few-shot learning, a function vector is remarkably robust to the specific formatting or lexical choices of the target input. Because it encodes the abstract algorithm (e.g., 'perform antonym generation') rather than surface-level patterns, it generalizes across different input templates, synonyms, and even slight task rephrasings without needing new examples.

04

Natural Task Vectors (NTVs)

A closely related concept is the Natural Task Vector, which is derived not from explicit input-output pairs but from a single, open-ended task definition prompt (e.g., 'Translate to French:'). The NTV is computed as the difference in activations between the task prompt and a neutral baseline. It demonstrates that models internally represent task intent as a directional vector in latent space.

05

Distinction from Prompting

Function vectors differ fundamentally from in-context learning prompts:

  • Prompting: Relies on attention heads (specifically induction heads) to dynamically copy and map patterns from the context window at every generation step.
  • Function Vectors: Bypass this dynamic attention mechanism by directly setting the model's computational state. The model no longer needs to 'read' the examples; it is already configured to execute the task.
06

Extraction Methodology

The standard extraction process involves a causal mediation analysis:

  1. Run the model on a set of few-shot examples and record the residual stream activations at a target layer.
  2. Run the model on a null or baseline prompt.
  3. Compute the activation delta (task activation minus baseline activation).
  4. Average these deltas across all example tokens to produce the final function vector. This isolates the task-specific signal from the background linguistic processing.
FUNCTION VECTORS EXPLAINED

Frequently Asked Questions

Concise answers to the most common technical questions about function vectors, their mechanisms, and their role in mechanistic interpretability.

A function vector (FV) is a compact, causal representation derived from a small set of in-context learning examples that, when injected into a model's forward pass, triggers a specific input-output task behavior without the original prompt. It works by computing the average difference in the residual stream activations between a prompted and a baseline input across multiple examples, isolating the task-specific computation. This vector is then added to the model's activations at a specific layer, effectively 'steering' the model to perform the task on a zero-shot input. Unlike prompt engineering, the function vector represents the internal algorithm the model learned to solve the task, making it a powerful tool for mechanistic interpretability and causal intervention.

MECHANISTIC INTERPRETABILITY COMPARISON

Function Vectors vs. Related Concepts

Distinguishing function vectors from other activation-based intervention and representation techniques in transformer models.

FeatureFunction VectorSteering VectorProbing Classifier

Primary Purpose

Trigger a specific input-output task behavior

Modify model behavior along a conceptual direction

Detect if information is linearly encoded in activations

Derivation Source

Averaged activations from in-context examples

Contrastive pairs of activations or curated prompts

Supervised training on labeled activation datasets

Causal Intervention

Requires Original Prompt at Runtime

Modifies Model Output

Typical Injection Location

Residual stream at specific token positions

Residual stream across all layers

Read-only access to intermediate activations

Interpretability Goal

Extract and replay a compact task algorithm

Induce a behavioral property like refusal or sycophancy

Audit what concepts are linearly separable

Dependency on In-Context Learning

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.