Markov Chain Text Generator illustration

Markov Chain Text Generator

A Markov chain models text by counting, for every context of k consecutive tokens, which token follows and how often — generation then walks the chain, sampling each next token from those counts. Paste any text (a public-domain excerpt from Alice in Wonderland is preloaded) and the model retrains instantly. Switch between character and word units, raise the order k, set the output length and press Generate to sample a new passage from a random seeded start. An inspector shows the model from the inside: type any prefix and the top next-token probabilities appear as bars. Readouts track the number of distinct contexts, the mean number of continuations per context and the estimated entropy per generated step.

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

Notes

  • Transition probabilities are maximum-likelihood estimates: P(next|context) is simply the count of that continuation divided by the context’s total count.
  • Higher order k reads more coherently but copies more: as contexts get longer most of them have a single continuation, so the chain replays verbatim spans of the training text.
  • The entropy readout is the count-weighted average of −Σ p log₂ p over all contexts — near zero it warns you the model has become a lookup table of the source.
  • An order-k chain sees nothing beyond its k-token window, so brackets, quotes and long-range grammar can never be balanced reliably — the key limitation neural language models address.
  • Runs 100% in your browser — models are trained and computed locally on your device.