HomeCompanion pagesBidirectional Markov Text Analyzer

Bidirectional Markov Text Analyzer

Build a language model from your own corpus, then watch another text light up token-by-token by how surprising it is. Forward and backward order-n Markov models are merged into a single surprise heatmap, with click-to-replace predictions, add-k smoothing, backoff, and live perplexity.

Open the interactive lab

Bidirectional Markov Text Analyzer

A browser-based instrument that learns the statistical "feel" of a body of text and then shows you, token by token, how surprising some other text looks through that lens. It runs entirely in your browser—nothing is uploaded, nothing is installed—and it turns an abstract idea (how predictable is this writing?) into something you can literally see, colored in like a heat map.


The Big Idea

Give the tool a corpus—any text you like: a novel, your own emails, source code, song lyrics, a decade of diary entries. The tool studies that text and learns its patterns; which words tend to follow which, which letters cluster, what "normal" looks like for that particular writing.

Then you hand it a second piece of text—the test text—and it paints every token according to how well it fits what the corpus taught it:

Click any token and the tool tells you what it would have predicted instead, and lets you swap it in. It's a bit like having a very well-read, slightly opinionated reader looking over your shoulder, pointing at the words that made them raise an eyebrow.


A Little Background

Under the hood sits one of the oldest and most charming ideas in text modeling: the Markov chain. The intuition is simple—the next word (or letter) depends mostly on the handful of words just before it. Count how often each continuation follows each little context in your corpus, and you have a model that can estimate "how likely is this word, right here?"

This tool adds a twist worth dwelling on. Ordinary models read left to right, the way we do. This one reads both directions: it builds one model that predicts each token from the words on its left, and a second that predicts it from the words on its right. Every token therefore gets two opinions—one from its past, one from its future—which are combined into a single verdict. A token is comfortably "expected" only when both directions agree; that turns out to be a much richer signal than either alone.

From those probabilities the tool computes a surprise score for every token, and (for the whole passage) a single summary number called perplexity—loosely, the effective number of choices the model felt it faced at each step. Lower perplexity means the text felt more predictable. It's the standard yardstick language researchers use, and here you get to watch it move.


What You Actually See

The interface is deliberately hands-on:

Most settings—how scores are combined, the palette, the color scale—update everything instantly. A few settings change how the corpus is learned (the tokenizer, the model's order, lowercasing, smoothing) and so require a rebuild; the tool tells you when.


Why It's Interesting

It turns out that "surprise" is a surprisingly expressive quantity. A few things I find genuinely fun about watching it:

None of this requires you to believe Markov models are the last word in language—they emphatically aren't. Their charm is that they're simple enough to understand completely and yet rich enough to reveal real structure, which makes them a wonderful teaching and exploration instrument.


Who Might Find It Useful


Getting Your Bearings Quickly

If you want a signal fast: paste a page or two of some text you know well into the corpus, build the model, then paste a different page into the test area and watch the colors. Hover a few tokens to read their probabilities; click one to see what the model wanted instead. Then try switching the color scale to log, or bumping the model order, and notice how the picture changes.

That's the whole idea—a small, transparent model, made visible. I'm looking forward to hearing what patterns you find in your own text. Enjoy!