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

2023年12月6日修改
本文使用《使用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 模型