Title: Generate Tweets Using Markov Chains
Slug: generate_tweets_using_markov_chain
Summary: Generate Tweets Using Markov Chains
Date: 2016-11-01 12:00
Category: Python
Tags: Other
Authors: Chris Albon
In [1]:
import markovify
The corpus I am using is just one I found online. The corpus you choose is central to generating realistic text.
In [2]:
# Get raw text as string
with open("brown.txt") as f:
text = f.read()
In [3]:
# Build the model.
text_model = markovify.Text(text)
In [4]:
# Print three randomly-generated sentences of no more than 140 characters
for i in range(3):
print(text_model.make_short_sentence(140))