Elman’s word categories: what a next-word predictor learns about words

Elman 1990 made 10,000 short sentences from a 29-word vocabulary, such as man eat cookie, dragon smash plate, cat sleep, ran them together with no breaks, and trained a simple recurrent network to predict each next word. The network sees every word as an arbitrary one-hot code, yet its hidden states end up grouping the words into categories. Below, the experiment runs live, along with the controls students asked for: is the structure learned or just in the data, is the zog result real, and does the network actually use the noun/verb distinction?

hidden units speed

1. Training: predicting the next word

Training on the word streamLeft, the last words the network trained on, each with the probability it gave to the word that actually came next, and its full prediction for the next word. Right, the error in bits per word on held-out sentences as training proceeds, against n-gram baselines.

2. The hidden state each word produces, averaged over all its occurrences

vectors from
clustering
zog test
Clustering of the words by their hidden statesLeft, a tree joining the words whose averaged hidden states are closest; right, the same vectors projected onto their two main directions, with the path of the sentence built below.

3. Is the noun/verb distinction really there, and is it used?

push the hidden state along the probe’s direction: ← verb-like     noun-like →0
The probe and the interventionLeft, how accurately a linear probe reads noun versus verb from the hidden state, for words it was fit on and for held-out words, in the trained and an untrained network. Right, the network's prediction for the next word after the sentence above, after pushing its hidden state along the probe's direction.
The setup. Elman’s lexicon has 13 kinds of word, such as humans (man, woman, boy, girl), food (cookie, bread, sandwich), and verbs that take a food (eat) or a fragile object (break, smash), and 16 sentence templates such as human eat food or animal move; some words belong to two kinds (lion is an animal and an aggressor). Each word is a one-hot input, so “man” and “woman” start out exactly as different as “man” and “plate.” Hidden units are sigmoids, the context units copy the previous hidden layer, the output is a softmax over the 30 words, and training is Elman’s one-step backprop, online, for 6 passes over about 27,000 words. The n-gram lines are the error of counting models fit to the same sentences and tested, like the network, on held-out ones: the trigram (two words of context) is close to the best possible, because a sentence is at most three words long. Beating the bigram requires memory: after eat, whether a human, animal or food comes next depends on who was eating.
What the tree shows, and what it does not. Elman reported a top split into nouns and verbs. Here the tree splits by what each word predicts: animate nouns (a verb comes next), transitive verbs (an object comes next), and everything that ends a sentence, both inanimate nouns and intransitive verbs like sleep (a new subject comes next). Within those the categories are clean: humans, animals, aggressors, food, fragile things. That is the point Parth and Ardhra raised. The averaged hidden state is shaped by the prediction task, and co-occurrence counts of the neighboring words recover much of the same tree with no network at all, so the structure is in the data; what the network adds is learning it from prediction, and compressing it. The untrained network shows no categories: a random network can only tell the words apart, not group them. And the tree itself is a choice: switch to average linkage and the same vectors make a different tree, which is why Teoman wants a test rather than a picture.
The zog test. Elman added a novel word, zog, replaced every man with it in new sentences, and found zog’s hidden state among the humans, with no training on zog. Zog’s own input weights are random and untrained, so its hidden state comes almost entirely from the words before it, and zog lands wherever its positions put it: with the humans where man was, with the foods where cookie was, among the sentence-ending words at random places. Ankit’s worry is right: the test shows the representation reflects context, which is useful, but it is built into how zog was placed, and it is not evidence the network learned anything about zog.
Probe, control, intervention. The probe is a logistic regression reading “is the current word a noun?” from the hidden state. It is fit on most words and tested on words it never saw (woman, dog, rock, plate, bread, chase, sleep, smell, break), because on the words it was fit on a probe can simply memorize which of the 29 one-hot words are nouns. Even so, the probe needs a control: an untrained network with random weights also scores well above chance on held-out words, because its context units carry the previous word forward, and the previous word hints at the current one’s category (after a verb, a noun is likely). The evidence is the gap between the two networks, not the trained network’s accuracy alone. Then the causal test: push the hidden state along the probe’s direction and watch the prediction. After “… man” the network expects a verb; push the state toward the verb side and it expects a noun instead, as if it had just read a verb. The distinction is not only readable, the network uses it.