4Gram Interactive Demo

4-Gram Language Models in your browser.

Train, tune, and evaluate a classical 4-gram text generator. Compare backoff with interpolation, inspect perplexity, and watch generated text form one word at a time.

Pipeline
Corpus
Tokenize
Limit vocab
Train 4-gram
Perplexity
Generate
LM1 Backoff

Shorter context fallback

When a 4-gram is unseen, LM1 backs off to trigram, bigram, then unigram counts.

Inspect counts, probabilities, perplexity, and generated output.
LM2 Interpolation

Weighted mixture with smoothing

LM2 mixes all n-gram orders with add-k smoothing, so unseen contexts still receive probability.

Inspect counts, probabilities, perplexity, and generated output.