Transformer课程 业务对话机器人Rasa 3.x Testing Your Assistant

2023-12-21 21:50

本文主要是介绍Transformer课程 业务对话机器人Rasa 3.x Testing Your Assistant,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Transformer课程 业务对话机器人Rasa 3.x Testing Your Assistant

RASA 官网

https://rasa.com/
在这里插入图片描述

Testing Your Assistant

Rasa开源允许您通过运行测试故事来验证和测试端到端的对话。此外,还可以分别测试对话管理和消息处理(NLU)。

Validating Data and Stories

验证数据和故事#

数据验证可验证您的域、NLU数据或故事数据中是否未出现错误或重大不一致。要验证数据,请运行以下命令:

rasa data validate

运行结果如下
在这里插入图片描述

如果将max_history 值传递给配置config.yml 文件中的一个或多个策略 ,提供这些值中的最小值,如下所示:

rasa data validate --max-history <max_history>

运行结果如下
在这里插入图片描述

如果数据验证导致错误,那么训练模型也可能失败或产生糟糕的性能,因此在训练模型之前运行此检查总是好的。通过包含–fail-on-warnings标志,此步骤将在指示更多次要问题的警告时失败。

运行 rasa data validate数据验证不会测试您的规则是否与您的故事一致。但是,在训练期间,RulePolicy会检查规则和故事之间的冲突。任何此类冲突都将中止训练。

要阅读有关验证器和所有可用选项的更多信息,请参阅rasa数据验证文档。

Writing Test Stories

在测试故事中测试您的训练模型是对您的助手在某些情况下的行为有信心的最佳方式。测试故事以修改后的故事格式编写,允许您提供完整的对话,并测试在给定特定用户输入的情况下,您的模型将以预期的方式运行。当您开始从用户对话中引入更复杂的故事时,这一点尤为重要。

测试故事与训练数据中的故事相似,但也包括用户消息。
以下是一些例子:

  • Basics
    tests/test_stories.yml
stories:
- story: A basic story teststeps:- user: |hellointent: greet- action: utter_ask_howcanhelp- user: |show me [chinese]{"entity": "cuisine"} restaurantsintent: inform- action: utter_ask_location- user: |in [Paris]{"entity": "location"}intent: inform- action: utter_ask_price
  • Custom Actions
    tests/test_stories.yml
stories:
- story: A test where a custom action returns eventssteps:- user: |heyintent: greet- action: my_custom_action- slot_was_set:- my_slot: "value added by custom action"- action: utter_ask_age- user: |thanksintent: thankyou- action: utter_no_worries
  • Forms Happy Path
    tests/test_stories.yml
stories:
- story: A test story with a formsteps:- user: |hiintent: greet- action: utter_greet- user: |im looking for a restaurantintent: request_restaurant- action: restaurant_form- active_loop: restaurant_form- user: |[afghan](cuisine) foodintent: inform- action: restaurant_form- active_loop: null- action: utter_slots_values- user: |thanksintent: thankyou- action: utter_no_worries
  • Forms Unhappy Path

tests/test_stories.yml

stories:
- story: A test story with unexpected input during a formsteps:- user: |hiintent: greet- action: utter_greet- user: |im looking for a restaurantintent: request_restaurant- action: restaurant_form- active_loop: restaurant_form- user: |How's the weather?intent: chitchat- action: utter_chitchat- action: restaurant_form- active_loop: null- action: utter_slots_values- user: |thanksintent: thankyou- action: utter_no_worries

默认情况下,该命令将对任何名称以test_开头的文件中的故事运行测试。您还可以使用–stories参数提供特定的测试故事文件或目录。您可以通过运行以下命令来测试助手:

rasa test

test_stories.yml

#### This file contains tests to evaluate that your bot behaves as expected.
#### If you want to learn more, please see the docs: https://rasa.com/docs/rasa/testing-your-assistantstories:
- story: happy path 1steps:- user: |hello there!intent: greet- action: utter_greet- user: |amazingintent: mood_great- action: utter_happy- story: happy path 2steps:- user: |hello there!intent: greet- action: utter_greet- user: |amazingintent: mood_great- action: utter_happy- user: |bye-bye!intent: goodbye- action: utter_goodbye- story: sad path 1steps:- user: |hellointent: greet- action: utter_greet- user: |not goodintent: mood_unhappy- action: utter_cheer_up- action: utter_did_that_help- user: |yesintent: affirm- action: utter_happy- story: sad path 2steps:- user: |hellointent: greet- action: utter_greet- user: |not goodintent: mood_unhappy- action: utter_cheer_up- action: utter_did_that_help- user: |not reallyintent: deny- action: utter_goodbye- story: sad path 3steps:- user: |hiintent: greet- action: utter_greet- user: |very terribleintent: mood_unhappy- action: utter_cheer_up- action: utter_did_that_help- user: |nointent: deny- action: utter_goodbye- story: say goodbyesteps:- user: |bye-bye!intent: goodbye- action: utter_goodbye- story: bot challengesteps:- user: |are you a bot?intent: bot_challenge- action: utter_iamabot

运行结果如下

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
intent_report.json

{"deny": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 7,"confused_with": {}},"mood_unhappy": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 14,"confused_with": {}},"greet": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 13,"confused_with": {}},"mood_great": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 14,"confused_with": {}},"bot_challenge": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 4,"confused_with": {}},"affirm": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 6,"confused_with": {}},"goodbye": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 10,"confused_with": {}},"accuracy": 1.0,"macro avg": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 68},"weighted avg": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 68}
}

story_report.json

{"goodbye": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 2},"utter_cheer_up": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 3},"utter_did_that_help": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 3},"utter_iamabot": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 1},"mood_unhappy": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 3},"greet": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 5},"utter_greet": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 5},"mood_great": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 2},"deny": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 2},"bot_challenge": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 1},"utter_happy": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 3},"utter_goodbye": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 4},"affirm": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 1},"action_listen": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 16},"accuracy": 1.0,"macro avg": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 51},"weighted avg": {"precision": 1.0,"recall": 1.0,"f1-score": 1.0,"support": 51},"conversation_accuracy": {"accuracy": 1.0,"correct": 7,"with_warnings": 0,"total": 7}
}

会话测试只与包含的测试用例一样准确,因此您应该在改进助手的同时继续增加测试用例集。一个很好的经验法则是,你应该让你的测试故事代表真实对话的真实分布。RASAX使基于真实对话添加测试对话变得容易。

rasa test

有关更多配置选项,请参阅rasa测试的CLI文档。

测试自定义操作

Custom Actions自定义操作不会作为测试故事的一部分执行。如果您的自定义操作将任何事件附加到对话中,这必须反映在您的测试故事中(例如,通过向您的测试故事中添加slot_was_set事件)。

要测试自定义操作的代码,应该为它们编写单元测试,并将这些测试包括在CI/CD管道中。

Evaluating an NLU Model

除了测试故事外,还可以单独测试自然语言理解(NLU)模型。一旦您的助手部署到现实世界中,它将处理训练数据中未显示的消息。为了模拟这种情况,您应该始终留出部分数据用于测试。您可以使用以下方法将NLU数据拆分为训练集和测试集:

rasa data split nlu

在这里插入图片描述
在这里插入图片描述test_data.yml

version: "3.0"
nlu:
- intent: bot_challengeexamples: |- are you a bot?
- intent: affirmexamples: |- of course
- intent: denyexamples: |- no way- n
- intent: goodbyeexamples: |- have a nice day- cu
- intent: greetexamples: |- let's go- hi
- intent: mood_greatexamples: |- so perfect- great- wonderful
- intent: mood_unhappyexamples: |- I'm so sad- very sad- so saad

training_data.yml

version: "3.0"
nlu:
- intent: bot_challengeexamples: |- are you a human?- am I talking to a human?- am I talking to a bot?
- intent: affirmexamples: |- correct- indeed- y- that sounds good- yes
- intent: denyexamples: |- never- I don't think so- not really- no- don't like that
- intent: goodbyeexamples: |- cee you later- good night- good by- goodbye- bye bye- see you around- see you later- bye
- intent: greetexamples: |- hello there- good afternoon- good morning- goodevening- hey there- goodmorning- hey- hey dude- moin- hello- good evening
- intent: mood_greatexamples: |- super stoked- I am going to save the world- I am feeling very good- so good- I am great- perfect- extremely good- amazing- so so perfect- I am amazing- feeling like a king
- intent: mood_unhappyexamples: |- my day was horrible- I am disappointed- not very good- not good- so sad- unhappy- I am sad- I don't feel very well- super sad- extremly sad- sad

接下来,您可以使用以下方法查看经过训练的NLU模型对生成的测试集数据的预测效果:

rasa test nlu--nlu train_test_split/test_data.yml

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

要更广泛地测试模型,请使用交叉验证,它会自动创建多个训练/测试拆分:

rasa test nlu--nlu data/nlu.yml--cross-validation

运行结果如下

在这里插入图片描述

在这里插入图片描述

Rasa系列博客:

  • 业务对话机器人Rasa 3.x Internals及Rasa框架定制实战
  • 业务对话机器人Rasa核心算法DIET及TED论文详解
  • 业务对话机器人Rasa 3.x部署安装初体验
  • 业务对话机器人Rasa 3.x Playground
  • 业务对话机器人Rasa 3.x Command Line Interface
  • 业务对话机器人Rasa 3.x 命令 rasa shell 及rasa run
  • 业务对话机器人Rasa 3.x 命令rasa run actions、rasa test、rasa data split 、rasa data convert nlu
  • 业务对话机器人Rasa 3.x 命令rasa data migrate、rasa data validate、rasa export、rasa evaluate markers、rasa x
  • 业务对话机器人Rasa 3.x 会话驱动开发(Conversation-Driven Development)
  • 业务对话机器人Rasa 3.x 生成自然语言理解NLU数据
  • 业务对话机器人Rasa 3.x 写入会话数据(Writing Conversation Data)
  • 业务对话机器人Rasa 3.x 聊天和FAQs常见问题解答
  • 业务对话机器人Rasa 3.x docker安装部署
  • 业务对话机器人Rasa 3.x Handling Business Logic
  • 业务对话机器人Rasa 3.x Fallback and Human Handoff
  • 业务对话机器人Rasa 3.x Handling Unexpected Input
  • 业务对话机器人Rasa 3.x Contextual Conversations
  • 业务对话机器人Rasa 3.x Reaching Out to the User
  • 业务对话机器人Rasa 3.x 微信+Rasa机器人实战案例
  • 业务对话机器人Rasa 3.x Tuning Your NLU Model
  • 业务对话机器人Rasa 3.x Tuning Your NLU Model(二)

这篇关于Transformer课程 业务对话机器人Rasa 3.x Testing Your Assistant的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/521610

相关文章

使用 sql-research-assistant进行 SQL 数据库研究的实战指南(代码实现演示)

《使用sql-research-assistant进行SQL数据库研究的实战指南(代码实现演示)》本文介绍了sql-research-assistant工具,该工具基于LangChain框架,集... 目录技术背景介绍核心原理解析代码实现演示安装和配置项目集成LangSmith 配置(可选)启动服务应用场景

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

SpringBoot整合DeepSeek实现AI对话功能

《SpringBoot整合DeepSeek实现AI对话功能》本文介绍了如何在SpringBoot项目中整合DeepSeekAPI和本地私有化部署DeepSeekR1模型,通过SpringAI框架简化了... 目录Spring AI版本依赖整合DeepSeek API key整合本地化部署的DeepSeek

利用Python编写一个简单的聊天机器人

《利用Python编写一个简单的聊天机器人》这篇文章主要为大家详细介绍了如何利用Python编写一个简单的聊天机器人,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 使用 python 编写一个简单的聊天机器人可以从最基础的逻辑开始,然后逐步加入更复杂的功能。这里我们将先实现一个简单的

Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)

《Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)》:本文主要介绍Python基于火山引擎豆包大模型搭建QQ机器人详细的相关资料,包括开通模型、配置APIKEY鉴权和SD... 目录豆包大模型概述开通模型付费安装 SDK 环境配置 API KEY 鉴权Ark 模型接口Prompt

业务中14个需要进行A/B测试的时刻[信息图]

在本指南中,我们将全面了解有关 A/B测试 的所有内容。 我们将介绍不同类型的A/B测试,如何有效地规划和启动测试,如何评估测试是否成功,您应该关注哪些指标,多年来我们发现的常见错误等等。 什么是A/B测试? A/B测试(有时称为“分割测试”)是一种实验类型,其中您创建两种或多种内容变体——如登录页面、电子邮件或广告——并将它们显示给不同的受众群体,以查看哪一种效果最好。 本质上,A/B测

【IPV6从入门到起飞】5-1 IPV6+Home Assistant(搭建基本环境)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant #搭建基本环境 1 背景2 docker下载 hass3 创建容器4 浏览器访问 hass5 手机APP远程访问hass6 更多玩法 1 背景 既然电脑可以IPV6入站,手机流量可以访问IPV6网络的服务,为什么不在电脑搭建Home Assistant(hass),来控制你的设备呢?@智能家居 @万物互联

业务协同平台--简介

一、使用场景         1.多个系统统一在业务协同平台定义协同策略,由业务协同平台代替人工完成一系列的单据录入         2.同时业务协同平台将执行任务推送给pda、pad等执行终端,通知各人员、设备进行作业执行         3.作业过程中,可设置完成时间预警、作业节点通知,时刻了解作业进程         4.做完再给你做过程分析,给出优化建议         就问你这一套下

深入解析秒杀业务中的核心问题 —— 从并发控制到事务管理

深入解析秒杀业务中的核心问题 —— 从并发控制到事务管理 秒杀系统是应对高并发、高压力下的典型业务场景,涉及到并发控制、库存管理、事务管理等多个关键技术点。本文将深入剖析秒杀商品业务中常见的几个核心问题,包括 AOP 事务管理、同步锁机制、乐观锁、CAS 操作,以及用户限购策略。通过这些技术的结合,确保秒杀系统在高并发场景下的稳定性和一致性。 1. AOP 代理对象与事务管理 在秒杀商品

基于树梅派的视频监控机器人Verybot

最近这段时间做了一个基于树梅派 ( raspberry pi ) 的视频监控机器人平台 Verybot ,现在打算把这个机器人的一些图片、视频、设计思路进行公开,并且希望跟大家一起研究相关的各种问题,下面是两张机器人的照片:         图片1:                   图片2                    这个平台的基本组成是: