多数对话机器人都需要有简单的FAQ和chichat功能。在一般情况下,FAQ和chitchat的问答数量较多。如果使用一个意图来表示一个FAQ或者chitchat并为之搭配一个动作,那么故事写起来将非常复杂,从而导致整个过程非常低效。RASA提供了NLU组件ResponseSelector实现该功能。
第一步:
在nlu.yml中增加相关intent,并提供训练数据用于意图识别,如下所示:
- intent: chitchat/whatyoucando
examples: |
- 你能干什么?
- 你是干什么的?
- 你可以做什么?
- 你能做什么?
- 你有什么功能?
- 功能有哪些?
- 你的本领是什么?
- intent: faq/checkweather
examples: |
- 天气来源
- 你的天气数据哪里来的?
- 你是怎么查询天气的?
第二步:
在responses.yml中定义机器人回复的信息内容,如下所示:
responses:
utter_chitchat/whoyouare:
- text: 你好,我是Hank,一个无所不能的超级对话机器人(假的)。
utter_chitchat/whatyoucando:
- text: 我能帮你查找中国大陆地区城市级别的当下和未来两天的天气情况,也可以查询家庭常见疾病信息。
utter_faq/checkweather:
- text: 数据来源是心知天气
utter_faq/askgraph:
- text: 东南大学的知识图谱
第三步:
在rules.yml中定义规则,将意图和动作建立规则映射,rules是基于规则的流程控制,如下所示:
rules:
- rule: respond to FAQS
steps:
- intent: faq
- actions: utter_faq
- rule: respond to chitchat
steps:
- intent: chitchat
- actions: utter_chitchat
第四步:
在config.yml中增加组件和策略,使用ResponseSelector组件用于闲chitchat和faq,使用RulePolicy策略进行规则预测,如下所示:
pipeline:
- name: ResponseSelector
policies:
- name: RulePolicy
最后:
在domain.yml中增加对应的intents和actions,如下所示:
intents:
- chitchat
- faq
actions:
- respond_chitchat
- respond_faq
大功告成啦!!!