如果说NLP是AI领域的皇冠,那么NLU则是那颗皇冠上的明珠。😏
克隆代码到本地
git clone https://github.com/crownpku/rasa_nlu_chi
处理流程
下载依赖
pip3 –default-timeout=1000 install -U jieba -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 sklearn
使用处理好的训练数据
python3 -m rasa_nlu.train -c sample_configs/config_jieba_mitie_sklearn.yml –data data/examples/rasa/demo-rasa_zh.json –path models
修改sklearn相关的代码
代码位置在: rasa_nlu/classifiers/sklearn_intent_classifier.py
修改的git记录
:param y: List of labels to convert to numeric representation - return self.le.inverse_transform(y) + #return self.le.inverse_transform(y) + return self.le.inverse_transform(np.squeeze(y)) def train(self, training_data, cfg, **kwargs): # type: (TrainingData, RasaNLUModelConfig, **Any) -> None
运行服务
python3 -m rasa_nlu.server -c sample_configs/config_jieba_mitie_sklearn.yml –path models
运行时的日志如下
2020-09-05 21:04:26 WARNING py.warnings - /Users/shengl/0000-hugerfuture/0-code/20-xiaoling/209-github-demo/Rasa_NLU_Chi/rasa_nlu/utils/__init__.py:236: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. return yaml.load(read_file(filename, "utf-8")) 2020-09-05 21:04:26+0800 [-] Log opened. 2020-09-05 21:04:26+0800 [-] Site starting on 5000 2020-09-05 21:04:26+0800 [-] Starting factory
- 测试请求
curl -XPOST localhost:5000/parse -d ‘{“q”:”我发烧了该吃什么药?”}’
测试效果
{ "intent": { "name": "medical", "confidence": 0.4941633432400155 }, "entities": [ { "entity": "disease", "value": "发烧", "start": 1, "end": 3, "confidence": null, "extractor": "ner_mitie" } ], "intent_ranking": [ { "name": "medical", "confidence": 0.4941633432400155 }, { "name": "restaurant_search", "confidence": 0.20337275690232598 }, { "name": "affirm", "confidence": 0.11712655806238002 }, { "name": "goodbye", "confidence": 0.11572347313876986 }, { "name": "greet", "confidence": 0.0696138686565087 } ], "text": "我发烧了该吃什么药?" }
请求后的日志
2020-09-05 21:04:26 WARNING py.warnings - /Users/shengl/0000-hugerfuture/0-code/20-xiaoling/209-github-demo/Rasa_NLU_Chi/rasa_nlu/utils/init.py:236: YAMLLoadWarning: calling yaml.load() without Loader=… is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
return yaml.load(read_file(filename, “utf-8”))
2020-09-05 21:04:26+0800 [-] Log opened.
2020-09-05 21:04:26+0800 [-] Site starting on 5000
2020-09-05 21:04:26+0800 [-] Starting factory <twisted.web.server.Site object at 0x110a80b00>
2020-09-05 21:06:09+0800 [-] /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/init.py:143: builtins.UserWarning: NumPy 1.14.5 or above is required for this version of SciPy (detected version 1.14.0)
2020-09-05 21:06:14+0800 [-] No Jieba Default Dictionary found
2020-09-05 21:06:14+0800 [-] No Jieba User Dictionary found
2020-09-05 21:06:15+0800 [-] Building prefix dict from the default dictionary …
2020-09-05 21:06:16+0800 [-] Dumping model to file cache /var/folders/xq/n7_8pfk11qz8p9l5s_09d5zw0000gn/T/jieba.cache
2020-09-05 21:06:16+0800 [-] Loading model cost 1.322 seconds.
2020-09-05 21:06:16+0800 [-] Prefix dict has been built successfully.
2020-09-05 21:06:16+0800 [-] “127.0.0.1” - - [05/Sep/2020:13:06:15 +0000] “POST /parse HTTP/1.1” 200 722 “-“ “curl/7.54.0”
版权声明
本文标题:105-使用rasa-nlu-chi构造中文意图识别服务
文章作者:盛领
发布时间:2020年09月05日 - 20:53:14
原始链接:http://blog.xiaoyuyu.net/post/217889f.html
许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。
如您有任何商业合作或者授权方面的协商,请给我留言:sunsetxiao@126.com
