|
|||||
« Paranoia Creating a slide show shouldn’t be this hard » Shakespeare vs. MarkovBy Jim, on February 19th, 2009 I’m developing some code to work with Markov models, and as an early test I created a model of Shakespeare’s sonnets. Then I had the program generate some verse from the model. For example: If they in thou, thy love, that old, The Markov model generates text one character at a time. The next character is selected based on the distribution of characters in the original source text, and also on the “order” of the model. In an order 0 model, character selection is based entirely on the frequency of characters in the source text. If the letter ‘e’ appears 12% of the time in the source text, then it will appear approximately 12% of the time in the output. Output from an order 0 model is just a weighted random sampling of the source text. For example: vl An order 1 model bases character selection on the frequency of characters that follow the current character. That is, given the current character, the next character selected is guaranteed to be one that followed that character in the source text. The model cannot generate a bigram (sequence of two characters) that did not exist in the source. So, for example, the sequence ‘qz’ can’t appear in the generated text unless it was also in the source. Verse generated from an order 1 model is slightly better than what you’ll get from an order 0 model: Myouivey inn f th peroeethe, Things begin to improve quickly as you move up in order of the model. Order 2 bases character selection on the two preceeding characters, and you start to see recognizable English words although overall it looks more like some freaky foreign language: Thich Must I winter, Order 3 verse contains primarily recognizable English words. At order 5 (the first sample above), almost all words are valid and you begin to see word pairs that existed in the original source text. The resulting verse is reminiscent of a drunk and confused dramatics major trying to impress a group of girls with his knowledge of Shakespeare. Order 10 verse is like Shakespeare in a blender: Thou blind fool Love, what dost thou abuse, Here you sometimes see complete sonnet lines. Other times you’ll see the first half of one line morph into the second half of another, or just pure randomness. Things get less interesting beyond order 10, and by order 15 the thing starts spitting out complete sonnets exactly as they were fed in. I probably spent entirely too much time “testing” my program: generating verse and laughing at the results. But it was a welcome bit of humor in an otherwise somewhat dull day. Odds 'n Ends, Programming « Paranoia Creating a slide show shouldn’t be this hard » 2 comments to Shakespeare vs. Markov
« Paranoia Creating a slide show shouldn’t be this hard » |
Links
Categories
|
Archive
|
|||
Copyright © 2012 Jim's Random Notes - All Rights Reserved |