开源bot工具Rasa学习---1
2017-07-09 15:57
281 查看
Rasa是一个不错的开源bot工具,全部基于python实现,主页是https://rasa-nlu.readthedocs.io/en/latest/index.html
本节是关于工具安装和初步运行的记录。
根据其文档进行安装,我选择的安装方式是:
git clone git@github.com:RasaHQ/rasa_nlu.git
cd rasa_nlu
pip install -r requirements.txt
python setup.py install
后端我选择的是“spaCy + sklearn”, 其中提示我需要安装sklearn-crfsuite。
然后当我安装这个工具时,又是各种与当前环境不匹配或找不到可用版本,最后通过以下方式解决了。
conda install -c conda-forge python-crfsuite=0.9.2
最后是在Ipython中针对自带的例子“ata\examples\rasa\demo-rasa.json”进行模型训练:
In [2]: run rasa_nlu/train.py -c config_spacy.json
INFO:rasa_nlu.utils.spacy_utils:Trying to load spacy model with name 'en'
INFO:rasa_nlu.components:Added 'nlp_spacy' to component cache. Key 'nlp_spacy-en'.
INFO:rasa_nlu.converters:Training data format at ./data/examples/rasa/demo-rasa.json is rasa_nlu
INFO:rasa_nlu.training_data:Training data stats:
- intent examples: 40 (4 distinct intents)
- found intents: 'affirm', 'goodbye', 'greet', 'restaurant_search'
- entity examples: 9 (2 distinct entities)
- found entities: 'cuisine', 'location'
INFO:rasa_nlu.model:Starting to train component nlp_spacy
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component ner_crf
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component ner_synonyms
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component intent_featurizer_spacy
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component intent_classifier_sklearn
Fitting 2 folds for each of 6 candidates, totalling 12 fits
[Parallel(n_jobs=1)]: Done 12 out of 12 | elapsed: 0.0s finished
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Successfully saved model into 'D:\Work\NLP\Task\Rasa\workspace\models\model_20170709-153926'
INFO:__main__:Finished training
针对以上得到的模型,进行预测的代码如下:
from rasa_nlu.model import Metadata, Interpreter
from rasa_nlu.config import RasaNLUConfig
metadata = Metadata.load('models/model_20170709-153926') # where model_directory points to the folder the model is persisted in
interpreter = Interpreter.load(metadata, RasaNLUConfig("config_spacy.json"))
interpreter.parse(u"I am looking for Chinese food")
Out[9]:
{'entities': [],
'intent': {'confidence': 0.7729154931115908, 'name': 'restaurant_search'},
'intent_ranking': [{'confidence': 0.7729154931115908,
'name': 'restaurant_search'},
{'confidence': 0.093570000080283558, 'name': 'goodbye'},
{'confidence': 0.093241162858677284, 'name': 'greet'},
{'confidence': 0.040273343949448648, 'name': 'affirm'}],
'text': 'I am looking for Chinese food'}
本节是关于工具安装和初步运行的记录。
根据其文档进行安装,我选择的安装方式是:
git clone git@github.com:RasaHQ/rasa_nlu.git
cd rasa_nlu
pip install -r requirements.txt
python setup.py install
后端我选择的是“spaCy + sklearn”, 其中提示我需要安装sklearn-crfsuite。
然后当我安装这个工具时,又是各种与当前环境不匹配或找不到可用版本,最后通过以下方式解决了。
conda install -c conda-forge python-crfsuite=0.9.2
最后是在Ipython中针对自带的例子“ata\examples\rasa\demo-rasa.json”进行模型训练:
In [2]: run rasa_nlu/train.py -c config_spacy.json
INFO:rasa_nlu.utils.spacy_utils:Trying to load spacy model with name 'en'
INFO:rasa_nlu.components:Added 'nlp_spacy' to component cache. Key 'nlp_spacy-en'.
INFO:rasa_nlu.converters:Training data format at ./data/examples/rasa/demo-rasa.json is rasa_nlu
INFO:rasa_nlu.training_data:Training data stats:
- intent examples: 40 (4 distinct intents)
- found intents: 'affirm', 'goodbye', 'greet', 'restaurant_search'
- entity examples: 9 (2 distinct entities)
- found entities: 'cuisine', 'location'
INFO:rasa_nlu.model:Starting to train component nlp_spacy
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component ner_crf
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component ner_synonyms
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component intent_featurizer_spacy
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Starting to train component intent_classifier_sklearn
Fitting 2 folds for each of 6 candidates, totalling 12 fits
[Parallel(n_jobs=1)]: Done 12 out of 12 | elapsed: 0.0s finished
INFO:rasa_nlu.model:Finished training component.
INFO:rasa_nlu.model:Successfully saved model into 'D:\Work\NLP\Task\Rasa\workspace\models\model_20170709-153926'
INFO:__main__:Finished training
针对以上得到的模型,进行预测的代码如下:
from rasa_nlu.model import Metadata, Interpreter
from rasa_nlu.config import RasaNLUConfig
metadata = Metadata.load('models/model_20170709-153926') # where model_directory points to the folder the model is persisted in
interpreter = Interpreter.load(metadata, RasaNLUConfig("config_spacy.json"))
interpreter.parse(u"I am looking for Chinese food")
Out[9]:
{'entities': [],
'intent': {'confidence': 0.7729154931115908, 'name': 'restaurant_search'},
'intent_ranking': [{'confidence': 0.7729154931115908,
'name': 'restaurant_search'},
{'confidence': 0.093570000080283558, 'name': 'goodbye'},
{'confidence': 0.093241162858677284, 'name': 'greet'},
{'confidence': 0.040273343949448648, 'name': 'affirm'}],
'text': 'I am looking for Chinese food'}
相关文章推荐
- 强大的Web开源测试工具—Selenium【待学习】
- 计算广告学习笔记2.1 合约广告系统-常见广告系统开源工具
- Jenkins学习总结(5)——免费DevOps开源工具简介
- ETL开源工具kettle学习笔记
- 谷歌生产级别开源容器调度和管理工具Kubernetes学习二
- iReaperPlus一个开源的工具项目,旨在获得MSDN学习资料,希望你能加入进来
- 开源矩阵计算工具Eigen学习笔记(一)
- Java基础学习总结(27)——7 款开源 Java 反编译工具
- Java基础学习总结(27)——7 款开源 Java 反编译工具
- Net-Snmp工具(学习SNMP的工具,开源项目)简单使用
- Android开发人员必须掌握的10 个开发工具+应该深入学习的10个开源应用项目
- 深度学习开源工具——caffe介绍
- 深度学习开源工具——caffe介绍
- 开发者和系统管理者最喜爱的开源工具Vim 起步学习的五个技巧
- 学习 FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- 开源Mysql热备份工具Xtrabackup详细学习手册
- 深度学习开源工具——caffe介绍
- 码农走向Quant之路_开源学习工具_Python_LEAN
- Libraries for developers 很好用的开发工具,集成很多开源项目供你学习
- 主流深度学习开源工具汇总