Around 350 BCE, somewhere in what is now northwestern Pakistan, a man named Panini wrote down a grammar. It had 3,959 rules. When you applied them in the right order, they generated every valid Sanskrit sentence that could ever exist, and nothing that was not valid. No more, no less.

We did not understand what he had built until we built something similar ourselves, two thousand years later.

What Panini Actually Wrote

The Ashtadhyayi is not organized the way a grammar textbook is organized. If you pick it up expecting to learn Sanskrit, you will be lost immediately. The rules are dense, abbreviated, full of technical notation that only makes sense in relation to other rules. There is no progression from simple to complex. No friendly examples. No concessions to the learner.

That is because Panini was not writing for learners. He was writing for completeness.

The goal was not to describe how Sanskrit speakers talk. The goal was to specify exactly what Sanskrit is. Every valid form, derived. Every invalid form, excluded. The whole language, in 3,959 rules.

This is what we now call a generative formal system. You give it a starting point and a set of rules, and it produces valid outputs. The rules are finite. The outputs are not.

He was not describing Sanskrit. He was specifying it. There is a difference.

The Structure That Should Feel Familiar

When you look at how the Ashtadhyayi actually works, some things stand out.

The rules are ordered. Order matters. Rule 500 can feed into rule 1,200. The system is not a flat list of facts; it is a process that runs in a specific sequence.

The rules are recursive. Outputs of some rules become inputs to others. You can apply rules to the results of applying rules.

The rules interact. A rule applied in one context might be blocked or modified by another rule. The system has to be understood as a whole, not rule by rule.

The rules are compressed. Panini uses a meta-language of his own invention, technically called the Shiva Sutras, to group sounds together so he can refer to entire classes in a single symbol. The whole system is designed for minimum redundancy.

If this sounds like a description of a neural network, I think that is not a coincidence. It sounds like that because both are doing the same underlying thing: representing a space of valid structures using a finite set of learned or stated operations.

Where the Analogy Holds

A large language model learns to generate valid language from examples. Panini derived valid language from first principles. One is learned, one is specified. That is a real difference.

But the output is structurally the same. Both produce valid utterances and nothing else. Both do it by learning or encoding the deep structure of the language, not by memorizing surface forms. Both are generative in the technical sense.

There is something else worth noticing. Panini's grammar is not just a grammar of sentences. It is a grammar of meaning. The rules operate on semantic units, morphological units, phonological units, all at once. The levels are not separate. They are woven together in the derivation.

Modern language models blur these levels too. They do not have a clean separation between sound, structure, and meaning. This used to seem like a limitation. After Panini, it looks more like a feature. The blurring is not a bug in how they were built. It is what a deep model of language looks like.

Before the Word traces the philosophical tradition behind Panini's grammar and what it means for how we understand language models today.

Read the Book

Where It Breaks

Panini knew what he was doing. He was writing a specification, and he wrote it like one. Every rule is there for a reason. The system is interpretable, in principle, all the way down.

A trained language model is not like this. We do not know why it makes the generalizations it does. We know it works. We do not know exactly how. The structure Panini made explicit, the model has learned implicitly, and we cannot fully read it back out.

This matters more than it might seem. Panini's grammar is a theory of Sanskrit. A language model trained on Sanskrit is not a theory of anything. It is a very good compression of patterns. The patterns may encode a structure as deep as Panini's, or deeper. But we cannot see it.

This is, I think, one of the more honest ways to describe what interpretability research is trying to do. It is trying to find the Ashtadhyayi inside the model.

What This Changes

The usual story about Panini is that he was ahead of his time. A linguist who somehow anticipated formal grammar, generative linguistics, Chomsky, all of it, by two millennia.

I think that framing is too modest in one direction and wrong in another.

Too modest, because Panini was not just anticipating formal grammar. He was doing something more ambitious: trying to write down the complete structure of a language as a generative system. That is not what modern descriptive linguistics does. It is closer to what AI researchers are trying to do now.

Wrong, because the Ashtadhyayi was not waiting around to be validated by Western linguistics. It was embedded in a tradition that understood exactly what it was: an investigation into how language generates reality, not just sentences. The philosophical context matters. Panini was read by Bhartrhari. The grammar was understood as ontology, not just philology.1

We are only now asking the same questions again, with different tools.

The model learns to predict. The grammar specifies to completion. Both arrive at the same place: a finite system that generates an infinite structured space. What Panini wrote by hand, with notation he invented, in rules short enough to memorize, we are approximating with billions of parameters and terabytes of text.

He got there first. And he knew what he was building.

Notes

1. The connection between Panini's grammar and Bhartrhari's ontology is developed in depth in Bimal Krishna Matilal, The Word and the World (Oxford University Press, 1990), and George Cardona, Panini: His Work and Its Traditions (Motilal Banarsidass, 1988). Frits Staal's A Reader on the Sanskrit Grammarians (MIT Press, 1972) remains the most useful entry point for readers coming from a formal linguistics or computer science background.

2. The characterization of the Ashtadhyayi as a generative formal system in the modern sense is controversial in Indological circles. The argument here follows the analysis in Wiebke Petersen, "A Mathematical Analysis of Panini's Sivasutras," Journal of Logic, Language and Information 13 (2004), which shows that the Shiva Sutras form a minimal covering of Sanskrit phoneme classes in a formally precise sense.