文章目录
Rules
Rules are a type of
training data
used to train your assistant’sdialogue management model
.
规则是一种用于训练你的助手的对话管理模型
的训练数据
类型。
Rules describe
short pieces of conversations
that shouldalways follow the same path
.
规则描述了应该始终遵循相同路径的简短对话片段
。
Don’t
overuse
rules.
不要过度使用
规则。
Rules are great to handle
small specific conversation patterns
, but unlikestories
, rules don’t have the power togeneralize to unseen conversation paths
.
规则非常适合处理小型特定的对话模式
,但与故事
不同,规则没有能力泛化到未见过的对话路径
。
generalize是泛化的意思
Combine
rules
andstories
to make your assistantrobust
and able to handlereal user behavior
.
结合规则
和故事
来使你的助手健壮
并能够处理真实用户行为
。
robust是健壮的意思
你的助手要想健壮,就必须使用规则,也要使用故事。
If you can’t decide whether to write a
story
or arule
toimplement
a certain behavior, see the best practices forWriting Conversation Data
.
如果你无法决定是否编写一个故事
或规则
来实现某种行为,请参阅编写对话数据
的最佳实践。
很多时候,你可能是没有法子判断,老子到底是写story还是写rule
这个时候,你就要看看我们提供给你的最佳实践
我们早就为你想好了。
For additional examples on
implementing
rules ina Rasa assistant
, refer to ourRules example bot
.
有关在Rasa助手
中实现
规则的更多示例,请参阅我们的规则示例机器人
。
你想要多学习一点,就看看我们的规则示例机器人。
Writing a Rule - 编写规则
Before you start writing
rules
, you have to make sure that theRule Policy
is added to yourmodel configuration
:
在你开始编写规则
之前,你必须确保规则策略
已添加到你的模型配置
中:
policies:
- ... # Other policies
- name: RulePolicy
这说的是什么意思?
这说的意思就是,你有一个配置文件,是专门用来配置model的。
在这里面,你是要添加规则策略的。
这是你可以编辑规则的前提条件
Rules can then be added to the
rules
section ofyour training data
.
规则可以添加到你的训练数据
的规则
部分。
规则,也TMD放到训练数据当中?看起来是这样的。
To
indicate
that a rule can apply atany point
in a conversation, start with theintent
which starts the conversation and then add theactions
which your assistant shouldperform
in response to that.
要表明
规则可以在对话中的任何时间点
应用,请从启动对话的意图
开始,然后添加你的助手应对此做出的动作
。
这是啥意思,规则可以在任何时间点应用,这还要indicate表明吗?
这里说的是两个意思,第一个意思是告诉你,TMD,规则可以在对话的任意位置,都能用。
这里说的第二个意思是,来吧,咱们看看吧,咱们先从启动对话的意图开始。
rules:
- rule: Say `hello` whenever the user sends a message with intent `greet`
steps:
- intent: greet
- action: utter_greet
这个代码老有意思了。
rules这个是说,这下头可以配置很多的rule,这是没问题的
rule下头是什么东西,是steps
steps下面,就是意图和对应的动作,就是intent和action
This example rule
applies
atthe start of conversation
as well as when the user decides to send a message with an intentgreet
in the middle ofan ongoing conversation
.
这个示例规则在对话开始时
以及当用户在正在进行的对话
中决定发送带有问候
意图的消息时都适用
。
这TMD,是啥意思
这意思就是说,上面的rule,只要你发了greet意图,那么就做对应的动作。
就是这么一个简单的意思,MLGB的,说这么复杂。
Dialogue turns
that only appear as rules in thetraining data
and do not appear instories
will beignored
byML-only policies
likeTEDPolicy
atprediction
time.
只作为训练数据
中的规则出现而不在故事
中出现的对话回合
,在预测
时间将被仅使用机器学习的策略
(如TEDPolicy
)忽略
。
这一句话,就显示出来了英语,这种低级语言的劣根性。
这句话是什么意思?
这句话的意思是说,dialogue turns,对话回合被忽略的情况
对话回合是什么意思,就是一问一答喽
你在训练数据当中配置规则的时候,也是类似一问一答的。
如果有的对话回合,它是出现在训练数据当中了,它是被用来训练了。
但是在story当中没出现,什么TMD叫做在story当中没有出现?是说训练数据当中的story吧
我们说,这种对话回合会被忽略,就是使用机器学习策略真正对话的时候,你训练了,但是我不用你预测
它训练了,它没有在story,你用机器学习策略,它就不出现,那TMD是为啥?
rules:
- rule: Say `hello` whenever the user sends a message with intent `greet`
steps:
- intent: greet
- action: utter_greet
stories:
- story: story to find a restaurant
steps:
- intent: find_restaurant
- action: restaurant_form
- action: utter_restaurant_found
这就是个配置。
rules和stories不说了,就是说下面可以整一堆rule和story。
他们的rule和story都是崽子,都是做注释说明的。其实我感觉这种设计,挺差的,歧义。
实际的rule和story,都TMLGB的,都是steps,就是一个意图一个动作,或者一个意图多个动作
意图TMLGB是见名知义的,动作TMLGB也是见名知义的,CTMD
For example if you define the
greeting rule
as above and don’t add it to any of yourstories
, afterRulePolicy
predictsutter_greet
,TEDPolicy
will makepredictions
as if thegreet
,utter_greet
turn did not occur.
例如,如果你按照上面的方式定义了问候规则
,但没有将其添加到任何故事
中,那么在RulePolicy
预测了utter_greet
之后,TEDPolicy
将做出预测
,就好像greet
、utter_greet
回合没有发生一样。
这他妈的,是什么意思?就不放在story当中,TEDPolicy就给人家忽略了?
Rules for the Conversation Start - 对话开始的规则
To write a rule which only
applies
atthe beginning of a conversation
, add aconversation_start: true
to your rule:
要编写仅在对话开始时
适用的规则,请在规则中添加conversation_start: true
:
rules:
- rule: Say `hello` when the user starts a conversation with intent `greet`
conversation_start: true
steps:
- intent: greet
- action: utter_greet
If a user sends a message with the intent
greet
later in theconversation
, therule
will not match.
如果在对话
过程中用户稍后在带有问候
意图的消息中发送消息,则规则
将不匹配。
为啥呢,因为你们都已经配置了conversation_start: true
Rules with Conditions - 带有条件的规则
Conditions
describerequirements
which have to befulfilled
for arule
to beapplicable
.
条件
描述了规则
适用的要求
,这些要求
必须得到满足
。
To do so, add any information about the
prior
conversation under thecondition
key:
要实现这一点,请在condition
键下添加有关之前
对话的任何信息:
rules:
- rule: Only say `hello` if the user provided a name
condition:
- slot_was_set:
- user_provided_name: true
steps:
- intent: greet
- action: utter_greet
就是他妈的,设置一个条件,就是condition
上面的代码中,条件是什么,是问槽位填充了吗?这TMD,就是条件。
Possible information that you can include under
condition
includesslot_was_set
events andactive_loop
events.
您可以在condition
下包含的可能信息,包括slot_was_set
事件和active_loop
事件。
啥几把意思?就condition下面,就只能够放置这两个东西吗?
Skip Waiting for User Input at the End of a Rule - 在规则末尾跳过等待用户输入
By default,
rules
will wait for thenext user message
when finished with the last step:
默认情况下,当规则完成最后一步时,将等待下一个用户消息
:
rules:
- rule: Rule which will wait for user message when it was applied
steps:
- intent: greet
- action: utter_greet
# - action: action_listen
# Every rule implicitly includes a prediction for `action_listen` as last step.
# This means that Rasa will wait for the next user message.
- action: action_listen
每个规则都隐式地包含将action_listen
作为最后一步的预测。
这意味着Rasa将等待下一个用户消息。
If you want to hand over the
next action prediction
to anotherstory
orrule
, addwait_for_user_input: false
to your rule:
如果您想将下一个动作预测
交给另一个故事
或规则
,请将wait_for_user_input: false
添加到您的规则中:
rules:
- rule: Rule which will not wait for user message once it was applied
steps:
- intent: greet
- action: utter_greet
wait_for_user_input: false
This
indicates
that theassistant
shouldexecute
another action before waiting for more user input.
这表明
,助手
应该在等待更多用户输入之前执行另一个动作。
Abort a Rule - 终止规则
Rules
aredesigned
to handlemultiple output steps
of a chatbot.
规则
旨在处理聊天机器人的多个输出步骤
。
规则是处理多个输出的?
They are
terminated
as soon asuser interaction
is required.
一旦需要用户交互
,它们就会被终止
。
这里说的它们是什么,就是rules
This happens
automatically
vialaunching a form
, since it starts withthe user input of the first slot
.
这是通过启动表单
、自动
完成的,因为表单的启动始于第一个槽位的用户输入
。
第一个槽位需要用户输入,那么表单就启动了TMD,那么规则就终止了?
Therefore all steps after launch are ignored.
因此,启动后的所有步骤都将被忽略。
Termination
, however, can also be achieved manually
.
然而,也可以通过
手动
方式实现终止
。
This can be useful to
implement conditional termination criteria
.
这对于实现条件终止标准
可能是有用的。
Here is an example:
下面是一个例子:
rules:
- rule: Rule which will be conditionaly terminated
steps:
- intent: greet
- action: action_check_termination
- action: utter_greet
wait_for_user_input: true
这是啥意思,这是一个规则。
根据说明,这个规则,会条件性的、选择性的、终止。
用户说了问候语的意图,我们的动作是什么呢,首先检查一下会不会有终止
我们还有一个动作,动作就是回复问候的话,urrerance,读音是:阿特伦斯
from rasa_sdk import Action
from rasa_sdk.events import FollowupAction
class ActionCheckTermination(Action):
def name(self):
return "action_check_termination"
def run(self, dispatcher, tracker, domain):
# your business logic here
should_terminate = check_for_termination(<params>)
if should_terminate:
return [FollowupAction("action_listen")]
return []
utter_greet
is never executed when termination is done, even after user input, because it causesa new intent prediction
.
当终止完成时,即使用户输入了内容,utter_greet
也从未被执行,因为它会导致新的意图预测
。
Rules and Forms - 规则和表单
When a
Form
isactive
, thebot
will makepredictions
based on how theform
isdefined
, ignoring rules.
当表单
处于活动
状态时,机器人
将基于表单
的定义
方式做出预测
,并忽略规则。
Rules become applicable
again
if:
如果满足以下条件,则规则将再次适用:
the form fills all required
slots
表单填写了所有必需的插槽
the form
rejects
its execution (seeHandling Unhappy Paths
for more details)
表单拒绝
其执行(请参阅处理不满意路径
以获取更多详细信息)
总结(只看这个也可以)
模型配置中RulePolicy要有
规则在训练数据中配rules下面
训练中rules有stories没有的,预测时只有机器学习策略的预测将会忽略。
如果有表单激活了,那么就会忽略规则。
rules:
- rule: Say `hello` when the user starts a conversation with intent `greet`
conversation_start: true # 对话开始的规则
condition: # 带条件的规则
- slot_was_set:
- user_provided_name: true
steps:
- intent: greet
- action: action_check_termination # 终止规则
- action: utter_greet
wait_for_user_input: false # 跳过等待用户输入,默认是true