Task Vector Geometry Underlies Dual Modes of Task Inference in Transformers

arXiv stat.ML / 5/6/2026

💬 OpinionIdeas & Deep AnalysisModels & Research

Key Points

  • The paper investigates how transformers infer latent tasks from context using two modes: recognizing previously trained tasks and adapting to novel ones.
  • Building on prior interpretability work that finds “task vectors” in middle-layer representations, the study provides a more rigorous theoretical link between internal task-vector geometry and external behavior.
  • Using small transformers trained from scratch on synthetic latent-task sequence distributions, the authors derive a mathematical characterization of how training affects task-vector geometry.
  • They report that in-distribution inference is driven by Bayesian task retrieval via convex combinations of learned task vectors, while out-of-distribution generalization comes from extrapolative task learning using representations that lie in a subspace nearly orthogonal to the task-vector space.
  • Overall, the results connect training distributions, task-vector geometry, and OOD generalization in a single unified framework, explaining why dual inference modes can coexist in one model.

Abstract

Transformers are effective at inferring the latent task from context via two inference modes: recognizing a task seen during training, and adapting to a novel one. Recent interpretability studies have identified from middle-layer representations task-specific directions, or task vectors, that steer model behavior. However, a lack of rigorous foundations hinders connecting internal representations to external model behavior: existing work fails to explain how task-vector geometry is shaped by the training distribution, and what geometry enables out-of-distribution (OOD) generalization. In this paper, we study these questions in a controlled synthetic setting by training small transformers from scratch on latent-task sequence distributions, which allows a principled mathematical characterization. We show that two inference modes can coexist within a single model. In-distribution behavior is governed by Bayesian task retrieval, implemented internally through convex combinations of learned task vectors. OOD behavior, by contrast, arises through extrapolative task learning, whose representations occupy a subspace nearly orthogonal to the task-vector subspace. Taken together, our results suggest that task-vector geometry, training distributions, and generalization behaviors are closely related.

Task Vector Geometry Underlies Dual Modes of Task Inference in Transformers | AI Navigate