← Latest papers
💬 NLP

Linear representations of grammaticality in neural language models

This paper demonstrates that grammaticality is robustly and independently encoded as a distinct representational dimension within the internal states of diverse pretrained neural language models, offering a probability-free framework for evaluating their syntactic competence.

Original authors: Jane Li, Najoung Kim

Published 2026-07-17
📖 6 min read🧠 Deep dive

Original authors: Jane Li, Najoung Kim

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to teach a robot to understand human language. You feed it millions of books, movies, and tweets, and it learns to predict the next word in a sentence with incredible accuracy. But here is the big mystery that has kept scientists up at night: Does this robot actually know the rules of grammar, or is it just a masterful guesser?

In the world of linguistics and computer science, there is a famous debate about this. On one side, some argue that because these robots (called Neural Language Models) are trained to predict what comes next based on how often they see things, they are just calculating "likelihood." They might think a sentence is "good" simply because it sounds familiar, not because it follows the invisible, abstract rules of grammar. On the other side, others believe that if a robot can consistently tell the difference between a correct sentence and a broken one, it must have learned the rules, even if it can't explain them. The problem is that for a long time, the only way to test this was to ask the robot, "How likely is this sentence?" But if the robot says, "Very likely!" for a sentence that is actually grammatically wrong but just happens to use common words, we can't tell if it knows grammar or just knows statistics.

This paper, titled "Linear Representations of Grammaticality in Neural Language Models," dives right into that messy debate. The authors, Jane Li and Najoung Kim, decided to stop asking the robot how likely a sentence is. Instead, they decided to look inside the robot's brain. They wanted to see if the robot's internal "thoughts" (its mathematical representations of sentences) actually have a special, organized space where "grammatical" and "ungrammatical" sentences live in separate neighborhoods. If they can find a clear line separating these two groups inside the robot's mind, it would be strong proof that the robot has truly learned the concept of grammar, not just the concept of "what sounds common."

The Detective Work: Looking Inside the Brain

To solve this mystery, the researchers used a clever trick called "linear probing." Imagine the robot's brain as a giant, multi-dimensional map. Every sentence the robot reads gets turned into a specific dot on this map. If the robot only cares about how common words are, all the dots might be scattered randomly or grouped by how many words are in the sentence. But if the robot actually understands grammar, there should be a clear direction on this map where "good sentences" are on one side and "bad sentences" are on the other.

The researchers took 25 different language models (ranging from tiny ones with 14 million parameters to massive ones with 14 billion) and tested them. They fed the models thousands of sentences—some perfectly grammatical, some with tiny, deliberate errors like "This dog like to jump" instead of "This dog likes to jump." Then, they tried to draw a single, simple straight line through the robot's internal map to see if it could separate the good sentences from the bad ones.

The Big Discovery: Grammar is Real (and Linear)

The results were exciting. They found that in almost every model they tested, there was a clear line. Even a very simple, low-complexity classifier could look at the robot's internal representation of a sentence and say, "Ah, this one is grammatical," or "Nope, that one is broken." This suggests that grammaticality isn't just a fuzzy feeling for these models; it is a distinct, organized dimension in their internal space.

But the researchers didn't stop there. They knew that just because the robot could separate the sentences, it didn't mean it was separating them because of grammar. Maybe it was just separating them because the bad sentences were less likely to happen, or because they sounded weird, or because they had fewer words. To prove it was really about grammar, they played a few games of "deconfounding."

The Probability Trap:
First, they asked: "Is the robot just looking at how likely the sentence is?" They created a tricky scenario where they took grammatical sentences that were very unlikely (rare but correct) and ungrammatical sentences that were very likely (common but wrong). If the robot was just a probability calculator, it should have gotten confused and failed. But it didn't. The robot still correctly identified the rare, correct sentences as grammatical and the common, wrong ones as ungrammatical. This suggests the robot's "grammar detector" is independent of how likely a sentence is to appear in real life.

The "Silly Sentence" Test:
Next, they wondered if the robot was just judging how "sensible" or "plausible" a sentence was. They tested sentences that were grammatically perfect but made no sense (like "The rock ate the sandwich") and sentences that were grammatically broken but made sense (like "The sandwich ate the rock"). They found that while the robot did notice the silliness, it still had a separate, robust signal for grammar. The "grammar line" in the robot's brain was distinct from the "silliness line."

The Universal Translator:
Finally, they checked if this grammar knowledge was specific to English or if it was a universal skill. They tested the models on languages like Russian, French, German, Hebrew, and Mandarin Chinese. They found that for the larger, more powerful models, the ability to detect grammar wasn't just an English trick. The same kind of internal "grammar line" existed across different languages, suggesting that these models have developed a general, language-independent way of understanding structure.

What This Means for the Future

The paper concludes that these neural networks do indeed possess a robust, internal representation of grammaticality. It's not just a side effect of them being good at guessing the next word; it's a fundamental part of how they organize information.

However, the authors are careful not to say this is the final word on everything. They note that while the "grammar line" exists, it's not always perfect. Smaller models sometimes struggle more than the giant ones, and some specific types of grammar errors are harder to detect than others. They also point out that while the models have this internal knowledge, it doesn't always perfectly match how humans judge sentences.

Ultimately, this research changes the conversation. We don't have to argue anymore about if these models know grammar. The evidence suggests they do. The new question is how they learned it, how deep that knowledge goes, and what it tells us about the nature of learning itself. By showing that a statistical system can develop a clear, linear understanding of abstract rules, the paper suggests that the ability to grasp grammar might not require a special "rule-book" in the brain, but can emerge naturally from the sheer power of learning patterns in data. It's a fascinating glimpse into the mind of a machine, showing that even without a teacher, a robot can learn to tell the difference between a sentence that works and one that doesn't.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →