Manuscript Offprint

arXiv:2610.13895

Task Context Shapes Component Roles in Language Models

Sovesh Mohapatra, Dani S Bassett

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Large language models reuse the same attention heads across tasks, but identifying these shared heads does not explain what they do differently in each task. A natural source of inspiration is task-dependent interactions among shared brain regions, which motivate a network view of language-model computation. Here, we compare fixed model components across tasks using identical graph facts, statements specifying which directed connections are present. We measure how interventions affect attention heads and the activation state in later layers (influence), as well as the answer (importance). Task changes redistribute the influence in five open-weight models spanning four families and 1.5–14 billion parameters. In Gemma-2-9B and Qwen3-14B, an activation edit changes an early internal activation vector and switches which fact the model reads while the written instruction stays fixed. The same heads then respond to different graph facts and influence later components differently. For each prompt, we construct two linear response maps, one before the edit and one after it. Each map predicts a later head's response from a measured change in an earlier head. For a separate factual intervention, the map for the corresponding condition reduces mean squared prediction error by 53.6% in Gemma and 5.0% in Qwen compared with the average of the two maps. These findings show that task context changes both which graph facts the shared components respond to and how their outputs affect later computation. A network account may help explain how models use shared parameters to perform different computations. Measurements of task-dependent influence could also guide interventions intended to alter one behavior while preserving others.

1 INTRODUCTION

Large language models can perform different tasks with a single set of parameters. Instructions or a few in-context examples specify the task at inference time, without further parameter updates (Brown et al., 2020; Wei et al., 2022). Circuit analyses show that different tasks can reuse attention heads and substantial parts of the same circuit (Merullo et al., 2024a). A small number of heads can also carry a compact representation of the task demonstrated in context (Todd et al., 2024). Two aspects of a shared head's computation may change across tasks: that is, which facts it responds to and how its output affects later components.

Network neuroscience provides a related perspective on how shared components support different tasks, focusing on interactions among brain regions (Bassett & Sporns, 2017). The same regions can participate in different tasks, while the relationships between their activity change with the task (Cole et al., 2013; Krienen et al., 2014). These relationships, known as functional connectivity, can help distinguish the task being performed (Gonzalez-Castillo et al., 2015). In language models, functional networks have similarly been identified from groups of neurons that repeatedly become active together. Suppressing selected networks impairs performance, whereas amplifying their activity can improve performance on some tasks (Liu et al., 2025). Tasks in the same cognitive domain, such as language or social reasoning, also share more task-relevant model neurons than tasks in different domains (Han et al., 2026). Mechanistic circuit analyses complement this network perspective by examining how individual model components affect later computation and the answer.

∗^{*}Corresponding author: dani.bassett@yale.edu.

Circuit discovery identifies components and interactions that support specific model behaviors (Wang et al., 2023; Conmy et al., 2023; Marks et al., 2025). Some interactions between earlier and later heads can also be predicted from their weight matrices (Merullo et al., 2024b). Interventions on internal task representations can make a model perform a task on new inputs (Todd et al., 2024). Attention heads also help identify possible output labels (Yang et al., 2026) and suppress information that is irrelevant to the task (Cho et al., 2026). A central question remains: when the graph facts are held fixed, does changing the task alter which facts the same components respond to and how their outputs influence later components?

A Same components, different interactions

B Measure task-dependent influence

Figure

C Change the internal task state

Same prompt

Same model weights

Read answer

Figure

Figure 1: Task-dependent computation with shared components. A. Same components, different interactions. Brain networks motivate the hypothesis that shared model components support different tasks through changes in their interactions. H1–H3 denote fixed attention heads in layer order; Res. denotes a later residual-stream site. B. Measure task-dependent influence. Identical graph facts yield True for Compose path and False for Read direct edge: the path A→B→CA \rightarrow B \rightarrow C exists, whereas the direct edge A→CA \rightarrow C is absent. Under each instruction, source perturbations ±δ\pm\delta produce responses at later sites that quantify influence, with intervening computation active. C. Change the internal task state. An early activation edit changes hh to h′=h+Δtaskh' = h + \Delta_{task} while the prompt and model weights remain fixed. The vector Δtask\Delta_{task} is the mean activation under Read fact 2 minus the mean activation under Read fact 1 on reference prompts. R1 and R2 denote two fixed attention heads. The schematic illustrates an answer change from True (Fact 1) to False (Fact 2), while the written instruction remains Read fact 1.

Here, we compare the same model components across tasks that use the same graph facts (Figure 1A). For example, one task checks whether a path A→B→CA \to B \to C exists, while another checks whether the direct edge A→CA \to C exists (Figure 1B). We measure each component's influence on later components and its importance for the answer. An early activation edit in Gemma-2-9B and Qwen3-14B switches the models between tasks that read different graph facts, while the task instruction and model parameters remain fixed (Figure 1C). Our main findings are:

  1. Influence changes with the task. Across the five models, changing the task changes the influence pattern among the same selected components while the graph facts remain fixed.

  2. Task context changes factual responses and influence. In Gemma and Qwen, factual interventions affect the answer more strongly when the targeted graph fact is relevant to the task. An early activation edit also changes which graph facts the same heads respond to and how their outputs influence later components, while the task instruction stays fixed.

  3. Task context improves prediction of later responses. Within the same prompt, the response map for the edited or unedited condition predicts a later head's response to a separate factual intervention more accurately than the average of the two maps. In Gemma and Qwen fine-tuned on graph tasks, a fixed perturbation to an earlier head produces a larger mean squared response in a later head when the targeted graph fact can affect the answer.

References (91)

  • Network neuroscience
  • Mechanism of task-oriented information removal in in-context learning
  • Multi-task connectivity reveals flexible hubs for adaptive task control
  • Activity flow over resting-state networks shapes cognitive task activations (opens the publisher in a new tab)
  • Towards automated circuit discovery for mechanistic interpretability
  • Transcoders find interpretable LLM feature circuits (opens the publisher in a new tab)
  • Gemma 2: Improving Open Language Models at a Practical Size
  • Tracking ongoing cognition in individuals using brief, whole-brain functional connectivity patterns
  • The Llama 3 Herd of Models
  • Modular cognitive architecture emerges in large language models (opens arXiv in a new tab)
  • In-context learning creates task vectors
  • LoRA: Low-rank adaptation of large language models
  • Reconfigurable task-dependent functional coupling modes cluster around a core functional architecture
  • Brain-inspired exploration of functional networks and key neurons in large language models (opens arXiv in a new tab)
  • Context-dependent computation by recurrent dynamics in prefrontal cortex
  • Sparse feature circuits: Discovering and editing interpretable causal graphs in language models
  • Circuit component reuse across tasks in transformer language models
  • Talking heads: Understanding inter-layer communication in transformer language models
  • Task state representations in vmPFC mediate relevant and irrelevant value signals and their behavioral influence (opens the publisher in a new tab)
  • Steering Llama 2 via contrastive activation addition
  • Function vectors in large language models
  • Steering Language Models With Activation Engineering
  • Investigating gender bias in language models using causal mediation analysis
  • Interpretability in the wild: A circuit for indirect object identification in GPT-2 small
  • Finetuned language models are zero-shot learners
  • Qwen3 Technical Report
  • Localizing task recognition and task learning in in-context learning via attention head analysis
  • Towards best practices of activation patching in language models: Metrics and methods
  • Jingwei Zuo, Maksim Velikanov, Ilyas Chahed, et al. Falcon-H1: A family of hybrid-head language models redefining efficiency and performance. arXiv preprint arXiv:2507.22448, 2025. (opens arXiv in a new tab)
  • A → B: absent
  • The opposite-answer graphs have a complete path without the direct edge, or the direct edge without a complete path
  • Is the explicit edge Pibepaka -> Karaduki present?
  • The following Read fact 1 example uses the same system message
  • Compose path and the AND task require True on two graphs and False on six
  • Gemma receives the system instruction and graph prompt in a single user message, while Qwen, Llama, and both Falcon-H1 variants receive separate system and user messages
  • Figure 2 uses eight additional groups for Falcon-H1-1.5B and 16 for each remaining model
  • Each group contains 192 prompts across eight graphs, two instructions, two response keys, three assignments of node names, and two fact wordings
  • Each group contains 64 prompts covering all eight graphs, both fact-reading instructions, both response keys, and two statement orders
  • The AND instruction refers to $B \rightarrow C$ and $A \rightarrow C$, with each edge targeted in turn
  • Gemma answers 119/128 prompts correctly, Qwen 125/128, and Llama 116/128
  • Across both instructions and fact wordings, Gemma answers 2,284/2,304 prompts correctly (99.1%) and Qwen 2,257/2,304 (98.0%)
  • Fine-tuned Gemma answers 767/768 correctly (99.9%), and Qwen 765/768 (99.6%)
  • Gemma answers all 64 True and 192 False prompts correctly
  • Within each range, heads are ranked by the standardized separation between reference activations for prompts requiring True and False answers
  • The selected site has the largest standardized separation between task instructions, evaluated by leaving out one reference vocabulary group at a time
  • For site i, $\mu_{i,t,y}$ is the mean activation under task t with correct semantic answer y
  • The standard deviation uses denominator $N - 1$ for $N$ reference prompts
  • Influence is calculated from the recipient coordinates using the definition in Section 2.2
  • The margin decrease follows Section 2.2
  • The changed residual activations span the complete fact statement, including the node names, relation, and presence or absence statement
  • The other facts, node names, and statement order remain identical
  • Their difference supplies the intervention:
  • The superscript base denotes the unaltered run, and v denotes the factual displacement or either source control
  • The Compose path answer then depends on $A \to B$, while the Read direct edge answer is independent of that edge
  • For each source variant, we apply the original restoration displacement and its two randomized versions to the corresponding later state in separate runs
  • The quantities $T_f^{intact}$, $T_f^{restore}$, and $T_f^{(k)}$ denote selectivity without a downstream intervention, under restoration, and under restoration control $k$
  • Selectivity falls to 6.43 [6.06, 6.83] under restoration and averages 13.30 [12.88, 13.68] under the restoration controls
  • Is the edge in Fact 1 present?
  • A. Factual effects follow task relevance
  • The residual vectors across the edited positions are concatenated for this calculation
  • Positive scores indicate a shift toward the alternative fact
  • Each band's statistic is the median of its heads' mean reassignment scores
  • Under Read fact 1, the reference direction at each site is the mean activation difference between Fact 1 being present and absent
  • The source shifts use the standardized two-unit procedure in Section 2.2
  • Each profile is averaged before its squared distance is calculated, and the two edit-direction distances are then averaged within each vocabulary group
  • The controlled contribution in Figure 4D is
  • Effects are averaged within each vocabulary group and edit direction, followed by equal averages across directions and groups
  • Each prompt provides an unedited map and a task-edited map, denoted $M_e$ for internal condition $e$
  • The paired absolute reductions are 0.00863 [0.00817, 0.00909] and 0.00521 [0.00379, 0.00663], respectively, retaining the four-comparison correction in Appendix G. Both corrected difference intervals exclude zero
  • For the third fact, the absolute error differences are below 0.00022, with Qwen's unedited mean favoring the averaged map
  • The H2–H3 pairs remain unchanged, while the early task displacement and factual directions are estimated from reference activations in each fine-tuned checkpoint
  • The paired absolute reductions are 0.00789 [0.00743, 0.00834] and 0.00194 [0.00075, 0.00314], respectively, retaining the 12-comparison correction in Appendix G. Both corrected difference intervals exclude zero
  • The task-specific map reduces error relative to this baseline by 0.03231 [0.03105, 0.03357] in Gemma and 0.01513 [0.01287, 0.01739] in Qwen
  • $(A \to B, B \to C)$ and $(B \to C, A \to C)$
  • The base weights remain frozen in bfloat16, while the adapter parameters use float32
  • The targeted edge is initially absent in both contexts
  • The reference pair preserves the remaining fact, instruction, response key, and prompt layout
  • Both preserve the displacement’s norm
  • Qwen's corresponding effects are 0.02922 [0.01337, 0.04508] and 0.01717 [0.00779, 0.02656]
  • Bootstrap resampling retains all paired conditions within each selected group
  • Each resample preserves both task instructions and both measurements
  • Each of 10,000 bootstrap resamples preserves all paired conditions within each vocabulary group
  • Each resample provides the largest absolute deviation across comparisons, with deviations divided by the corresponding standard errors from the original sample
  • The function $t_{15}(p)$ gives the $p$-quantile of a Student- $t$ distribution with 15 degrees of freedom
  • The depth-band analysis uses its original 100,000 paired resamples and pointwise 97.5% intervals
  • Each resample recalculates both margins and their paired decrease in each model
  • Each of 100,000 paired bootstrap resamples recalculates both means from the same vocabulary groups
  • The three mean errors in each model receive pointwise 95% intervals
  • Their percentage reductions use 100,000 paired resamples with Bonferroni correction across the two fine-tuned model ratios
  • The adjusted test compares the factual displacement's context difference with the mean context difference under the permutation and sign-flip controls
  • four control-adjusted fact means and two between-fact differences