Character RNN Text Generator illustration

Character RNN Text Generator

A recurrent neural network learns to write text one character at a time. Paste any training text (a public-domain excerpt is preloaded), pick the hidden-layer size and press Play: the browser trains a vanilla tanh RNN with truncated backpropagation through time over 25-character windows, updating the weights with gradient-clipped Adagrad. Watch the loss curve fall and the iteration counter climb, then press Generate at any point to sample new text character by character — the temperature slider controls how conservative or adventurous the sampling is. Early output is gibberish; after a few thousand iterations the network discovers the words, spacing and punctuation of your corpus. The vocabulary is built from the text itself, so any language or alphabet up to 96 distinct symbols works.

Runs 100% in your browser — models are trained and computed locally on your device.

Notes

  • A vanilla RNN carries a hidden state vector updated at every character, h ← tanh(Wxh·x + Whh·h + b); the next-character distribution is a softmax over Why·h.
  • Truncated backpropagation through time unrolls the network over the last 25 characters only, which keeps gradients tractable but limits how long a dependency the model can learn.
  • Temperature divides the logits before the softmax: below 1 sampling concentrates on likely characters, above 1 it flattens the distribution and produces more surprising (and more misspelled) text.
  • Adagrad scales each weight’s learning rate by the root of its accumulated squared gradients, and gradients are clipped to ±5 to tame the exploding-gradient problem typical of RNNs.
  • Runs 100% in your browser — models are trained and computed locally on your device.