本文使用《使用ResponseSelector实现校园招聘FAQ机器人》中的例子,主要详解介绍train_nlu()函数中变量的具体值。

一.rasa/model_training.py/train_nlu()函数

  train_nlu()函数实现,如下所示:

def train_nlu(
config: Text,
nlu_data: Optional[Text],
output: Text,
fixed_model_name: Optional[Text] = None,
persist_nlu_training_data: bool = False,
additional_arguments: Optional[Dict] = None,
domain: Optional[Union[Domain, Text]] = None,
model_to_finetune: Optional[Text] = None,
finetuning_epoch_fraction: float = 1.0,
) -> Optional[Text]:
"""Trains an NLU model. # 训练一个NLU模型。 Args:
config: Path to the config file for NLU. # NLU的配置文件路径。
nlu_data: Path to the NLU training data. # NLU训练数据的路径。
output: Output path. # 输出路径。
fixed_model_name: Name of the model to be stored. # 要存储的模型的名称。
persist_nlu_training_data: `True` if the NLU training data should be persisted with the model. # 如果NLU训练数据应该与模型一起持久化,则为`True`。
additional_arguments: Additional training parameters which will be passed to the `train` method of each component. # 将传递给每个组件的`train`方法的其他训练参数。
domain: Path to the optional domain file/Domain object. # 可选domain文件/domain对象的路径。
model_to_finetune: Optional path to a model which should be finetuned or a directory in case the latest trained model should be used. # 可选路径,指向应该进行微调的模型,或者在应该使用最新训练的模型的情况下指向一个目录。
finetuning_epoch_fraction: The fraction currently specified training epochs in the model configuration which should be used for finetuning. # 模型配置中当前指定的训练时期的fraction,应该用于微调。 Returns:
Path to the model archive. # 模型归档的路径。
"""
if not nlu_data: # 没有NLU数据
rasa.shared.utils.cli.print_error( # 打印错误
"No NLU data given. Please provide NLU data in order to train " # 没有给出NLU数据。请提供NLU数据以训练
"a Rasa NLU model using the '--nlu' argument." # 使用--nlu参数训练Rasa NLU模型
)
return None # 只训练NLU,因此仍然必须选择训练文件
file_importer = TrainingDataImporter.load_nlu_importer_from_config(
config, domain, training_data_paths=[nlu_data], args=additional_arguments
) training_data = file_importer.get_nlu_data() # 获取NLU数据
if training_data.contains_no_pure_nlu_data(): # 如果没有纯NLU数据
rasa.shared.utils.cli.print_error( # 打印错误
f"Path '{nlu_data}' doesn't contain valid NLU data in it. " # 路径{nlu_data}中不包含有效的NLU数据
f"Please verify the data format. " # 请验证数据格式
f"The NLU model training will be skipped now." # 现在将跳过NLU模型训练
)
return None return _train_graph( # 训练图
file_importer, # 文件导入器
training_type=TrainingType.NLU, # 训练类型
output_path=output, # 输出路径
model_to_finetune=model_to_finetune, # 模型微调
fixed_model_name=fixed_model_name, # 固定模型名称
finetuning_epoch_fraction=finetuning_epoch_fraction, # 微调时期fraction
persist_nlu_training_data=persist_nlu_training_data, # 持久化NLU训练数据
**(additional_arguments or {}), # 额外的参数
).model # 模型

1.传递来的形参数据

  形参config="config.yml",nlu_data="data",output="models",persist_nlu_training_data=False,其它的都是None,如下所示:

2.train_nlu()函数组成

  该函数主要由3个方法组成,如下所示:

  • file_importer = TrainingDataImporter.load_nlu_importer_from_config(*) #file_importer数据类型为NluDataImporter
  • training_data = file_importer.get_nlu_data() #根据nlu数据创建一个TrainingData类对象
  • return _train_graph(*) #训练config.yml文件中pipline对应的图

二.training_data数据类型

  training_data数据类型为rasa.shared.nlu.training_data.training_data.TrainingData,如下所示:



1.MIN_EXAMPLES_PER_ENTITY=2

每个实体的最小样本数量。

2.MIN_EXAMPLES_PER_INTENT=2

每个意图的最小样本数量。

3.action_names=set()

action名字集合。

4.entities=set()

entity集合。

5.entity_examples=[]

entity例子集合。

6.entity_groups=set()

entity组的集合。

7.entity_roles=set()

entity角色集合。

8.entity_synonyms=set()

entity近义词集合。

9.intent_examples=[25*Message]

  intent例子列表,列表中数据为rasa.shared.nlu.training_data.message.Message数据结构。对于普通意图,Message数据结构如下所示:



  对于检索意图,Message数据结构如下所示:

10.intents

具体数值为set('faq', 'goodbye', 'greet')。

11.lookup_tables=[]

查找表。

12.nlu_examples=[25*Message]

内容和intent_examples相同,不再介绍。

13.number_of_examples_per_entity

每个entity例子的数量。

14.number_of_examples_per_intent

每个intent例子的数量,即{'faq': 14, 'goodbye': 5, 'greet': 6}。

15.number_of_examples_per_response

  每个response例子的数量,如下所示:

{'faq/notes': 1, 'faq/work_location': 1, 'faq/max_job_request': 1, 'faq/audit': 1, 'faq/write_exam_participate': 1, 'faq/write_exam_location': 1, 'faq/write_exam_again': 1, 'faq/write_exam_with-out-offer': 1, 'faq/interview_arrangement': 1, 'faq/interview_times': 1, 'faq/interview_from': 1, 'faq/interview_clothing': 1, 'faq/interview_paperwork': 1, 'faq/interview_result': 1}

16.regex_features=[]

正则特征。

17.response_examples=[14*Message]

  response例子,如下所示:

18.responses

  response例子,如下所示:

19.retrieval_intents=set('faq')

检索意图。

20.training_examples=[25*Message]

内容和intent_examples相同,不再介绍。

参考文献:

[1]https://github.com/RasaHQ/rasa

[2]rasa 3.2.10 NLU模块的训练:https://zhuanlan.zhihu.com/p/574935615

rasa train nlu详解:1.1-train_nlu()函数的更多相关文章

  1. SQL 中详解round(),floor(),ceiling()函数的用法和区别?

    SQL 中详解round(),floor(),ceiling()函数的用法和区别? 原创 2013年06月09日 14:00:21   摘自:http://blog.csdn.net/yueliang ...

  2. 第7.25节 Python案例详解:使用property函数定义与实例变量同名的属性会怎样?

    第7.25节 Python案例详解:使用property函数定义与实例变量同名的属性会怎样? 一.    案例说明 我们上节提到了,使用property函数定义的属性不要与类内已经定义的普通实例变量重 ...

  3. 第7.24节 Python案例详解:使用property函数定义属性简化属性访问代码实现

    第7.24节 Python案例详解:使用property函数定义属性简化属性访问代码实现 一.    案例说明 本节将通过一个案例介绍怎么使用property定义快捷的属性访问.案例中使用Rectan ...

  4. 详解wait和waitpid函数

    #include <sys/types.h> /* 提供类型pid_t的定义 */ #include <sys/wait.h> pid_t wait(int *status) ...

  5. Linux 信号详解一(signal函数)

    信号列表 SIGABRT 进程停止运行 SIGALRM 警告钟 SIGFPE 算述运算例外 SIGHUP 系统挂断 SIGILL 非法指令 SIGINT 终端中断 SIGKILL 停止进程(此信号不能 ...

  6. (译)详解javascript立即执行函数表达式(IIFE)

    写在前面 这是一篇译文,原文:Immediately-Invoked Function Expression (IIFE) 原文是一篇很经典的讲解IIFE的文章,很适合收藏.本文虽然是译文,但是直译的 ...

  7. 《Windows驱动开发技术详解》之派遣函数

    驱动程序的主要功能是负责处理I/O请求,其中大部分I/O请求是在派遣函数中处理的.用户模式下所有对驱动程序的I/O请求,全部由操作系统转化为一个叫做IRP的数据结构,不同的IRP数据会被“派遣”到不同 ...

  8. [二] java8 函数式接口详解 函数接口详解 lambda表达式 匿名函数 方法引用使用含义 函数式接口实例 如何定义函数式接口

    函数式接口详细定义 package java.lang; import java.lang.annotation.*; /** * An informative annotation type use ...

  9. 详解MySQL中concat函数的用法(连接字符串)

    MySQL中concat函数 使用方法: CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意: 如果所有参数均为非二进制 ...

  10. 详解javascript立即执行函数表达式(IIFE)

    立即执行函数,就是在定义函数的时候直接执行,这里不是申明函数而是一个函数表达式 1.问题 在javascript中,每一个函数在被调用的时候都会创建一个执行上下文,在函数内部定义的变量和函数只能在该函 ...

随机推荐

  1. 【matplotlib 实战】--堆叠柱状图

    堆叠柱状图,是一种用来分解整体.比较各部分的图.与柱状图类似,堆叠柱状图常被用于比较不同类别的数值.而且,它的每一类数值内部,又被划分为多个子类别,这些子类别一般用不同的颜色来指代. 柱状图帮助我们观 ...

  2. mysql之简单的多表查询

    最简单的多表查询需要用到连操作符(join) 1.笛卡儿积 形式为table1 join table2.如: select e.fname,e.lname,d.name from employee e ...

  3. Go语言代码断行规则详解

    本文深入探讨了Go语言中代码断行的各个方面,从基础概念到实际应用实践. 关注[TechLeadCloud],分享互联网架构.云服务技术的全维度知识.作者拥有10+年互联网服务架构.AI产品研发经验.团 ...

  4. Atcoder Regular Contest 165

    B. Sliding Window Sort 2 被题目名里的滑动窗口误导了,于是卡 B 40min /fn Description 给定长度为 \(n\) 的排列 \(P\) 和一个整数 \(K\) ...

  5. 浅谈仓储UI自动化之路

    1 分层测试 分层测试:就是不同的时间段,不同的团队或团队使用不同的测试用例对产品不同的关注点进行测试.一个系统/产品我们最先看到的是UI层,也就是外观或者说整体,这些是最上层,最上层依赖下面的服务层 ...

  6. 关于fstream对象的open方法报错183的问题

    当使用fstream,ifstream,ofstream,这几种对象打开文件, 但文件已经存在的时候, 调用GetLastError()函数,会返回错误代码183, 这个代码代表该文件已经存在,是正常 ...

  7. AutoCAD ObjectARX 二次开发(2020版)--1,下载和部署开发环境--

    教程说明: 本教程为2019年10月开始编撰,使用CAD官方最新版本的软件和库.对旧版本仍有参考价值. 本教程中使用的各种软件版本为官方指定匹配版本. 本教程需要你拥有编程基础,对于普通编程常识不再敷 ...

  8. 安卓端出现https请求失败的一次问题排查

    背景 某天早上,正在一个会议时,突然好几个同事被叫出去了:后面才知道,是有业务同事反馈到领导那里,我们app里面某个功能异常. 具体是这样,我们安卓版本的app是禁止截屏的(应该是app里做了拦截), ...

  9. Python 实现Word转HTML

    将Word转换为HTML能将文档内容发布在网页上,这样,用户就可以通过浏览器直接查看或阅读文档而无需安装特定的软件.Word转HTML对于在线发布信息.创建在线文档库以及构建交互式网页应用程序都非常有 ...

  10. 零基础 从 yolo8 入门计算机视觉超简单:物体识别、图像分类、轨迹追踪、姿势识别

    目录 安装 Ultralytics 训练 模型验证 预测 & 识别 导出 追踪 图像分割提取 分类 姿势识别 轨迹生成 Ultralytics YOLOv8 是备受好评的实时目标检测和图像分割 ...