cfgen
1.0.0
使用马尔可夫链和无上下文语法的组合来生成具有两种语言模型功能的随机句子。
由威廉·吉尔平(William Gilpin)创建,2014- 2019年
自动安装
下载并提取存储库,然后运行
$ python setup.py install
通常,解析器将无法安装。因此,请运行
$ pip install git+git://github.com/emilmont/pyStatParser
手动安装
要求
可选安装(使用所有工具)
通过运行这些命令手动安装代码和基本依赖关系
$ git clone https://github.com/williamgilpin/cfgen
$ conda install nltk
$ pip install git+git://github.com/emilmont/pyStatParser
要评分语法或自动纠正结果句子,请安装Python软件包语言检查。
$ pip install language-check
将工具指向您的语料库并设置语言模型。在这里,我们将使用玛丽·雪莱(Mary Shelley)的科学怪人的2克。
my_model = GrammarModel('cfgen/full_books/frankenstein.txt', 2)
现在生成一个示例句子
example_sentence = my_model.make_sentence()
corrected_example_sentence = clean_output_text(example_sentence, use_language_tool=True)
print(corrected_example_sentence)
文件Demos.ipynb中给出了完整的工作流程。
从玛丽·雪莱(Mary Shelley)的科学怪人(Frankenstein)训练的模特中:
these conversation possessed to his time
those sense all fulfillment, me of affairs a soul been of I.
The next kindness her black, light of it I wished as our perish certainty.
horrible wretch that memory, their lake I to me, which the glad unhappiness
of the paroxysm of a several engagement of Clerval in her apartment and all
mainland, and on a progress, me surprised so divine me.
从启示录中训练的模型中:
Who said ever to no crown to was the listener and SECOND:
my man, and to the wheat,
and had eat in this angel.
Their pieces kill the sort the angel come up
to another translucent and weep any stone.
Her timeless will measure them to the day,
hold created with earth noises and hurled every nation.
There shown out upon the voice
It be in seventh which is to trample, I.
This tampering opened not for its time.
The land to their moment Who threw their glory to cherish that art.
The glory to the speaking, and at that white appearance, and say given
the thousand for the sake. And said show in myself. And it of no sweet victory
whose gateways enemies was loathe to the bowl
and it for them and worked out as my hast to every vision.
Their noise erase me.