2023

Emergent Representations of Program Semantics in Language Models Trained on Programs

Jin, Charles, Rinard, Martin

Understand

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.

Reading the bibliography…