一个简单的马尔可夫链建模器和生成器,用于单词和句子的生成。
pymarkoff的Python项目详细描述
最初是概念的证明,我已经在足够多的项目中使用了这个 我决定把它出版以便于进口。名字是 播放类似于标记/降价的单词。嘿,我有时很有趣,
基本用途
如果您的数据是 已经表现得很好了。这些方法返回一个Markov对象 是这整件事的主心骨。您输入的单词序列或 句子应该用换行符分隔。使用next_word()和 next_sentence()生成所需的输出。
高级使用
用m = markoff.Markov(seeds)实例化,其中seeds是 可接受的次可接受的。可能是一个单词列表或者 如果要模拟^{tt1}的功能,请使用字母$ 和from_words()。每一个子元素都是 要建模的链。
你可以只供应一条或多条链。
然后使用m.generate(max_length=100)生成单个链 仅限于max_length在已知结尾处自动终止 状态(通常以标点符号结尾)。
示例
别忘了从import pymarkoff生成句子开始 ##
输入
m = pymarkoff.from_sentences( """The quick brown fox jumped over the lazy dog. Jack and Jill ran up the hill to fetch a pail of water. Whenever the black fox jumped the squirrel gazed suspiciously.""" ) print([m.next_sentence() for i in range(10)])
输出
[ 'The quick brown fox jumped over the black fox jumped the lazy dog.', 'The quick brown fox jumped the squirrel gazed suspiciously.', 'Whenever the squirrel gazed suspiciously.', 'Jack and Jill ran up the lazy dog.', 'Jack and Jill ran up the hill to fetch a pail of water.', 'Jack and Jill ran up the black fox jumped the hill to fetch a pail of water.', 'Whenever the lazy dog.', 'The quick brown fox jumped over the lazy dog.', 'Jack and Jill ran up the hill to fetch a pail of water.', 'Jack and Jill ran up the squirrel gazed suspiciously.' ]
生成单词
输入
seeds = """Ana Bastion D.Va Genji Hanzo Junkrat Lúcio McCree Mei Mercy Pharah Reaper Reinhardt Roadhog Soldier: 76 Symmetra Torbjörn Tracer Widowmaker Winston Zarya Zenyatta""" brain = pymarkoff.from_words(mystr) print([brain.next_word() for i in range(10)])
输出
['Zen', 'D.Vaperein', 'Za', 'To', 'Merya', 'Metrdo', 'So', 'Junjör', 'Ph', 'Mera']
更高级的使用
Markov.feed()方法可用于向模型中添加更多数据 一个Markov对象。这允许您在 时间,如果你愿意的话。
注释
这个模块还在开发中,主要是给我玩的 学习马尔可夫链。干杯。