See this step by step guide on how the algorithm works with reference code provided.
Photo by Thomas Lefebvre onĀ Unsplash
Making computer generated text mimic human speech using Markov Chain is a fascinating and actually not that difficult for an effect that is sometimes convincing, but certainly entertaining. Markov Chains work by generating sentences based on recombination of elements of history of known sentences to generate meaningful sentences.
Whatās really interesting, is that you can combine texts from two different people and get a mixed āvoiceā.
I played around this with texts of speeches from two great presidents:
Image of courtesy of screentv.com
What my text generator came up with from Obama speeches and Bartlet scripts, is as follows:
- āCan I burn my mother in North Carolina for giving us a great night planned.ā
- āAnd so going forward, I believe that we can build a bomb into their church.ā
- āāCharlie, my father had grown up in the Situation Room every time I came in.āā
- āThis campaign must be ballistic.ā,
Further details and the python sourceĀ code
You can find a detailed explanation of how it works and also how to create one yourself at DrMysterian.com site: How to code a Markov Text Generator.
Otherwise, you can find the source code here.
Thanks for reading! If you like what you read, give a clap below so that others may find this (you can also find me on Twitter )