Neural Network Visualizer

Watch a network remember.

A small recurrent network reads your text one character at a time, carrying a memory of 256 numbers from each character to the next. From nineteen children’s classics it learned how English is spelled and punctuated, but not what it means, so its own sentences sound like English without making sense.

Memory

0 characters read, 256 memory cells

Each box is one step: a character read. Hover or tap one to see what the network expected next, and what shaped that guess.

Stronger amber, more surprising

Memory span
    Cell state c the memory, one row per cell, violet above zero and amber below
    Cell its memory over the text
    Input gate Forget gate Output gate

    Each row is one memory cell. Some switch on inside a word or a quote and hold until it ends. Hover or tap a row to follow that cell.

    The bars above the text show how much each earlier character shaped the chosen guess. Watch them fade with distance.

    Next character

    What could follow

      Beside each character is the word it would lead to if the network kept taking its likeliest letter. Lower the temperature for safer choices; raise it for surprises.

      Why gates matter

      A second network reads the same text: an ordinary recurrent network with no gates, trained on the same books for just as long. To have about as many parameters as the LSTM, it gets twice the memory, 512 numbers instead of 256, yet it forgets older text sooner.

      Loading the network without gates…

      LSTM
      Gateless network
        Inside a quotation

        How fast memory fades

        Each earlier character’s average share of what shaped a guess, by how far back it is, on a log scale LSTM Gateless network Text neither trained on A text of 150 characters or more adds its own curves

        How often each is right on this text
        First guessWithin three
        LSTM––
        Gateless network––

        Let each one continue the text

        Both pick every character from their five likeliest, at the temperature set above, as Generate does.

        Without gates, every step squashes the whole memory through the same tanh, so a character’s pull shrinks by about the same factor with every character that follows. Up close that hardly shows; from about fifty characters back, it does.

        The LSTM’s forget gate can hold a cell’s memory almost unchanged for dozens of characters. That is how it keeps track of an open quote.

        Memory, one character at a time.

        A recurrent network keeps no copy of the text. Everything it knows about what came before has to fit in the memory it carries forward.

        It reads one character at a time

        Each character updates the memory, and the memory alone predicts the next character. Once read, a character is gone; only what the memory kept of it can still help.

        Gates decide what to keep, write and reveal

        For every cell, the forget gate decides how much of the old memory to keep, the input gate how much new information to write, and the output gate how much of the memory to reveal to the prediction. Each is a number between 0 and 1.

        Why memory fades

        Every step multiplies the old memory by a forget gate, so a character’s influence shrinks as more text arrives unless the gates hold it open. Without gates nothing can hold it open: every step shrinks the pull of older text by about the same factor, so it fades away steadily. Even the LSTM remembers only the last dozen or so characters well, enough to finish a word but not to keep a thought going, which is why its own sentences drift. The Transformer avoids this: attention looks back at every earlier token directly instead of carrying a memory forward.

        Model and credits

        The network is a long short-term memory (LSTM) with one layer of 256 cells and about 346,000 parameters, trained for this site on nineteen public-domain children’s books from Project Gutenberg, among them Alice’s Adventures in Wonderland, The Wonderful Wizard of Oz, Peter Pan, The Jungle Book, Treasure Island, The Secret Garden, The Wind in the Willows, Anne of Green Gables, and the fairy tales of the Brothers Grimm and Hans Christian Andersen. Paragraphs with the period slurs some of these books use were left out. The last 5% of each book was held out from training; on that text it averages about 2 bits per character. The network it is compared with has no gates: one layer of 512 units, h = tanh(Wxx + Uh + b), with about 329,000 parameters, trained the same way on the same books. On the same held-out text it averages about 2 bits per character. Both run entirely in your browser; nothing you type leaves your device.