1.init rasa
2.rasa train nlu
3.rasa shell 对话
4.rasa run actions 让端口运行
rule和story内容不要冲突,可以重复
如何写一个故事
https://rasa.com/docs/rasa/writing-stories
rasa -x 安装
pip3 install -i https://pypi.rasa.com/simple rasa-x==0.37.0 --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple --use-deprecated=legacy-resolver
对外服务
./ngrok http 5002
https://zhuanlan.zhihu.com/p/329872032
docker run -p 8000:8000 rasa/duckling
换源
https://blog.csdn.net/yuzaipiaofei/article/details/80891108
nlu数据检查并且给出反馈,在系统上直接对对话进行标注,标注后倒入系统中
FORM
https://zhuanlan.zhihu.com/p/349170436
1.定义相关实体和槽位还有respond,格式为utter_ask_{entity},utter_ask_<form_name>_<slot_name>
2.定义form
3.定义action函数,函数一vaild开头
When designing stories, there are two groups of conversational interactions that need to be accounted for: happy and unhappy paths. Happy paths describe when the user is following the conversation flow as you’d expect and always providing the necessary information when prompted. However, users will often deviate from happy paths with questions, chit chat, or other asks. We call these unhappy path.
form的中断形式
https://rasa.com/docs/rasa/forms#writing-stories–rules-for-unhappy-form-paths
打岔再拉回
取消
检查数据正确性
检查返回意图正确性
给出各种评估指标,包括标签太相似了,标签错标注
自动的增加新的故事流程,故事流程是独立的
While reviewing conversations, you create tags to keep track of what happened in conversations, and flag specific messages to pinpoint problems.
检查意图过不去的,走了back机制的数据流程
Filter by intent or action confidence to see conversations that include low prediction values
Filter by a fallback action to see where your assistant was not able to move forward
Filter for a specific slot to see if users are filling out a form
Filter for positive or negative intents in feedback flows
设置正向和负向的fallback机制
If you have some kind of feedback skill built into your bot, you can filter on positive or negative user feedback to identify potential successes and failures. User feedback can also be a good use for automated tagging, such as is done in Sara the demo bot.
修改
修改的层级是先修改分类和实体,之后再去修改意图
Keep in mind that depending on your domain and stories, both the intent and entities of a user message can influence the prediction of the next action, so make sure both the intent and entities of the preceding user message are correct before correcting the predicted action(s).
增加故事量防止按下葫芦起了瓢
Having a large and representative set of test stories is the best way to ensure any updates you make to solve one problem don’t inadvertently cause new problems.
Other disruptive fixes include:
renaming an intent or entity
adding a new featurized slot which changes the logic of existing stories
adding a new custom action, or fixing one
removing all annotations and mentions of an entity
adding a custom NLU component
nlu操作
1.metadata:
sentiment: neutral
https://rasa.com/docs/rasa/training-data-format
适用于复杂的nlp任务
https://blog.csdn.net/csdn1e/article/details/117219163
2.chitchat/
进入到faq时候,能进入更细致的分类
3.实体的标注
[]{“entity”: “”, “role”: “”, “group”: “”, “value”: “”}
4.story和rule的区别,一个是大的,一个是小的
Stories and rules are both representations of conversations between a user and a conversational assistant. They are used to train the dialogue management model. Stories are used to train a machine learning model to identify patterns in conversations and generalize to unseen conversation paths. Rules describe small pieces of conversations that should always follow the same path and are used to train the RulePolicy.
特殊槽位被加入时候还能有特定的回掉方法
Validating Form Input:从用户输入中提取插slot后,可以验证提取的slot是否满足自己的场景要求。
from_entity
from_text
from_inten
from_trigger_intent
预设置一系列的内容比如intent,role,group都不能满足需要写代码了。
在上面的示例中,实体date唯一地设置槽arrival_date,具有角色(role)from的实体city唯一地设置槽departure_city,具有角色to的实体city唯一地设置槽arrival_city,因此,即使没有请求这些槽,也可以使用它们来匹配相应的槽。但是,不带角色的实体city可以填充departure_city和arrival_city两个槽位,具体取决于请求的槽位,因此如果在请求槽位arrival_date时提取实体城市,则表单将忽略该实体城市。
槽位事件
下面那个是说明槽位不重要,就只是显示一下名字即可,即该槽位被找到了,就可以进行之后的操作了。
多对一,多个意图对应一个结果:
rules
有点像故事,每次在一个小的范围内生成固定的回复。但是尽量少用,因为不能产出一个对话流程
Don’t overuse rules. Rules are great to handle small specific conversation patterns, but unlike stories, rules don’t have the power to generalize to unseen conversation paths. Combine rules and stories to make your assistant robust and able to handle real user behavior.
表的优先级高于规则
端到端训练
直接训练下一个意图,或者直接训练下一个回复
transformer推荐的模型
Regex features for entity extraction are currently only supported by the CRFEntityExtractor and the DIETClassifier components!
pipline
是一个dict,走过改流程就把相应的值存进去,以供后面的内容实用
多意图使用方法:
1.使用intent+实体 再加上故事的流程走不一样的内容
2.标签如下直接产出多意图的单分类
由槽位控制流程走向,尤其是意图重复
模型的流程可以选择要那些特征,例如,在selector上,只选择如下两个特征对模型有利
对不同的内容进行规约(or太多了就要想着简化标签了)
同义词:缩小对话流程走向
lookuptable:防暴恐,特殊的品牌等不能用正则来描述
rule,form,lookuptable不会计入TED流程,这就是区别
One-turn interactions: Some messages do not require any context to answer them. Rules are an easy way to map intents to responses, specifying fixed answers to these messages.
Fallback behavior: In combination with the FallbackClassifier, you can write rules to respond to low-confidence user messages with a certain fallback behavior.
Forms: Both activating and submitting a form will often follow a fixed path. You can also write rules to handle unexpected input during a form.
Because rules do not generalize to unseen conversations, you should reserve them for single-turn conversation snippets, and use stories to train on multi-turn conversations.
通过代码来降低故事的复杂度
故事到一定程度需要重构
通过检查槽位的方式,让机器人不再制杖
故事的开头完全可以由action开始,前后穿起来了,防止对话流程过长
抽象的有深度一些,比如说问银行的存款还有多少,则没必要走故事,因为每次回复都是一样的。
这个例子和之前的不一样,这个是还没开始,就直接停下来回复其他内容之后再回来。上一个case是回复了一部分然后中途打断
添加知识库
https://blog.csdn.net/csdn1e/article/details/117298298
知识库的详细实例
列出所有,指代消奇,查询实体和关系,对实体通过属性进行比较。查询实体有何属性/
https://blog.rasa.com/integrating-rasa-with-knowledge-bases/
和图谱的思路一样,除了实体有什么属性之外,实体上还需要有自己的属性,比如都是饭馆但是需要时东北的还是内蒙口味的。