Text Generator 🔗

Generates a random yet syntactically plausible-ish and meaningful-ish text using Markov chains and a bit of luck. Sometimes outputs “wise thoughts”™

Try Yourself! 👨‍💻

Upload a .txt file with a text that will be used as the source for word generation. The more words the text contains the better, more than 100k is perfect :–)

⚠️ Some browsers don't yet support modules in web workers. If the app isn't working in your browser that is probably the reason. It should work in Chrome and Safari though.

How it works 🛠

The generator uses Markov chains to randomly choose a word based on previously generated words—the chain. The whole process consists of 3 steps.

Parsing and tokenizing

The generator takes the source text and splits it into tokens: words, punctuation, spaces, line breaks.

Creating predictions map

Each token has its following token: a word, punctuation mark, or a space. The same token can have a list of many different following ones. This list allows to randomly select the “next token” based on the current one.

For better syntax “comprehension”, the generator creates a map between a group of tokens with a certain length and a list of tokens following that group. This way, a generated sentence is more likely to “consider” the syntax of a language.

Generating words

The generator then iteratively selects a random token based on the last group in the chain and adds it to the chain, making it longer and changing the last token group.

Post about it ✍️

More info about Markov chains, text generation, and how to create one of these generators you can find in my post: