rasa train nlu详解:1.1-train_nlu()函数

2023-11-12 01:20
文章标签 函数 详解 1.1 train rasa nlu

本文主要是介绍rasa train nlu详解:1.1-train_nlu()函数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  本文使用《使用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 Nonereturn _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,  # 微调时期fractionpersist_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()函数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

C#数据结构之字符串(string)详解

《C#数据结构之字符串(string)详解》:本文主要介绍C#数据结构之字符串(string),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录转义字符序列字符串的创建字符串的声明null字符串与空字符串重复单字符字符串的构造字符串的属性和常用方法属性常用方法总结摘

Java中StopWatch的使用示例详解

《Java中StopWatch的使用示例详解》stopWatch是org.springframework.util包下的一个工具类,使用它可直观的输出代码执行耗时,以及执行时间百分比,这篇文章主要介绍... 目录stopWatch 是org.springframework.util 包下的一个工具类,使用它

Java进行文件格式校验的方案详解

《Java进行文件格式校验的方案详解》这篇文章主要为大家详细介绍了Java中进行文件格式校验的相关方案,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、背景异常现象原因排查用户的无心之过二、解决方案Magandroidic Number判断主流检测库对比Tika的使用区分zip

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

springboot security快速使用示例详解

《springbootsecurity快速使用示例详解》:本文主要介绍springbootsecurity快速使用示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录创www.chinasem.cn建spring boot项目生成脚手架配置依赖接口示例代码项目结构启用s

Python中随机休眠技术原理与应用详解

《Python中随机休眠技术原理与应用详解》在编程中,让程序暂停执行特定时间是常见需求,当需要引入不确定性时,随机休眠就成为关键技巧,下面我们就来看看Python中随机休眠技术的具体实现与应用吧... 目录引言一、实现原理与基础方法1.1 核心函数解析1.2 基础实现模板1.3 整数版实现二、典型应用场景2

一文详解SpringBoot响应压缩功能的配置与优化

《一文详解SpringBoot响应压缩功能的配置与优化》SpringBoot的响应压缩功能基于智能协商机制,需同时满足很多条件,本文主要为大家详细介绍了SpringBoot响应压缩功能的配置与优化,需... 目录一、核心工作机制1.1 自动协商触发条件1.2 压缩处理流程二、配置方案详解2.1 基础YAML

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

java中反射(Reflection)机制举例详解

《java中反射(Reflection)机制举例详解》Java中的反射机制是指Java程序在运行期间可以获取到一个对象的全部信息,:本文主要介绍java中反射(Reflection)机制的相关资料... 目录一、什么是反射?二、反射的用途三、获取Class对象四、Class类型的对象使用场景1五、Class

golang 日志log与logrus示例详解

《golang日志log与logrus示例详解》log是Go语言标准库中一个简单的日志库,本文给大家介绍golang日志log与logrus示例详解,感兴趣的朋友一起看看吧... 目录一、Go 标准库 log 详解1. 功能特点2. 常用函数3. 示例代码4. 优势和局限二、第三方库 logrus 详解1.