/markov-chain-text-generation

A demo of a text generator based on Markov chains in Python

Primary LanguagePython

Text generation using a simple Markov model:

Note: As you can see, the generated sentences are neither coherent nor grammatically correct, which is fine for this demo purpose.

This program demos how a simple Markov model can be used to generate text that resembles the style and structure of the original input text. Sample text generated by a model trained on Tiny Shakespear with a n-gram length of 8 and single characters as tokens:

KATHARINA:
Husband, be not in the prince
Take on without blows! Despising,
For you, became of Antigonus to break an oath by Him,
The unity the king! Will no more but the outward show; which, without,
the carpets laid, and so becoming: in pure and think and paper,
And driven snow;
Cyprus black veil,
Have been beyond commission. Yet I well might the mayor towards London with thee to thy breath of Hermione hath congealed blood,
Nor tackle, sail, nor mast; the very wrath,
And his to me no more. Thou art experienced, since we have her son.

PROSPERO:
Following him to rue at the morning to the end of reckoning are yourselves, as
we term it.

First Citizen:
Bad news, good favourable a grave
And loves me well in 't.

LUCIO:
Thou liest; his honours on my fault that way?

Third Servingman:
Let me entreat you should be king.