RASA_Rules_规则

Rules

Rules are a type of training data used to train your assistant’s dialogue management model.

规则是一种用于训练你的助手的对话管理模型训练数据类型。

Rules describe short pieces of conversations that should always follow the same path.

规则描述了应该始终遵循相同路径的简短对话片段

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.

规则非常适合处理小型特定的对话模式,但与故事不同,规则没有能力泛化到未见过的对话路径

generalize是泛化的意思

Combine rules and stories to make your assistant robust and able to handle real user behavior.

结合规则故事来使你的助手健壮并能够处理真实用户行为

robust是健壮的意思

你的助手要想健壮,就必须使用规则,也要使用故事。

If you can’t decide whether to write a story or a rule to implement a certain behavior, see the best practices for Writing Conversation Data.

如果你无法决定是否编写一个故事规则来实现某种行为,请参阅编写对话数据的最佳实践。

很多时候,你可能是没有法子判断,老子到底是写story还是写rule

这个时候,你就要看看我们提供给你的最佳实践

我们早就为你想好了。

For additional examples on implementing rules in a Rasa assistant, refer to our Rules example bot.

有关在Rasa助手实现规则的更多示例,请参阅我们的规则示例机器人

你想要多学习一点,就看看我们的规则示例机器人。

Writing a Rule - 编写规则

Before you start writing rules, you have to make sure that the Rule Policy is added to your model configuration:

在你开始编写规则之前,你必须确保规则策略已添加到你的模型配置中:

policies:
- ... # Other policies
- name: RulePolicy

这说的是什么意思?

这说的意思就是,你有一个配置文件,是专门用来配置model的。

在这里面,你是要添加规则策略的。

这是你可以编辑规则的前提条件

Rules can then be added to the rules section of your training data.

规则可以添加到你的训练数据规则部分。

规则,也TMD放到训练数据当中?看起来是这样的。

To indicate that a rule can apply at any point in a conversation, start with the intent which starts the conversation and then add the actions which your assistant should perform 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 at the start of conversation as well as when the user decides to send a message with an intent greet in the middle of an ongoing conversation.

这个示例规则在对话开始时以及当用户在正在进行的对话中决定发送带有问候意图的消息时都适用

这TMD,是啥意思

这意思就是说,上面的rule,只要你发了greet意图,那么就做对应的动作。

就是这么一个简单的意思,MLGB的,说这么复杂。

Dialogue turns that only appear as rules in the training data and do not appear in stories will be ignored by ML-only policies like TEDPolicy at prediction 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 your stories, after RulePolicy predicts utter_greet, TEDPolicy will make predictions as if the greet, utter_greet turn did not occur.

例如,如果你按照上面的方式定义了问候规则,但没有将其添加到任何故事中,那么在RulePolicy预测了utter_greet之后,TEDPolicy将做出预测,就好像greetutter_greet回合没有发生一样。

这他妈的,是什么意思?就不放在story当中,TEDPolicy就给人家忽略了?

Rules for the Conversation Start - 对话开始的规则

To write a rule which only applies at the beginning of a conversation, add a conversation_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 the conversation, the rule will not match.

如果在对话过程中用户稍后在带有问候意图的消息中发送消息,则规则将不匹配。

为啥呢,因为你们都已经配置了conversation_start: true

Rules with Conditions - 带有条件的规则

Conditions describe requirements which have to be fulfilled for a rule to be applicable.

条件描述了规则适用的要求,这些要求必须得到满足

To do so, add any information about the prior conversation under the condition 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 includes slot_was_set events and active_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 the next 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 another story or rule, add wait_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 the assistant should execute another action before waiting for more user input.

表明助手应该在等待更多用户输入之前执行另一个动作。

Abort a Rule - 终止规则

Rules are designed to handle multiple output steps of a chatbot.

规则旨在处理聊天机器人的多个输出步骤

规则是处理多个输出的?

They are terminated as soon as user interaction is required.

一旦需要用户交互,它们就会被终止

这里说的它们是什么,就是rules

This happens automatically via launching a form, since it starts with the 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 causes a new intent prediction.

当终止完成时,即使用户输入了内容,utter_greet 也从未被执行,因为它会导致新的意图预测

Rules and Forms - 规则和表单

When a Form is active, the bot will make predictions based on how the form is defined, ignoring rules.

表单处于活动状态时,机器人将基于表单定义方式做出预测,并忽略规则。

Rules become applicable again if:

如果满足以下条件,则规则将再次适用:

the form fills all required slots

表单填写了所有必需的插槽

the form rejects its execution (see Handling 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
  • 20
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值