<Rasa实战> 内容摘要(三)

FAQ和闲聊(chitchat)功能

官方介绍

https://rasa.com/docs/rasa/chitchat-faqs/

需要更新config.yml

横版说明:

pipeline:
  - name: XXXFeaturizer   # 替换为真实的特征提取组件
  - name: XXXClassifier   # 替换为真实的意图分类组件
    - name: ResponseSelector

policies:
  # other policies
  - name: RulePolicy  

以下是实例部分

pipeline:
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: char_wb
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
policies:
# Other policy
  - name: RulePolicy

其中:

  • ResponseSelector必须要加的
  • RulePolicy也是必须要加的.

默认情况下,ResponseSelector 将为所有检索意图构建一个检索模型。 要分别检索常见问题解答和闲聊的响应,请使用多个 ResponseSelector 组件并指定检索意图键:
(By default, the ResponseSelector will build a single retrieval model for all retrieval intents. To retrieve responses for FAQs and chitchat separately, use multiple ResponseSelector components and specify the retrieval_intent key:)

pipeline:
# Other components
- name: ResponseSelector
  epochs: 100
  retrieval_intent: faq
- name: ResponseSelector
  epochs: 100
  retrieval_intent: chitchat

定义检索意图和 ResponseSelector

考虑一个示例,您有 20 个不同的常见问题解答。 尽管每个问题都表示为一个单独的意图,但所有常见问题解答意图在对话中都以相同的方式处理。 对于每个常见问题解答意图,助手会根据提出的问题检索正确的响应。

您可以使用单个操作,而不是编写 20 条规则,例如 utter_faq 使用单个规则处理所有常见问题解答,方法是将它们组合在一个名为例如的检索意图下。 常问问题。

单个操作使用 ResponseSelector 的输出来为用户询问的特定 FAQ 返回正确的响应。

创建规则

rules:
  - rule: respond to FAQs
    steps:
    - intent: faq
    - action: utter_faq
  - rule: respond to chitchat
    steps:
    - intent: chitchat
    - action: utter_chitchat

utter_faq 和 utter_chitchat 动作将使用 ResponseSelector 的预测来返回实际的响应消息。

更新NLU训练的数据

如:
data/nlu.yml

nlu:
  - intent: chitchat/ask_name
    examples: |
      - What is your name?
      - May I know your name?
      - What do people call you?
      - Do you have a name for yourself?
  - intent: chitchat/ask_weather
    examples: |
      - What's the weather like today?
      - Does it look sunny outside today?
      - Oh, do you mind checking the weather for me please?
      - I like sunny days in Berlin.

确保domain.yml文件添加 chitchat 这个意图
domain.yml

intents:
# other intents
- chitchat

定义responses响应

domain.yml

responses:
  utter_chitchat/ask_name:
  - image: "https://i.imgur.com/zTvA58i.jpeg"
    text: Hello, my name is Retrieval Bot.
  - text: I am called Retrieval Bot!
  utter_chitchat/ask_weather:
  - text: Oh, it does look sunny right now in Berlin.
    image: "https://i.imgur.com/vwv7aHN.png"
  - text: I am not sure of the whole week but I can see the sun is out today.

小结

Once you’ve done the following, you can train your bot and try it out!

  • Add RulePolicy to your policies and ResponseSelector to your pipeline in config.yml
  • Add at least one rule for responding to FAQs/chitchat
  • Add examples for your FAQs/chitchat intents
  • Add responses for your FAQs/chitchat intents
  • Update the intents in your domain

现在,您的助手应该能够正确且一致地响应常见问题解答或闲聊,即使这些感叹词发生在您的助手正在帮助用户完成另一项任务时。

附:

我正在「AI爱好者社区」服务器中聊天,来和我一起畅聊吧 ~ 点击加入:https://fanbook.mobi/3H6D5FVN
网页版,请入:
https://fanbook.mobi/web/home
网页版如要加入社区,请复制社区ID(3H6D5FVN)加入.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值