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

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

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

def _train_graph(
file_importer: TrainingDataImporter,
training_type: TrainingType,
output_path: Text,
fixed_model_name: Text,
model_to_finetune: Optional[Union[Text, Path]] = None,
force_full_training: bool = False,
dry_run: bool = False,
**kwargs: Any,
) -> TrainingResult:
if model_to_finetune: # 如果有模型微调
model_to_finetune = rasa.model.get_model_for_finetuning(model_to_finetune) # 获取模型微调
if not model_to_finetune: # 如果没有模型微调
rasa.shared.utils.cli.print_error_and_exit( # 打印错误并退出
f"No model for finetuning found. Please make sure to either " # 没有找到微调模型。请确保
f"specify a path to a previous model or to have a finetunable " # 要么指定一个以前模型的路径,要么有一个可微调的
f"model within the directory '{output_path}'." # 在目录'{output_path}'中的模型。
) rasa.shared.utils.common.mark_as_experimental_feature( # 标记为实验性功能
"Incremental Training feature" # 增量训练功能
) is_finetuning = model_to_finetune is not None # 如果有模型微调 config = file_importer.get_config() # 获取配置
recipe = Recipe.recipe_for_name(config.get("recipe")) # 获取配方
config, _missing_keys, _configured_keys = recipe.auto_configure( # 自动配置
file_importer.get_config_file_for_auto_config(), # 获取自动配置的配置文件
config, # 配置
training_type, # 训练类型
)
model_configuration = recipe.graph_config_for_recipe( # 配方的graph配置
config, # 配置
kwargs, # 关键字参数
training_type=training_type, # 训练类型
is_finetuning=is_finetuning, # 是否微调
)
rasa.engine.validation.validate(model_configuration) # 验证 tempdir_name = rasa.utils.common.get_temp_dir_name() # 获取临时目录名称 # Use `TempDirectoryPath` instead of `tempfile.TemporaryDirectory` as this leads to errors on Windows when the context manager tries to delete an already deleted temporary directory (e.g. https://bugs.python.org/issue29982)
# 翻译:使用TempDirectoryPath而不是tempfile.TemporaryDirectory,因为当上下文管理器尝试删除已删除的临时目录时,这会导致Windows上的错误(例如https://bugs.python.org/issue29982)
with rasa.utils.common.TempDirectoryPath(tempdir_name) as temp_model_dir: # 临时模型目录
model_storage = _create_model_storage( # 创建模型存储
is_finetuning, model_to_finetune, Path(temp_model_dir) # 是否微调,模型微调,临时模型目录
)
cache = LocalTrainingCache() # 本地训练缓存
trainer = GraphTrainer(model_storage, cache, DaskGraphRunner) # Graph训练器 if dry_run: # dry运行
fingerprint_status = trainer.fingerprint( # fingerprint状态
model_configuration.train_schema, file_importer # 模型配置的训练模式,文件导入器
)
return _dry_run_result(fingerprint_status, force_full_training) # 返回dry运行结果 model_name = _determine_model_name(fixed_model_name, training_type) # 确定模型名称
full_model_path = Path(output_path, model_name) # 完整的模型路径 with telemetry.track_model_training( # 跟踪模型训练
file_importer, model_type=training_type.model_type # 文件导入器,模型类型
):
trainer.train( # 训练
model_configuration, # 模型配置
file_importer, # 文件导入器
full_model_path, # 完整的模型路径
force_retraining=force_full_training, # 强制重新训练
is_finetuning=is_finetuning, # 是否微调
)
rasa.shared.utils.cli.print_success( # 打印成功
f"Your Rasa model is trained and saved at '{full_model_path}'." # Rasa模型已经训练并保存在'{full_model_path}'。
) return TrainingResult(str(full_model_path), 0) # 训练结果

1.传递来的形参数据



2._train_graph()函数组成

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

  • model_configuration = recipe.graph_config_for_recipe(*)
  • trainer = GraphTrainer(model_storage, cache, DaskGraphRunner)
  • trainer.train(model_configuration, file_importer, full_model_path, force_retraining, is_finetuning)

二._train_graph()函数中的方法

1.file_importer.get_config()

  将config.yml文件转化为dict类型,如下所示:

2.Recipe.recipe_for_name(config.get("recipe"))



(1)ENTITY_EXTRACTOR = ComponentType.ENTITY_EXTRACTOR

实体抽取器。

(2)INTENT_CLASSIFIER = ComponentType.INTENT_CLASSIFIER

意图分类器。

(3)MESSAGE_FEATURIZER = ComponentType.MESSAGE_FEATURIZER

消息特征化。

(4)MESSAGE_TOKENIZER = ComponentType.MESSAGE_TOKENIZER

消息Tokenizer。

(5)MODEL_LOADER = ComponentType.MODEL_LOADER

模型加载器。

(6)POLICY_WITHOUT_END_TO_END_SUPPORT = ComponentType.POLICY_WITHOUT_END_TO_END_SUPPORT

非端到端策略支持。

(7)POLICY_WITH_END_TO_END_SUPPORT = ComponentType.POLICY_WITH_END_TO_END_SUPPORT

端到端策略支持。

3.model_configuration = recipe.graph_config_for_recipe(*)

  model_configuration.train_schema和model_configuration.predict_schema的数据类型都是GraphSchema类对象,分别表示在训练和预测时所需要的SchemaNode,以及SchemaNode在GraphSchema中的依赖关系。

(1)model_configuration.train_schema

  • schema_validator:rasa.graph_components.validators.default_recipe_validator.DefaultV1RecipeValidator类中的validate方法
  • finetuning_validator:rasa.graph_components.validators.finetuning_validator.FinetuningValidator类中的validate方法
  • nlu_training_data_provider:rasa.graph_components.providers.nlu_training_data_provider.NLUTrainingDataProvider类中的provide方法
  • train_JiebaTokenizer0:rasa.nlu.tokenizers.jieba_tokenizer.JiebaTokenizer类中的train方法
  • run_JiebaTokenizer0:rasa.nlu.tokenizers.jieba_tokenizer.JiebaTokenizer类中的process_training_data方法
  • run_LanguageModelFeaturizer1:rasa.nlu.featurizers.dense_featurizer.lm_featurizer.LanguageModelFeaturizer类中的process_training_data方法
  • train_DIETClassifier2:rasa.nlu.classifiers.diet_classifier.DIETClassifier类中的train方法
  • train_ResponseSelector3:rasa.nlu.selectors.response_selector.ResponseSelector类中的train方法

说明:ResponseSelector类继承自DIETClassifier类。

(2)model_configuration.predict_schema

  • nlu_message_converter:rasa.graph_components.converters.nlu_message_converter.NLUMessageConverter类中的convert_user_message方法
  • run_JiebaTokenizer0:rasa.nlu.tokenizers.jieba_tokenizer.JiebaTokenizer类中的process方法
  • run_LanguageModelFeaturizer1:rasa.nlu.featurizers.dense_featurizer.lm_featurizer.LanguageModelFeaturizer类中的process方法
  • run_DIETClassifier2:rasa.nlu.classifiers.diet_classifier.DIETClassifier类中的process方法
  • run_ResponseSelector3:rasa.nlu.selectors.response_selector.ResponseSelector类中的process方法
  • run_RegexMessageHandler:rasa.nlu.classifiers.regex_message_handler.RegexMessageHandler类中的process方法

4.tempdir_name

  'C:\Users\ADMINI~1\AppData\Local\Temp\tmpg0v179ea'

5.trainer = GraphTrainer(*)和trainer.train(*)

  这里执行的代码是rasa/engine/training/graph_trainer.py中GraphTrainer类的train()方法,实现功能为训练和打包模型并返回预测graph运行程序。

6.Rasa中GraphComponent的子类

参考文献:

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

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

[3]rasa.engine.graph:https://rasa.com/docs/rasa/next/reference/rasa/engine/graph/

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

  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. 要知其然还要知其所以然printChar

    虽然过渡与的追求细节不是好事, 但是现实社会逼迫我们不得不兼顾周全. 所以什么都是最好不仅要知其然还要知其所以然! public class printChar { public static voi ...

  2. 造轮子之EventBus

    前面基础管理的功能基本开发完了,接下来我们来优化一下开发功能,来添加EventBus功能.EventBus也是我们使用场景非常广的东西.这里我会实现一个本地的EventBus以及分布式的EventBu ...

  3. 记Halo1.5版本迁移Halo2.10.0版本

    原文地址: 记Halo1.5版本迁移Halo2.10.0版本 - Stars-One的杂货小窝 上一篇Window10安装linux子系统及子系统安装1Panel面板 - Stars-One的杂货小窝 ...

  4. 【Unity3D】资源管理

    1 前言 ​ Unity 中资源管理方案主要有 Resources.TextAsset.ScriptableObject .AssetDatabase.PlayerPrefs.Addressables ...

  5. kubernetes发布周期

    前言 页面介绍了版本发布的一些时间点和PR的要求,通过了解k8s的发布周期来规划自己的版本选择. 合并PR的要求 如果你希望将你的代码合并到官方代码仓库中,不同的开发阶段需要有不同的标签和里程碑.也是 ...

  6. 虹科案例|虹科Visokio商业智能平台在疫后帮酒店业打好翻身仗!

    疫后时代以来,报复性度假呈爆炸式增长,首先点燃的就是酒店行业.面对疫后更为理性"挑剔"的客户以及酒店行业复苏节点: 如何提升酒店管理效率? 怎么准确判断流量变化趋势,拓展线上客源? ...

  7. P1522 [USACO2.4] 牛的旅行 Cow Tours

    Problem 题目简述 给你两个独立的联通块,求:在两个联通块上各找一个点连起来,使得新的联通块的直径的最小值. 思路 本题主要做法:\(Floyd\). 首先,Floyd求出任意两个点之间的最短路 ...

  8. 使用 Appilot 部署 Llama2,会聊天就行!

    Walrus 是一款基于平台工程理念的应用管理平台,致力于解决应用交付领域的深切痛点.借助 Walrus 将云原生的能力和最佳实践扩展到非容器化环境,并支持任意应用形态统一编排部署,降低使用基础设施的 ...

  9. 如何对BIOS/UEFI 更新

    确定当前BIOS/UEFI版本: 在启动计算机时,按下相应的键(通常是DEL.F2.或F10,具体取决于制造商),进入BIOS/UEFI设置.在系统信息或主页部分,你应该能够找到当前的BIOS/UEF ...

  10. .NET周刊【11月第1期 2023-11-09】

    国内文章 C#/.NET/.NET Core优秀项目和框架2023年10月简报 https://www.cnblogs.com/Can-daydayup/p/17804085.html 本文主要介绍了 ...