Table of Contents
Fetching ...

Steering Code LLMs with Activation Directions for Language and Library Control

Md Mahbubur Rahman, Arjun Guha, Harshitha Menon

Abstract

Code LLMs often default to particular programming languages and libraries under neutral prompts. We investigate whether these preferences are encoded as approximately linear directions in activation space that can be manipulated at inference time. Using a difference-in-means method, we estimate layer-wise steering vectors for five language/library pairs and add them to model hidden states during generation. Across three open-weight code LLMs, these interventions substantially increase generation toward the target ecosystem under neutral prompts and often remain effective even when prompts explicitly request the opposite choice. Steering strength varies by model and target, with common ecosystems easier to induce than rarer alternatives, and overly strong interventions can reduce output quality. Overall, our results suggest that code-style preferences in LLMs are partly represented by compact, steerable structure in activation space.

Steering Code LLMs with Activation Directions for Language and Library Control

Abstract

Code LLMs often default to particular programming languages and libraries under neutral prompts. We investigate whether these preferences are encoded as approximately linear directions in activation space that can be manipulated at inference time. Using a difference-in-means method, we estimate layer-wise steering vectors for five language/library pairs and add them to model hidden states during generation. Across three open-weight code LLMs, these interventions substantially increase generation toward the target ecosystem under neutral prompts and often remain effective even when prompts explicitly request the opposite choice. Steering strength varies by model and target, with common ecosystems easier to induce than rarer alternatives, and overly strong interventions can reduce output quality. Overall, our results suggest that code-style preferences in LLMs are partly represented by compact, steerable structure in activation space.
Paper Structure (13 sections, 2 equations, 7 figures)

This paper contains 13 sections, 2 equations, 7 figures.

Figures (7)

  • Figure 1: CodeGemma-7B: Output distribution across language/library pairs under neutral prompts, with and without directional-vector interventions.
  • Figure 2: Qwen2.5-Coder-7B: Output distribution across language/library pairs under neutral prompts, with and without directional-vector interventions.
  • Figure 3: Llama3.1-8B: Output distribution across language/library pairs under neutral prompts, with and without directional-vector interventions.
  • Figure 4: Effect of intervention strength $\alpha$ on steering performance in the Matplotlib--Seaborn task. Larger $\alpha$ increases target-direction generation, but excessive strength leads to repetitive or incomplete outputs.
  • Figure 5: Codegemma-7B: Output distribution when directional-vector interventions are applied against prompts that request the opposite language or library.
  • ...and 2 more figures