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.