当前位置: 首页 > article >正文

Rasa对话模型——做一个语言助手

1、Rasa模型

1.1 模型介绍

Rasa是一个用于构建对话 AI 的开源框架,主要用于开发聊天机器人和语音助手。Rasa 提供了自然语言理解(NLU)和对话管理(DM)功能,使开发者能够创建智能、交互式的对话系统。

1.2 主要功能

  • 意图识别:

    根据用户输入识别用户的意图,如问候、查询信息、执行任务等。
  • 实体提取:

    从用户输入中提取有用的信息,如时间、地点、数量等。
  • 对话管理:

    管理多轮对话的状态,确保对话流程的连贯性和逻辑性。
  • 自定义动作:

    支持在对话中调用自定义动作,如查询数据库、调用外部API等。
  • 多渠道支持:

    支持集成多个聊天渠道,如Slack、Facebook Messenger、Telegram、WhatsApp等。
  • 对话训练和测试:

    提供方便的训练和测试工具,帮助开发者优化和验证对话系统的性能。

1.3  工作流程

  • 数据收集和标注:

    收集用户输入示例,并将其标注为意图和实体。
  • 模型训练:

    使用收集和标注的数据训练NLU和对话管理模型。
  • 对话设计:

    使用故事(stories)和规则(rules)定义对话流程和策略。
  • 自定义动作实现:

    编写自定义动作代码,实现对外部服务的调用和复杂任务的处理。
  • 集成和部署:

    将Rasa系统集成到所需的聊天渠道,并进行部署和上线。
  • 监控和优化:

    通过日志和用户反馈,持续监控和优化对话系统的性能。

2、本地环境

2.1 python环境

在Windows上使用命令行窗口查看所安装的python版本

python --version

2.2 Visual Studio Code编译

Visual Studio Code是一款由微软开发且跨平台的免费源代码编辑器。该软件以扩展的方式支持语法高亮、代码自动补全、代码重构功能,并且内置了命令行工具和Git 版本控制系统。

3、程序内容

3.1 程序框架

rasa/
├── data/
   ├── nlu.yml                        //收集并标注训练数据,确保覆盖用户的所有可能输入。
   └── stories.yml                       //编写示例对话,展示系统应如何处理不同的对话场景。
├── models/
├── config.yml                               //配置NLU和对话管理的模型管道和策略。
├── domain.yml                                //定义对话域,包括意图、实体、槽和响应模板。
└── endpoints.yml

3.2 具体代码

3.2.1 nlu.yml

version: "3.1"

nlu:
- intent: greet
  examples: |
    - hey
    - hello
    - hi
    - hello there
    - good morning
    - good evening
    - moin
    - hey there
    - let's go
    - hey dude
    - goodmorning
    - goodevening
    - good afternoon

- intent: goodbye
  examples: |
    - cu
    - good by
    - cee you later
    - good night
    - bye
    - goodbye
    - have a nice day
    - see you around
    - bye bye
    - see you later

- intent: affirm
  examples: |
    - yes
    - y
    - indeed
    - of course
    - that sounds good
    - correct

- intent: deny
  examples: |
    - no
    - n
    - never
    - I don't think so
    - don't like that
    - no way
    - not really

- intent: mood_great
  examples: |
    - perfect
    - great
    - amazing
    - feeling like a king
    - wonderful
    - I am feeling very good
    - I am great
    - I am amazing
    - I am going to save the world
    - super stoked
    - extremely good
    - so so perfect
    - so good
    - so perfect

- intent: mood_unhappy
  examples: |
    - my day was horrible
    - I am sad
    - I don't feel very well
    - I am disappointed
    - super sad
    - I'm so sad
    - sad
    - very sad
    - unhappy
    - not good
    - not very good
    - extremly sad
    - so saad
    - so sad

- intent: bot_challenge
  examples: |
    - are you a bot?
    - are you a human?
    - am I talking to a bot?
    - am I talking to a human?

 3.2.2 stories.yml 

version: "3.1"

stories:

- story: happy path
  steps:
  - intent: greet
  - action: utter_greet
  - intent: mood_great
  - action: utter_happy

- story: sad path 1
  steps:
  - intent: greet
  - action: utter_greet
  - intent: mood_unhappy
  - action: utter_cheer_up
  - action: utter_did_that_help
  - intent: affirm
  - action: utter_happy

- story: sad path 2
  steps:
  - intent: greet
  - action: utter_greet
  - intent: mood_unhappy
  - action: utter_cheer_up
  - action: utter_did_that_help
  - intent: deny
  - action: utter_goodbye

3.2.3 domain.yml

version: "3.1"

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - bot_challenge

responses:
  utter_greet:
  - text: "Hey! How are you?"

  utter_cheer_up:
  - text: "Here is something to cheer you up:"
    image: "https://i.imgur.com/nGF1K8f.jpg"

  utter_did_that_help:
  - text: "Did that help you?"

  utter_happy:
  - text: "Great, carry on!"

  utter_goodbye:
  - text: "Bye"

  utter_iamabot:
  - text: "I am a bot, powered by Rasa."

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

3.3 代码运行

在vscode中右击项目目录,在集成终端中打开,然后输入下面的命令创建虚拟环境(也可以使用命令行界面导航到该文件夹下)

python -m venv venv

初始化rasa,然后一直输入y就可以啦

rasa init

 

4.总结

使用Rasa构建一个属于自己的语言助手,自己创建语料库,你也来试一试吧!


http://www.kler.cn/news/315019.html

相关文章:

  • Qt窗口——QToolBar
  • JVM常见面试题(三):类加载器,双亲委派模型,类装载的执行过程
  • python中ocr图片文字识别样例(二)
  • Spring MVC设置请求头和响应头的Header
  • Unity DOTS物理引擎的核心分析与详解
  • 植物大战僵尸【源代码分享+核心思路讲解】
  • [每日一练]MySQL中的正则表达式的应用
  • Day 9:1306 跳跃游戏III
  • 神经网络构建原理(以MINIST为例)
  • Java | Leetcode Java题解之第416题分割等和子集
  • 国内可以使用的ChatGPT服务【9月持续更新】
  • 828华为云征文 | 云服务器Flexus X实例:多智能体对话框架 AutoGen 部署和实例运行
  • 重修设计模式-结构型-门面模式
  • python 实现binomial coefficient二项式系数算法
  • excel 单元格一直显示年月日
  • Contact Form 7最新5.9.8版错误修复方案
  • ClickHouse 与 Quickwit 集成实现高效查询
  • 适用于QF的存档系统
  • react的事件绑定
  • vulnhub(12):bob 1.0.1(gpg文件解密)
  • @PostConstruct
  • <刷题笔记> 力扣236题——二叉树的公共祖先
  • 全面详尽的 PHP 环境搭建教程
  • C++ 元编程
  • 18938 汉诺塔问题
  • 《深度学习》PyTorch 常用损失函数原理、用法解析
  • 【电力系统】基于遗传算法的33节点电力系统无功优化及MATLAB实现
  • LeetCode337. 打家劫舍III
  • springbootKPL比赛网上售票系统
  • Maven 项目无法下载某个依赖