This site uses tracking cookies. By using this site, you agree to our Privacy Policy. If you don't opt in, some parts of the site might not function.
Blog
Home / Blog / FileMaker / Using Javascript and Markov Chains to Generate Text
10Feb 2013

Using Javascript and Markov Chains to Generate Text

About the Author

Jason Bury

Jason is a Senior Application Developer. Jason is certified in PHP, Zend Framework, MySQL, Salesforce, and Linux system administration.

Comments (14)

Makah Encarnacao
Makah Encarnacao - February 12, 2013

Please tell me what day and time "Dirty Little Man With Harmful Intent" airs.

Great article!

Reply
kmone - October 27, 2013

Holy fuck, good to see that your markov chain take into account what words start title and what words end title, a thing a extreme amount of guys doing it forget.

Anyway, your markov chain generator, generate the title starting with the “title start” word by default.
A better idea, would be to generate the first word at random (including “title start” words and “title ends” words), if the first word you generate is not a title start word, you need to generate words before this word until you generate the title start word. Then you continue to generate words after the first one you got (unless the first word you generated was a “title end” word), until you generate the “title end” word

Reply
Jason Bury - October 28, 2013

Kmone,

Are you suggesting to pick a random seed word then choose words from the Markov chain data to find preceding words, until I read a start word?  That is a very interesting idea, and I don't think I've seen that done before.

The way I built my Markov chain, though, the data about frequencies of which words precede a given word isn't calculated or stored.  The Markov chain data only has information about the frequencies of which words follow a given word (notice the arrows in the graph diagram all point to the right).

It would certainly be feasible to alter to code to make the Markov chain bi-directional, though (so that the arrows in the graph between nodes point in both directions).  Maybe you can make a copy of my JSFiddle and try it.  I'd be interested to see what you come up with.

Thanks for commenting on the blog post!

-Jason

Reply
Shaun Pedicini - July 27, 2014

@Kmone,

This is commonly referred to as backwards and forwards chaining. However in this particular instance it seems like a lot of work with no real value added. His program generates titles completely randomly whereas the primary advantage of backwards and forwards chaining is to allow you to seed a chain with a particular keyword.

@jbury,

If you’re interested in examples of bidirectional markov chaining I suggest you take a look at the chat bot, MegaHAL, which extracts a keyword from the users input to generate a relevant reply chain.

Reply
Jason Cataldo - February 14, 2016

why don’t you create a program that uses markov chains to generate readable articles based on a set of keywords and sell it to seo people? you’d make a fortune in renewals and rebills.

Reply
james - June 30, 2016

Cool do the variations go on forever and ever? and is this possible to add to blogspot? thanks

Reply
Alison - July 25, 2017

Neat concept.

Reply
Alison - July 25, 2017

wow- megaHAL is too cool. Thanks for that suggestion

Reply
An Di - November 11, 2017

The code and the generate button are not showing up. Would be great if you cold fix that because I am very interested in this topic.

Reply
Raymond Camden - January 16, 2018

Ditto last comment – would love to see the code.

Reply

Leave a Reply