Elman’s letter stream: prediction error marks what the network cannot know

Elman 1990 fed a network one letter at a time from a stream with no gaps, like b a d i i g u u u d i i, and asked it to predict the next letter. Each consonant is random, but it fixes the vowels that follow: b→a, d→ii, g→uuu. Two networks train side by side on the same stream: Elman’s, whose error goes back only one step, and one trained with backpropagation through time over k steps. Click any letter to see the network at that moment.

vowels after g3 backprop steps k8 hidden units
speed inspect:

1. The stream, and each network’s error on every letter

Letter stream with prediction errorsA window of the letter stream. Above each letter, a bar for the error the one-step network made predicting it, and a bar for the error of the network trained with backpropagation through time.

2. Inside the network at the selected letter

The simple recurrent network at one time stepInput units for the current letter, hidden units, context units holding a copy of the previous hidden state, and output units predicting the next letter; at right, the steps the training gradient reaches back through.

3. Where the errors are, and how training goes

Error by position in the syllable, and the training curveLeft, the average error for predicting each position of a syllable or word, for both networks, with the unavoidable error marked. Right, the average error per pass through the stream as training proceeds.
What the network is. Elman’s simple recurrent network has an ordinary hidden layer, ht = σ(Wx xt + Wh ct + b), whose input includes a bank of context units ct holding an exact copy of the previous hidden state, ct = ht−1. The copy has fixed weight 1 and is not learned; what is learned is Wh, how the hidden layer reads its own past. So memory is trained even though the copy is not. (Jordan’s 1986 networks copied the output instead; copying the hidden layer lets the network keep anything it finds useful, not only what it predicted.) The output is the next letter’s prediction. In syllable mode each letter is Elman’s six phonetic features (consonant, vowel, interrupted, high, back, voiced) with squared error on each, as in his paper; in word mode each letter is one unit and the error is cross-entropy in bits.
Why the error spikes. A consonant’s identity is a coin flip, so no network can predict it: its error stays at the dashed line, the variance of the coin (0.44 for three equally likely consonants differing in two features). The vowels after it are fully determined, so their error falls to zero. The bars therefore spike at each syllable start. Look at the six output units at a consonant: the consonant and interrupted features come out right, because after the last u the network knows a consonant is coming, only not which one. In the word modes the same thing happens at the first letter of each word, the “weird spikes at the start” in Elman’s Figure 6. He pointed out that the spikes find the word boundaries, with no spaces in the input.
How close to the paper. Syllable mode is Elman’s first experiment as he ran it: 1,000 random consonants expanded into about 3,000 letters, six features, a 6-20-6 network, 200 passes. His word experiment used the same 15 words, but in 200 sentences from a small grammar, with each letter coded as a random 5-bit pattern; here the words come in random order and each letter has its own unit, which keeps the same point (the boundaries are where the next letter is unknown). English mode goes beyond the paper: the opening paragraphs of Alice’s Adventures in Wonderland with spaces and punctuation removed, about 1,300 letters, so the network has to pick up real spelling. With so little text it partly memorizes it; the spikes at word starts appear anyway. The second network, trained with backpropagation through time, is not in the paper either: it shows what Elman’s one-step training leaves on the table.
One step back, and how far that reaches. Elman trained by ordinary backprop at each step, treating the context units as fixed inputs: the error never flows back past the copy. Yet his network learned to count three us. It can do that because the context it receives is not random: it was produced by the same network one step earlier, so a hidden state that already happens to differ after one u and after two can be told apart, and one-step training sharpens that. Nothing, though, trains the earlier step to keep information for later. Raise vowels after g: at 4 the one-step network usually still counts; at 6 it usually loses count near the end of the run (it cannot tell whether another u is coming), and at 8 it lost count in every run we tried, while backprop through k ≥ the run length kept it every time. Which way a given run goes depends on the random start, so press New networks a few times. The backward pass in panel 2 shows the difference: Elman’s gradient stops at the context units, while BPTT carries ∂E/∂h back through Wh and each step’s σ′ for k steps, accumulating weight changes at every step it reaches. Carrying it back many steps is where gradients vanish, which is the problem LSTMs were built to fix (LSTMs, highways, ResNets).