Papers › Emergent Representations of Program Semantics in Language Models Trained on Programs

Emergent Representations of Program Semantics in Language Models Trained on Programs

18 May 2023arXiv:2305.11169archive 2025-07-28

Charles Jin, Martin Rinard

We present evidence that language models (LMs) of code can learn to represent the formal semantics of programs, despite being trained only to perform next-token prediction. Specifically, we train a Transformer model on a synthetic corpus of programs written in a domain-specific language for navigating 2D grid world environments. Each program in the corpus is preceded by a (partial) specification in the form of several input-output grid world states. Despite providing no further inductive biases, we find that a probing classifier is able to extract increasingly accurate representations of the unobserved, intermediate grid world states from the LM hidden states over the course of training, suggesting the LM acquires an emergent ability to interpret programs in the formal sense. We also develop a novel interventional baseline that enables us to disambiguate what is represented by the LM as opposed to learned by the probe. We anticipate that this technique may be generally applicable to a broad range of semantic probing experiments. In summary, this paper does not propose any new techniques for training LMs of code, but develops an experimental framework for and provides insights into the acquisition and representation of formal semantics in statistical models of code. Our code is available at https://github.com/charlesjin/emergent-semantics.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2305.11169")

Code

Syntology Ran 12 of 13 code samples harvested from 1 repository linked to this paper; 1 has no recorded run. Of those that ran: 12 ran · our draft was wrong.

By repository: official repository: 13 samples from 1 repository, 12 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

charlesjin/emergent-semantics officialmentioned in papermentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

13 samples harvested; 12 ran; 0 honoured the contract we drafted; 1 has no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

12ran · our draft was wrong
1unverified

Licence: 13 of the 13 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from charlesjin/emergent-semantics. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

opposite1 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 19289791bccfe4aa · report
perm1 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 06ef4785e27794a2 · report
perm_nomarks_1 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 9c15d06bd3b8286a · report
perm_nomarks_2 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 57fa76126e713940 · report
perm_nomarks_3 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 45f490a781f1c4b4 · report
perm_nomarks_4 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · e5a9b785d18c1264 · report
perm_nomarks_5 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 017dd7ef99ca3626 · report
random1 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 55d8912d375aaabb · report
unsemantic1 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · c785730b24eadf32 · report
unsemantic2 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · a54437cd7c70b3e9 · report
unsemantic3 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · c860b95cbf28a9cc · report
unsemantic4 charlesjin/emergent-semantics/probe/alt.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · 46316ec582bba1bf · report
semantics_transformer charlesjin/emergent-semantics/probe/alt.py official repository unverified no licence file found · pointer only · de1956b9f51d4ea7 · report

Tasks

Inductive BiasLanguage ModellingProgram Synthesis

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections