LLMs program using Reusable and Composable Abstract Representations
Casper L. Christensen, Kyle J. Ray, Dmitry Manning-Coe, Adam Shai, Paul Riechers
Key points
From the paper's conclusion- LLMs generate code while capturing shared computational structures in reusable and composable abstract representations through their activations.
- The middle layers of LLMs show the emergence of these abstract representations, which allow for impressive generalization across different programming languages and implementation strategies.
- Using activation steering, the model can independently manipulate function, programming language, and implementation strategy, even when the prompt lacks such information.
Abstract
When writing code, the same computation can be expressed in different programming languages and through different implementation strategies. We show that the activations of LLMs capture this shared structure in reusable and composable abstract representations when they generate code. These representations emerge in the middle layers, are reusable across programming languages, and afford the model an impressive amount of generalization ability when generating code under various interventions. Using activation steering, we show that function, programming language, and implementation strategy can be independently manipulated. The independent interventions on language and function can be flexibly composed to control code generation, even in cases when the prompt contains no information about language and function. We additionally find that finetuning on examples of arbitrarily defined functions in one programming language transfers to other languages, consistent with the models reusing abstract features of code generation that are shared across different examples. Finally, to study how such abstract representations come to be, we implement a minimal model of shared, reusable, and composable structure in a synthetic setting, and show that transformers trained on such data learn representations that reuse these parts flexibly across contexts.
Read the paper
Discussion · 1
Science Skim's AI key points, plus readers' public thoughts
- LLMs generate code while capturing shared computational structures in reusable and composable abstract representations through their activations.
- The middle layers of LLMs show the emergence of these abstract representations, which allow for impressive generalization across different programming languages and implementation strategies.
- Using activation steering, the model can independently manipulate function, programming language, and implementation strategy, even when the prompt lacks such information.
Readers' thoughts
No reader thoughts yet.
Related papers
- From Abstraction to Action: DSLs for Natural Language Abstraction Interpretation and ExecutionarXiv · 2026
- Reasoning-Trace Overflow in Code Generation: An Empirical Study of Explicit Reasoning ModelsarXiv · 2026
- DivAlgo: A systematic evaluation of algorithmic diversity for code generation modelsarXiv · 2026
- Understanding code semantics: a benchmark study of LLMsInternational Journal on Software Tools for Technology Transfer · 2026
- CoBoVLA: Decoupling Language from Action with Discrete Codes for Robust and Interpretable Robot ManipulationarXiv · 2026
- Invariant Pretraining for Robust Code RepresentationsarXiv · 2026