Goal Encoding in LLMs
Arnab Sen Sharma, Eric Todd, Sheridan Feucht, Andy Arditi, Rohit Gandikota, Natalie Shapira, et al.
arXiv:2611.17297v1Do large language models have goals in any meaningful internal sense, or do they only produce goal-like behavior from the outside? That is the central question this paper asks. And it matters because we often describe intelligent systems in intentional terms: we say they want, intend, plan, or decide. But for language models, that kind of language can be misleading unless there is some internal representation that actually corresponds to the goal and helps drive action. The authors focus on a more operational definition of a goal. They borrow from planning theory and treat a goal as something that is pre-committed to before action, plastic enough to be realized in different ways depending on the environment, and persistent enough to keep guiding execution over time. That gives them a concrete way to ask whether an LLM is merely producing the right next token, or whether it is carrying an internal sub-goal that shapes what comes next. They study this in a coding setting, because code generation naturally decomposes into multi-step tasks. If the overall job is something like implementing merge sort, then there are intermediate sub-goals: split the array, sort each half, merge the results. Those are useful because they let the researchers ask whether the model has already committed to the next sub-goal before it starts writing it, whether that sub-goal can be transferred across environments like Python and C++, and whether the same internal encoding persists while the model is actually carrying out the step. To make this precise, they build controlled prompts that specify several sub-tasks in sequence. They then look at token positions just before the model begins the next sub-goal. These positions are called pivots. By pre-filling the prompt up to a pivot, they can inspect the model’s internal state at the moment when the next sub-goal should already be selected, but before the implementation begins. That lets them compare what is encoded internally with what the model later does in generated text. The broader technical backdrop here is the transformer architecture. A transformer language model builds each next-token prediction from a residual stream updated by attention heads and MLPs across layers. Attention heads can be especially interesting because they can move information from earlier tokens into the current computation. The paper’s question is whether some attention heads carry a portable representation of the next sub-goal — something abstract enough to outlive a particular syntax choice, but specific enough to determine the next action. The authors first localize what they call goal heads. They do this by constructing source and destination prompts that ask for different predicates on the same data type, but in different programming languages. For example, a source prompt might ask for a palindrome check in C++, while a destination prompt asks for duplicate characters in Python. They then cache internal activations from the source run and learn a sparse mask over attention heads in the destination run. The objective is to find which heads, when transplanted, cause the destination model to begin implementing the source predicate instead of its own. In other words, they are searching for heads whose outputs contain an abstract encoding of the upcoming operation, not just the exact token sequence. After optimization, they binarize the mask and call the selected heads the goal heads. In their main setup, they identify 122 such heads, distributed across layers 28 through 55 in a 64-layer Qwen-2.5-Coder-32B-Instruct model. That detail matters because it suggests the encoding is not isolated in one tiny region of the network, but spread across a sparse set of heads in the upper-middle to upper layers. Once they have these heads, they build a probe they call GoalScope. The idea is simple: take what the selected heads write to the residual stream at the pivot, sum those contributions into one vector, and inject that vector into a separate run of the same model that has been given a generic verbalizer prompt, something like asking what operation is being performed. Since the verbalizer run does not contain the source context, any useful information has to come from the injected activation. The result is a lightweight readout that can turn the internal encoding into a natural-language description of the upcoming sub-goal. They evaluate this in two ways. First is faithfulness: does the readout correctly describe a meaningful part of the model’s upcoming behavior? Because they know the ground-truth sub-goal in their controlled setting, they can compare the verbalization to the actual implementation that follows. Second is causality: if they transplant the same encoding into a different code stub, even in a different programming language, does it trigger a nontrivial part of the source operation there too? That second test is important because it checks plasticity, not just interpretability. The results in this section are striking. The next sub-goal becomes decodable well before the model begins to implement it. In other words, the internal representation shows up at the pivot positions before the generated code reaches the point where the sub-goal is written out. And when they transplant that encoding into another language, it can steer the model toward the same operation, but realized through a different token sequence suited to the new environment. That is exactly the kind of plasticity the authors wanted to test. They also find that the same goal-head encoding can be read out as a natural-language description of the upcoming action. So the internal state is not just predictive of the next token distribution; it can be interpreted as something like “I’m checking whether a word is a palindrome” or another similar sub-goal description. The paper emphasizes that this is not just a probe artifact, because the same encoding has causal effects when transplanted. The next question is persistence. If the model has a goal encoding at the start of a sub-task, does that same encoding remain available while the model executes the sub-task over many generated tokens? Empirically, they find that it does. The goal heads continue to sustain the encoding throughout execution. But this creates a puzzle. A transformer language model has no recurrence in the usual sense. Information can only move forward through layers, and a token position only has a finite number of layers available to influence later positions. So how can a goal encoded at one point keep affecting tokens many steps later? The authors argue that the model may not be carrying the goal forward as a persistent hidden state at all. Instead, they propose a non-recurrent goal-seeking account, or NRGS. Under this view, the model repeatedly re-derives the goal from the task specification in the prompt, re-encodes the current progress from the growing context, and chooses the next action by comparing the two. So the goal is not a single state handed off through time; it is reconstructed at each step from the prompt and the partial solution so far. To test that idea, they use targeted causal interventions. They control what the goal heads read from the task span in the middle of implementing a sub-goal. If they alter that readout, they can redirect the model toward a different sub-goal. Importantly, this works across programming languages, which supports the idea that the encoding is abstract rather than tied to a specific surface form. The same intervention also works consistently across different levels of the goal hierarchy, suggesting the mechanism generalizes beyond one narrow kind of sub-task. What do these experiments actually show? First, they show that in these controlled coding tasks, the model contains a decodable internal representation of the next sub-goal before execution starts. Second, that representation is causally relevant: if you transplant it, you can steer behavior. Third, it is plastic: the same abstract operation can be realized in a different language with different syntax and token sequences. And fourth, the model seems to sustain this encoding during execution, but the authors argue this does not require a recurrent hidden state. A repeated read-from-prompt, compare-with-progress mechanism may be enough. There are also some useful broader implications. The authors note that although they localize goal heads in code generation, their readouts can be informative in non-code settings too, such as verbalizing the implicit rule in a few-shot prompt or the intentions of a misaligned model. That suggests the mechanism may be more general than coding alone. At the same time, there are clear limitations. The study is done in a controlled setting with specific multi-step coding prompts, so we should be careful about overgeneralizing to open-ended real-world tasks. The models they analyze do not robustly show obstacle persistence in the sense of maintaining a goal despite unexpected disruptions. And while the causal interventions are persuasive, they are still tied to the particular architecture, model scale, and task design used here. So the main takeaway is nuanced. The paper does not claim that LLMs have human-like intentions. Instead, it shows that at least in these coding tasks, they can encode something that behaves like a goal in a functional sense: it is present before action, portable across environments, and causally linked to what the model does next. The authors then offer a plausible explanation for how that can happen in a transformer without recurrence: the model may be re-reading and re-deriving the goal as it goes, rather than carrying one uninterrupted internal plan forward.
Also spotted that day
Previous daily papers