Generate Tweets Using Markov Chains


Preliminaries

import markovify

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 string
with open("brown.txt") as f:
    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 characters
for i in range(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.

Author: Chris Albon
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Chris Albon !
 Previous
零基础入门深度学习-长短时记忆网络 零基础入门深度学习-长短时记忆网络
参考资料:https://www.zybuluo.com/hanbingtao/note/581764 往期回顾在上一篇文章中,我们介绍了循环神经网络以及它的训练算法。我们也介绍了循环神经网络很难训练的原因,这导致了它在实际应用中,很难处
2019-12-20
Next 
Mine Twitter's Stream For Hashtags Or Words Mine Twitter's Stream For Hashtags Or Words
This is a script which monitor’s Twitter for tweets containing certain hashtags, words, or phrases. When one of those ap
2017-12-20 Chris Albon
  TOC