Manuscript Offprint

arXiv:2610.24118

Do LMs Know What Variables Do? Interpreting Code Representations via Variable Roles

Célian Vasson, Daniil Ognev, Kentaro Inui, Benjamin Heinzerling

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

ABSTRACT

Variable roles describe recurring behaviors such as accumulation, traversal, and retaining the best candidate encountered. We use Sajaniemi's independently defined taxonomy to study which role distinctions can be recovered from large language models, how sparse autoencoders (SAEs) retain those distinctions, and whether associated directions support control of generation. We introduce static annotation rules for all eleven roles and a corpus of 126,926 natural-code files across five languages. Across five model–SAE systems, residual probes outperform individual SAE features and tested lexical baselines, with modest losses after neutral target renaming. Combining SAE features closes much of the single-feature gap, but probes on SAE reconstructions are less sensitive to role-changing edits reviewed by LLMs. High paired ranking accuracy coexists with frequent false positives at fixed thresholds. During generation, interventions often change role annotations at the cost of correctness; changes accompanied by passing tests show no clear aggregate advantage over random controls. The benchmark separates role-related recoverability, SAE fidelity, and correctness-preserving control through matched prediction, source edits, and generation interventions.

1 INTRODUCTION

Large language models generate and modify source code, from code completion to agents that plan, edit, and test software (Jiang et al., 2024; Dong et al., 2025). Yet programming success alone does not establish which program properties a model represents: models may exploit identifiers and familiar code patterns, and their performance can change under controlled input transformations (Hooda et al., 2024). We investigate this question through the behavior of individual variables. A variable may advance through a predictable sequence, accumulate values, or retain the best candidate seen so far. These behaviors depend on relationships across updates: recognizing an addition alone does not distinguish a regular progression from accumulation of input-dependent data. The same behavior can also use different names and language constructs, motivating three questions: which role distinctions are recoverable, how faithfully do sparse autoencoders retain them, and can associated directions change generation while preserving correctness?

We investigate these questions using Sajaniemi's variable roles, developed in the psychology of programming to characterize recurring uses of variables (Sajaniemi, 2002; Sajaniemi & Navarro Prieto, 2005). The taxonomy defines behavioral criteria independently of the models under study. Prior studies recover program structure and intermediate execution states from model representations (Hernández López et al., 2022; Jin & Rinard, 2024) and find shared representations across programming languages (Kargaran et al., 2025; Yin et al., 2026). We extend these analyses to variable behavior through matched prediction, controlled source edits, and generation interventions.

We combine program analysis with sparse autoencoder (SAE) features and probes, contributing:

• Large-scale multilingual dataset and benchmark. We introduce a dataset of 126,926 natural-code files across five programming languages, to our knowledge the first to au-

References (61)