Generate Tweets Using Markov Chains

Preliminaries

Load Corpus

The corpus I am using is just one I found online. The corpus you choose is central to generating realistic text.

# Get raw text as stringwithopen("brown.txt")asf:text=f.read()

Build Markov Chain

# Build the model.text_model=markovify.Text(text)

Generate One Tweet

# Print three randomly-generated sentences of no more than 140 charactersforiinrange(3):print(text_model.make_short_sentence(140))

Within a month, calls were still productive and most devotees of baseball attended the dozens of them.
Even death, therefore, has a leather bolo drawn through a local rajah in 1949.
He had a rather sharp and confident.