文章目录
- 1、`domain.yml` 领域
- 1) intent 意图 和 entity 实体
- 2) action 动作
- 3) slot 词槽
- 4) response 回复
- 5) session_config 会话配置
- 2、`config.yml`
- 1) pipeline 流水线
- 2) policies 策略
- 3、`endpoints.yml` 端点
- 4、`data/nlu.yml` nlu 训练数据
- 5、`data/stories.yml` 故事
- 6、组件
常见rasa工程目录如下:
.
├── actions
│ ├── actions.py
│ ├── __init__.py
│ └── __pycache__
│ ├── actions.cpython-37.pyc
│ └── __init__.cpython-37.pyc
├── config.yml
├── credentials.yml
├── data
│ ├── nlu.yml
│ ├── rules.yml
│ └── stories.yml
├── domain.yml
├── endpoints.yml
├── models
│ └── 20230201-193003-allegro-golf.tar.gz
└── tests
└── test_stories.yml
1、domain.yml
领域
定义了对话机器人需要知道的所有信息,包括以下字段:
- intent 意图 和 entity 实体,表示输入的范围;
- slot 词槽 和 form 表单,给定了模型输出的范围;
- action 动作;
- response 回复,作为对话机器人回复的模板;可以认为是一种简单的动作,也可以认为是复杂动作的 NLG 步骤
- 这些信息对模型的输入和输出 进行了明确的范围指定;
- 意图和实体
- 词槽和表单,相当于内部的变量,用于表征状态和存储记忆
1) intent 意图 和 entity 实体
告诉机器人可能要处理的意图和实体有哪些。
intents:
- greet
- goodbye
entities:
- object_type
- mention
- hotel
2) action 动作
- 是对话管理模型的输出
- 定义了机器人可以执行的动作
- 以
utter_
开头
actions:
- action_query_knowledge_base
3) slot 词槽
定义了机器人在对话过程中需要跟踪记忆的信息
slots:
object_type:
type: text
influence_conversation: false
mappings:
- type: from_entity
entity: object_type
mention:
type: text
influence_conversation: false
mappings:
- type: from_entity
entity: mention
attribute:
type: text
influence_conversation: false
mappings:
- type: from_entity
entity: attribute
4) response 回复
定义了机器人回复的模板
responses:
utter_greet:
- text: "Hey!"
- text: "Hello! How can I help you?"
utter_goodbye:
- text: "Bye"
- text: "Goodbye. See you soon."
5) session_config 会话配置
session 会话,是指用户和机器人之间的一场对话。一个会话可以横跨很多轮对话。
Rasa 支持的会话配置有:
session_expiration_time
,用户的最新消息多久后,会话被认为过期;carry_over_slots_to_new_session
,新的会话开始时,是否应该将上一个绘画的词槽延续到新的会话。
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
2、config.yml
配置文件一般有三个主要的键:
- recipe,表示配置文件所用的格式,当前只支持
default.v1
- language,要处理的语言
- pipeline,流水线组件列表
1) pipeline 流水线
示例:
pipeline:
- name: "WhitespaceTokenizer"
- name: "CountVectorsFeaturizer"
analyzer: "char_wb"
min_ngram: 1
max_ngram: 4
- name: "DIETClassifier"
epochs: 100
- name: SpacyNLP
model: "en_core_web_md"
- name: SpacyEntityExtractor
dimensions: ["PERSON"]
推荐的中文流水线配置
recipe: default.v1
language: zh
pipeline:
- name: "JiebaTokenizer"
- name: LanguageModelFeaturizer
model_name: "bert"
model_weight: "bert-base-chinese"
- name: "DIETClassifier"
2) policies 策略
策略负责学习故事,从而预测动作。
示例:
policies:
- name: TEDPolicy
max_history: 5
epochs: 1
- name: MemoizationPolicy
- name: RulePolicy
3、endpoints.yml
端点
定义了 rasa core 和其他服务进行连接的而配置信息。
目前支持的端点有:
- event broker
- tracker store
- lock store
- action server
- NLU 服务器
- NLG 服务器
- model storage
4、data/nlu.yml
nlu 训练数据
data/nlu.yml
中 key为 nlu 的列表是训练数据。
列表中每个元素是一个字典,依靠字典中不同特殊含义的 key 来区分不同字典的功能。key 包括如下几种:
- intent,意图字段
- synonym, 同义词字段
存储同义词信息,examples 中的同义词会被替换为 synonym 的值; - lookup,查找表字段
用来存储查找表,如特征词表。 - regex, 正则表达式字段
存储正则表达式
- 其中,除 intent 必须有外,其他三个可选;
数据示例:
version: "3.1"
nlu:
- intent: bot_challenge
examples: |
- are you a bot?
- are you a human?
- am I talking to a bot?
- lookup: hotel
examples: |
- Hilton
- City Hotel
- ...
- entity,实体
- slot,词槽
- action,动作
- form,表单
- response,回复
5、data/stories.yml
故事
rasa 通过学习故事来学习对话管理知识。故事是一种在较高语义层次上记录对话过程的方式。不仅需要记录用户的语义表达,还需要记录系统内部正确的状态变化。
观察文件内容,每个故事都是 stories列表中的一个元素。
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
6、组件
DAG: Directed Acyclic Graph,有向无环图;
Rasa NLU 是一个基于DAG的通用框架,DAG 由组件(component)相互连接构成。
常用组件
- 语言模型组件,加载预训练的词向量模型
如:spaCyNLP, MittieNLP - 分词组件
如:JiebaTokenizer, MittieTokenizer, spaCyTokenizer - 特征提取组件
如:MittieFeaturizer, spaCyFeaturizer, ConveRTFeaturizer, LanguageModelFeaturizer, RegexFeaturizer, ConutVectorsFeaturizer, LexiconSyntacticFeaturizer - NER 组件
如:CRFEntityExtractor, spaCyEntityExtractor, DucklingHTTPExtractor, MittieEntityExtractor, EntitySynonymMapper, DIETClassifier, RegexEntityExtractor - 意图分类组件,也称为意图识别组件
如:MittieIntentClassifier, SklearnIntentClassifier, KeywordIntentClassifier, DietClassifier, FallbackClassifier, - 结构化输出组件
- 实体和意图联合提取组件
如:rasa 提供的 DIETClassifier - 回复选择器 ResponseSelector
组件特性
- 顺序很重要
- 可以互相替换
- 有些组件之间互斥
- 有些组件可以同时使用
伊织 2023-02-04(六)