How Do Language Models Compose Functions?
Apoorv Khandelwal, Ellie Pavlick
Mech Interp @ ICML 2026
Abstract. While large language models (LLMs) appear to be increasingly capable of solving compositional tasks, it is an open question whether they do so using compositional mechanisms. In this work, we investigate how feedforward LLMs solve two-hop factual recall tasks, which can be expressed compositionally as . We first confirm that modern LLMs continue to suffer from the "compositionality gap": i.e. their ability to compute both and does not entail their ability to compute the composition . Then, using logit lens on their residual stream activations, we identify two processing mechanisms, one which solves tasks compositionally, computing along the way to computing , and one which solves them directly, without any detectable signature of the intermediate variable . Finally, we find that which mechanism is employed appears to be related to the embedding space geometry, with the idiomatic mechanism being dominant in cases where there exists a linear mapping from to in the embedding spaces.
Are you an author? Claim this paper to see who's reading it, with views and other statistics, and to write about it here.
Claim this paperedit · history
Loading the discussion…