James Adam Buckland
Home Blog Games Resume

2014-06-08 Using Markov Chains to Generate Realistic Song Lyrics python


Using a document with every John Darnielle lyric ever written, I wrote a python script to create a JSON data file containing a simple Markov-chain-style dictionary, where the user can pick a word from the vocabulary at random and find a list of words that typically follow it in written (or, sung) use. The javascript code on this page randomly picks starting words and chains them out into long, sentence-like lists that have the approximate mood and vocabulary of a singer-songwriter. The code then goes one step further to generate a typical song pattern (verse, bridge, chorus) and fills the sections with lines of a predetermined length. The end result is a piece of entirely generative writing that often reads like an intentioned song.