一个玩具马尔可夫链实现。
vokram的Python项目详细描述
vokram是一个玩具库,最有可能实现 错误的,极其低效的。
用法
命令行用法
将一段文本导入vokram,它将生成一些(希望如此) 根据正文合成的合理句子:
$ cat the_art_of_war.txt | vokram Spies cannot be obtained inductively from experience, nor by any danger.
可以控制输出和ngram大小的最大单词数 用于建立马尔可夫模型。所有命令行选项如下:
$ vokram --help
输出:
usage: vokram [-h] [-w NUM_WORDS] [-n NGRAM_SIZE] Generates plausible new sentences from a corpus provided on STDIN. optional arguments: -h, --help show this help message and exit -w NUM_WORDS, --num-words NUM_WORDS Maximum number of words in the resulting sentence. -n NGRAM_SIZE, --ngram-size NGRAM_SIZE
库使用
vokram也可以用作一个普通的旧python库:
>>> import vokram >>> corpus = open('the_art_of_war.txt') >>> model = vokram.build_word_model(corpus, 2) >>> vokram.markov_words(model, 25)) 'Hence it is not supreme excellence; supreme excellence consists in breaking the enemy's few.'
学分
Vokram的灵感来自于这个简单而平易近人的 Python implementation and explanation。