N-gram 3
Words 20
Seed
Theory // how it works
What is an N-gram?
An n-gram is a sequence of N consecutive words. Given the previous (N−1) words, the model predicts the next one using frequency tables built from the corpus.
"the city"
  was: 9
  had: 6
  seemed: 3

How it differs from GPT
GPT uses a Transformer neural network with attention spanning thousands of tokens. We use a frequency table with only 2–4 words of context. Same core idea — predict the next word — but radically different scale and architecture.

About this corpus
The training text is a short fictional narrative (~24,000 characters) following several characters — Martin, Clara, Elena, Thomas, Nadia, Gabriel, Irene — across short scenes about cities, decisions, and everyday life.
It's not random text. It has consistent characters, settings, and recurring phrases, which is exactly why the model can learn patterns from it — real sentence structure, not noise.
Good seeds to try:
"the city" · "martin smiled"
"elena watched" · "the project"

How to use this page
  1. Pick an N-gram size in the top bar. Higher N = more coherent text but needs longer seed.
  2. Pick how many words to generate.
  3. Type a seed — at least (N−1) words from the corpus.
  4. Press RUN — watch the code execute step by step.
  5. Read the flowchart alongside to follow the algorithm.
  6. The output appears in the status bar when done.
Live code execution // pauses are real, in the source
ngram.js
idle
Algorithm flow // follows the code
Generation complete
ready
corpus: english
tokens: —
contexts: —
— output will appear here when generation completes —