How Do Language Models Compose Functions?
Apoorv Khandelwal, Ellie Pavlick
NeurIPS page · OpenReview · alphaXiv · Open on the map
Category: LLM Reasoning, Memory & RAG › Diffusion Language Model Decoding · Type: empirical study · Keywords: language model compositionality, two-hop recall, embedding geometry, mechanism analysis, LLM reasoning
Areas: LLM Reasoning › Reasoning Mechanisms › Chain-of-Thought Reasoning
Summary
We investigate how feedforward language models solve two-hop factual recall tasks, discover a compositionality gap, and identify two distinct processing mechanisms-compositional and direct-linked to embedding space geometry.
Explained to a 5-year-old
Big computer programs called language models try to answer questions. Sometimes they need to do two things in a row, like first find a fact and then use it. The researchers found that even if the model could answer the first part, it often failed at the second part. By looking inside the model, they could see whether it was thinking about the middle step. Some models solved the problem by actually computing the middle step and then using it, while others took a shortcut without showing any sign of the middle step.
Explained to a 5-year-old, longer
A language model is a big computer program that can talk and answer questions. Sometimes you need to answer a question that has two parts, like first find a fact and then use that fact. The researchers wanted to see if the model really does the two parts one after another. They gave the model many two-step questions and watched what it did. They discovered that even if the model could answer the first part, it often failed at the second part. This gap between doing each step and doing both steps is called the compositionality gap. By looking inside the model, they could see whether it was thinking about the middle step. Some models solved the problem by actually computing the middle step and then using it. Other models solved it by taking a shortcut, without showing any sign of the middle step. The researchers also noticed that the way the model stores information in its memory mattered. When the stored information was arranged in a certain way, the model preferred the careful step-by-step method. When the arrangement was different, the model tended to take the shortcut.
For a technical reader
We tested large language models on tasks that require two sequential lookups, such as finding a fact and then using it. The models often failed the combined task even though they could perform each individual lookup correctly. By inspecting the internal representations, we identified two distinct solving strategies: one that explicitly computes the intermediate result and one that bypasses it. The geometry of the model’s embedding space strongly predicts which strategy is used. This insight helps engineers understand when models may rely on shortcuts and how to design prompts or fine-tuning to encourage proper composition.
Problem
How do language models handle tasks that require composing two functions, and do they use compositional mechanisms to compute the combined result?
Method
We evaluate LLMs on two-hop factual recall tasks, decode residual stream representations to detect intermediate computations, and analyze embedding space geometry to determine whether the model uses a compositional or direct mechanism.
Results
The approach confirms a compositionality gap, reveals both compositional and direct processing mechanisms, and shows that embedding space geometry strongly predicts which mechanism is employed.
Contributions
We provide empirical evidence of the compositionality gap in LLMs, uncover two distinct processing mechanisms, and demonstrate a strong relationship between embedding geometry and mechanism selection.
Research questions this paper is counted under
This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. Suggest a correction