基于Rasa框架搭建中⽂机器⼈对话系统
Rasa是⼀个能⽤于构建机器⼈对话系统的框架,基于Rasa框架搭建机器⼈对话系统,可以使⽤于⼯业各类语⾳智能服务场景,如:远程医疗问诊、智能客户服务、保险产品销售、⾦融催收服务、⼿机智能助⼿等领域。⽀持基于规则、填槽和机器学习来构建对话系统。主要模块包括:NLU(意图识别和实体提取)和Core(基于模型及规则进⾏回复)。提供了搭建对话系统的脚⼿架。
常⽤命令有:
rasa init 创建项⽬
rasa train 训练NLU和Core模型
rasa run actions 启动动作服务(主要是⾃⼰写的动作,系统默认的动作,不需要单独启动)
rasa shell 启动对话机器⼈ (会⾃动启动默认动作服务)
涉及配置⽂件有:
# Configuration for Rasa NLU.
# rasa/docs/rasa/nlu/components/
language: zh
pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See rasa/docs/rasa/tuning-your-model for more information.
#  - name: WhitespaceTokenizer
- name: JiebaTokenizer #⽀持中⽂
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: char_wb
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
constrain_similarities: true
- name: EntitySynonymMapper
- name: ResponseSelector
epochs: 100
constrain_similarities: true
- name: FallbackClassifier
threshold: 0.3
ambiguity_threshold: 0.1
# Configuration for Rasa Core.
# rasa/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See rasa/docs/rasa/policies for more information.validation框架
- name: MemoizationPolicy
- name: TEDPolicy
max_history: 5
epochs: 100
constrain_similarities: true
- name: RulePolicy
version: '2.0'
config:
store_entities_as_slots: true
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true intents:
- greet:
use_entities: true
- deny:
use_entities: true
- request_names:
use_entities: true
- goodbye:
use_entities: true
- affirm:
use_entities: true
-
mood_great:
use_entities: true
- mood_unhappy:
use_entities: true
- bot_challenge:
use_entities: true
entities: []
slots:
first_name:
type: slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
last_name:
type: slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
name_spelled_correctly:
type: slots.BooleanSlot
initial_value: null
auto_fill: true
influence_conversation: true
requested_slot:
type: slots.UnfeaturizedSlot    initial_value: null
auto_fill: true
influence_conversation: false responses:
utter_greet:
- text: 嗨,你好吗?
utter_cheer_up:
- image: i.imgur/nGF1K8f.jpg
text: '这是某些使你嗨起来的东西:'
utter_did_that_help:
-
text: 这对你有帮助吗?
utter_happy:
- text: 好极了,继续!
utter_goodbye:
- text: 再见
utter_iamabot:
- text: 我是个机器⼈,由Rasa框架提供⽀持.
utter_ask_first_name:
- text: 你贵姓?
utter_ask_last_name:
- text: 你的名字?
utter_ask_name_spelled_correctly:
- buttons:
- buttons:
- payload: /affirm
title: 是
- payload: /deny
title: 否
text:  姓 {first_name} 拼写对了吗?
utter_submit:
- text: 好的,谢谢!
utter_slots_values:
-
text: 我记住你了, {first_name} {last_name}!
actions:
- utter_greet
- utter_slots_values
- utter_submit
- validate_name_form
forms:
name_form:
first_name:
- type: from_text
last_name:
-
type: from_text
e2e_actions: []
# This file contains the credentials for the voice & chat platforms
# which your bot is using.
# rasa/docs/rasa/messaging-and-voice-channels
rest:
#  # you don't need to provide anything here - this channel doesn't
#  # require any credentials
#facebook:
#  verify: "<verify>"
#  secret: "<your secret>"
#  page-access-token: "<your page access token>"
#slack:
#  slack_token: "<your slack token>"
#  slack_channel: "<the slack channel>"
#  slack_signing_secret: "<your slack signing secret>"
#socketio:
#  user_message_evt: <event name for user message>
#  bot_message_evt: <event name for bot messages>
#  session_persistence: <true/false>
#mattermost:
#  url: "<mattermost instance>/api/v4"
#  token: "<bot token>"
#  webhook_url: "<callback URL>"
# This entry is needed if you are using Rasa X. The entry represents credentials # for the Rasa X "channel", i.e. Talk to your bot and Share with guest testers. rasa:
url: "localhost:5002/api"
# This file contains the different endpoints your bot can use.
# Server where the models are pulled from.
# rasa/docs/rasa/model-storage#fetching-models-from-a-server
#models:
#  url: my-server/models/default_core@latest
#  wait_time_between_pulls:  10  # [optional](default: 100)
# Server which runs your custom actions.
# rasa/docs/rasa/custom-actions
#action_endpoint:
#  url: "localhost:5055/webhook"
action_endpoint:
url: "localhost:5055/webhook"
# Tracker store which is used to store the conversations.
# By default the conversations are stored in memory.
# rasa/docs/rasa/tracker-stores
#tracker_store:
#    type: redis
#    url: <host of the redis instance, e.g. localhost>
#    port: <port of your redis instance, usually 6379>
#    db: <number of your database within redis, e.g. 0>
#    password: <password used for authentication>
#    use_ssl: <whether or not the communication is encrypted, default false>
#tracker_store:
#    type: mongod
#    url: <url to your mongo instance, e.g. mongodb://localhost:27017>
#    db: <name of the db within your mongo instance, e.g. rasa>
#    username: <username used for authentication>
#    password: <password used for authentication>
tracker_store:
type: SQL
dialect: sqlite
db: trackers.db
# Event broker which all conversation events should be streamed to.
# rasa/docs/rasa/event-brokers
#event_broker:
#  url: localhost
#  username: username
#  password: password
#  queue: queue
event_broker:
type: SQL
dialect: sqlite
db: events.db
< 本案例使⽤的姓名列表。
孙悟空
猪⼋戒
唐三藏
沙悟净
诸葛青云
数据,主要包括:
version: "2.0"
nlu:
- intent: greet
examples: |
- 你好
- 上午好
- 中午好
- 嗨
- intent: goodbye
examples: |
- 再见
- 回头见
- 晚安
- intent: affirm
examples: |
- 是的
- 有
- 当然
- 听上去不错
- intent: deny
examples: |
- 不
- 不要
- 没有
- 没有
- 我不喜欢
- intent: mood_great
examples: |
- 太好了
- 感觉不错
- ⾮常好
-
intent: mood_unhappy
examples: |
- 不开⼼
- 感到沮丧
- 不⾼兴
- 不太好
- intent: bot_challenge
examples: |
- 你是个机器⼈吗?
- 你是⼈类吗?
- 我是在和机器⼈讲话吗?
-
我是在和⼈类讲话吗?
- intent: request_names
examples: |
- 我想告诉你姓名
- 你知道我的姓名吗?
- lookup: names
examples: |
- 猪⼋戒
- 孙悟空
- 沙悟净
- 唐三藏

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。