Circuits, Features, and Heuristics in Molecular Transformers
Kristof Varadi, Mark Marosi, Peter Antal
TL;DR
The paper probes how autoregressive molecular transformers learn to enforce chemical grammar and validity in SMILES generation. It combines mechanistic analyses of attention circuits (ring and branch) with valence-budgeting signals in the residual stream, and uses sparse autoencoders to extract interpretable feature dictionaries tied to functional groups. The results show specialized circuits and disentangled latent detectors that improve downstream property prediction (e.g., MoleculeACE, cADME) and enable controllable generation through latent steering. Overall, the work provides a concrete, testable framework for mechanistic interpretability in molecular language models and highlights opportunities to guide design and optimization with interpretable internal signals.
Abstract
Transformers generate valid and diverse chemical structures, but little is known about the mechanisms that enable these models to capture the rules of molecular representation. We present a mechanistic analysis of autoregressive transformers trained on drug-like small molecules to reveal the computational structure underlying their capabilities across multiple levels of abstraction. We identify computational patterns consistent with low-level syntactic parsing and more abstract chemical validity constraints. Using sparse autoencoders (SAEs), we extract feature dictionaries associated with chemically relevant activation patterns. We validate our findings on downstream tasks and find that mechanistic insights can translate to predictive performance in various practical settings.
