A Karel robot helps test what language models learn
Researchers at MIT’s CSAIL trained a language model to predict program tokens for a virtual robot, then found internal representations linked to program meaning and correctness. The results challenge the claim that next-token training captures only surface patterns, though the researchers say it remains unclear how far the findings extend to models such as GPT-4.
A model trained to predict the next piece of program code may learn more than patterns in code. Researchers at MIT’s CSAIL used a virtual robot called Karel to study whether a language model’s internal representations reflect what programs do, as well as how they are written.
“The study examines what a code-predicting model learns, with no clear drift toward harm or human dependence.”Why it scores Neutral
Using programs to give meaning a clear test
Debates about language models often turn on whether predicting text can produce an understanding of meaning, or whether models merely reproduce statistical patterns. The researchers framed their study around two claims: that next-token models are limited to surface-level correlations in their training material, and that they cannot assign meaning to the text they process and generate.
To investigate, the team chose program synthesis. A program’s meaning and correctness can be evaluated according to the rules of its programming language, giving the researchers a way to connect a model’s representations to what its output actually does.
They trained a model on the Karel programming language, developed for educational purposes. Karel programs direct a digital robot through a grid containing obstacles. The model’s training objective was to predict the next token in program code that would guide the robot successfully.
Looking inside the model as code runs
After training, the researchers used a linear probe to examine the model’s internal states while a Karel program ran. They found that those states contained information that could be used to identify abstractions of the program’s current and future states.
The model had been trained to predict tokens, not explicitly to learn Karel’s semantics. Yet the semantic representations identified by the probe developed alongside the model’s ability to generate correct programs. That relationship offers evidence that the internal information was connected to program behavior, rather than only to the code’s visible form.
The researchers also selectively changed internal states to check whether the probe alone explained the result. They reported a strong, statistically significant correlation between the probe’s accuracy and the model’s ability to generate a program.
Evidence beyond familiar training patterns
The study reported other signs that the model’s output was not simply a copy of the training examples. On average, it learned to produce programs shorter than those in its training set. The researchers interpret this as a meaningful departure from the training distribution: different code can still achieve the intended behavior.
They also found that the model’s perplexity—a measure of its uncertainty when predicting the next token—remained high for programs in the training set while its ability to synthesize correct programs improved. In the team’s view, this challenges the claim that the model’s abilities are explained only by reproducing surface-level statistical patterns.
Taken together, the findings led the researchers to argue that the model’s internal representations aligned with the programs’ semantics, rather than encoding only lexical and syntactic information. They say the results challenge both claims tested in the study: that next-token training is limited to surface patterns and that models cannot represent meaning.
What the findings do—and do not—show
The work provides empirical support for the idea that meaning can be learned from form, the paper states. Its method could also help researchers investigate what representations language models develop and how those representations relate to the outputs they produce. The question has practical and philosophical importance, according to the researchers.
The study does not establish how directly its results apply to large language models such as OpenAI’s GPT-4. The article describes that connection as unclear, so the Karel experiment should be understood as evidence about a model trained on a programming task, rather than a definitive account of every language model.
The researchers place their work among studies that probe internal model behavior. OthelloGPT, for example, has shown that a language model can learn an internal representation of a game board and use it to predict future moves. The Karel results add a different kind of task to that discussion: whether a model trained on code prediction can represent what a program will do.
Read next