怪雨是新手,刚刚接触Rasa,以下内容不一定正确。有错误的地方欢迎指出。
? 我的理解是一开源的机器学习框架用于AI助手和机器人。基于两个主要的模块
怪雨的系统:manjaro18+kde
安装前先更新同步数据库:sudo pacman -Syy
系统已经安装过以下内容的,可以跳过这一步(这一步也只是确保不会因为缺少什么而报错)
? - 安装pip3sudo pacman -S python-pip
? - 安装相关的依赖的python3的库pip install numpy pandas jieba sklearn
安装Rasa和Rasa-x 并初始化Rasa
? pip install rasa-x --extra-index-url https://pypi.rasa.com/simple
? rasa init
? rasax就是Rasa 带界面的工具安装后终端运行rasax
会自动弹出浏览器进入Rasax界面
现在就可以测试自带的简单数据了
不过好像只能进行2次对话,不知道是不是我的问题
输入/stop
就能推出Rasa shell
输入Rasa shell
就能再次进入对话!
? rasa init --no-prompt
不加后面的--no-prompt的话会详细的问你需要设置什么
cat data/nlu.md
来查看 (以下是markdown的格式)## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct
## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really
? ##后面是intents(意图) 就是以下的几条消息所要表达的意图
? -后面跟的就是消息了
? 意思就是把这一组消息都是这一意图
你可以通过cat config.yml
来查看配置文件
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en
pipeline: supervised_embeddings
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
- name: MemoizationPolicy
- name: KerasPolicy
- name: MappingPolicy
这些文件定义了你这个模型会使用的NLU和CORE组件
NLUpipeline的选择:
如果训练样例小于1000的 使用pipeline: "pretrained_embeddings_spacy"
如果训练样例大于1000的 使用pipeline: "supervised_embeddings"
以上两个是最重要的两个pipelines
这个文档是教你的助手如何去回应消息的
strories就是机器和用户的对话,core models通过真实的对话学习来训练自己。
同样cat data/stories.md
查看一下里面的内容(截取部分)
## happy path
* greet
- utter_greet
* mood_great
- utter_happy
## sad path 1
* greet
- utter_greet
* mood_unhappy
- utter_cheer_up
- utter_did_that_help
* affirm
- utter_happy
*greet
* 后面的是用户发送的消息(语句的意图或是实体)
- utter_greet
- 后面是action (机器人需要执行的操作,可以是回一段消息或是自定义操作)
? action中如果是回消息的话需要 回话必须要以utter_开头且与domain里面定义的一致
? 如果是自定义操作虽然没有强制要求不过最好以action_开头
? action这里还大有内容,后面学习了更新到后面的文章
[^]: 这里说域的话好像不太合适 保留英文Domain吧
老样子查看cat domain.yml
intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
templates:
utter_greet:
- text: Hey! How are you?
utter_cheer_up:
- text: 'Here is something to cheer you up:'
image: https://i.imgur.com/nGF1K8f.jpg
utter_did_that_help:
- text: Did that help you?
utter_happy:
- text: Great carry on!
utter_goodbye:
- text: Bye
actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
intents | 你期待用户说的话(意图) |
---|---|
actions | 机器人能做的和能说的 |
templates | 机器人回话模板 |
每次一的更新内容,我们都需要重新训练我们的模型
执行下列代码
rasa train
echo "Finished training."
执行rasa shell
data/nlu.md
中加入中文截取内容如下
## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct
- 是的
- 当然
- 正确
修改cat config.yml
的内容
把language: en
改为 language: zh
修改domain.yml
内容
修改templates: utter 的text的文本内容
templates:
utter_greet:
- text: 嗨!生活还好吗
utter_cheer_up:
- text: '希望这张图片能让你心情有所好转:'
image: https://i.imgur.com/nGF1K8f.jpg
utter_did_that_help:
- text: 对你有帮助吗?
utter_happy:
- text: 加油!继续!
utter_goodbye:
- text: 再见
尝试训练
rasa train
运行
rasa shell
完成,不过奇怪的是我输入当然 却 回我再见???训练出错了吗?
可能是回复help的结束吧。。。
原文:https://www.cnblogs.com/am5sia/p/11548802.html