赞
踩
在做一个中医问诊的项目上,决定使用rasa框架来搭建一个多轮对话的智能问诊的模型。
本文介绍在windows系统上 rasa、MITIE、rasa-nlu-chi、rasa x 的安装。电脑上已经有了anaconda和pycharm,所以没有这部分的相关过程。
从创建好一个虚拟环境开始----->
1.使用conda 命令创建一个新的虚拟环境
create -n medicalrasa python==3.8
2.进入虚拟环境
conda activate medicalrasa
3.安装rasa (自动安装最新版本,有版本要求的带上版本号,另外当前rasa3.0以上版本暂不支持rasa x,有rasa x使用需求的请直接安装rasa x)
说明:
换源(-i http://mirrors.aliyun.com/pypi/simple/)、
信任镜像链接(–trusted-host mirrors.aliyun.com)
避免版本冲突导致安装失败(–use-deprecated=legacy-resolver)
因为有版本冲突,如果没加这个参数会进入死循环找版本,一直出现: pip is looking at multiple versions of urllib3 to determine which version is compatible with other requirements. This could take a while.
pip install rasa -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com --use-deprecated=legacy-resolver
或安装rasa x
pip3 install rasa-x --extra-index-url https://pypi.rasa.com/simple
4.安装完后有可能出现红色报错代码,提示依赖包版本不适配,更换报错的包的版本
pip uninstall xxx
pip install xxx==xxx
5.输入python
,进入python环境,输入import tensorflow
,尝试导入tensorflow以确定tensorflow是否安装好
可能报错:(也是依赖包版本问题)
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
更换tensorflow依赖包版本
pip uninstall protobuf
pip install protobuf==3.20.1
6.建一个文件夹用于rasa工程并在该目录下(确保该文件夹为空)运行rasa init --no-prompt
,将在当前文件夹下建立rasa初始化结构文件目录
7.其他
如无必要不需要安装ujson等包,pip install rasa
会自动找到最新的rasa稳定版本(目前自动安装3.1.0版本)同时会自动安装tensorflow等依赖,不需要自己单独装一遍
可使用pip show rasa
查看当前rasa包信息及安装位置,
或使用rasa --version
查看更详细的版本信息。
Rasa_NLU_Chi:Rasa NLU本身是只支持英文和德文。中文因为其特殊性需要加入特定的tokenizer作为整个流水线的一部分。Rasa_NLU_Chi加入了jieba作为中文的tokenizer,适用于中文的rasa NLU。
MITIE:Rasa NLU的实体识别和意图识别的任务,需要一个训练好的MITIE的模型。这个MITIE模型是非监督训练得到的,类似于word2vec中的word embedding。另外有的也用到了Kashgari
这个NLP框架,为命名实体识别(NER)、词性标注(PoS)和文本分类任务构建模型。不过MITIE以能够解决当前任务,不累述。
参考:用Rasa NLU构建自己的中文NLU系统
8.安装Rasa_NLU_Chi
下载链接地址:https://github.com/crownpku/rasa_nlu_chi
首先下载代码并解压到rasa工程文件夹内,然后打开cmd进入到Rasa_NLU_Chi-master文件目录,
执行python setup.py install
安装。
完成安装:
9. 安装MITIE
MITIE在windows系统上的安装比较麻烦,需要有Visual Studio 环境、cmake、boost, 三者缺一不可。具体安装过程如下:
A. 安装 Visual Studio,以 vs2017 社区版为例。在官网下载安装包,安装时组件勾选 如图 2-2,安装。安装完成后,把 vs 安装路径(你的实际安装路径) C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64 加入环境变量,并 在该路径下 cmd,输入‘cl’不报错则安装成功。如图:
B. 安装 cmake。官网下载:https://cmake.org/download/,解压后把 bin 目录路径, 配置到 path 环境变量中,例如:D:\SoftInstall\cmake-3.19.1-win64-x64\bin。运行 cmake --version 测试,确保安装成功:
C. 安 装 boost 。 官 网 下 载 : https://www.boost.org/ , 解 压 后 在 目 录 D:\boost_1_69_0\tools\build 下 cmd,输入.\bootstrap.bat,开始安装。安装成功后输 入.\b2 --prefix=D:\boost\bin install,其中“D:\”为任意安装路径。然后把这个目录 增加到系统的环境变量中 D:\boost\bin\bin。最后,确保安装成功:
D.安装MITIE。下载 MITIE 安装包: https://github.com/mit-nlp/MITIE 解压后的文件放在工程目录下,和安装Rasa_NLU_Chi的步骤一样,在相应目录下运行 python setup.py install
命令安装。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。