如何建設(shè)簡(jiǎn)易網(wǎng)站他達(dá)拉非片
??本文使用《使用ResponseSelector實(shí)現(xiàn)校園招聘FAQ機(jī)器人》中的例子,主要詳解介紹train_nlu()函數(shù)中變量的具體值。
一.rasa/model_training.py/train_nlu()函數(shù)
??train_nlu()函數(shù)實(shí)現(xiàn),如下所示:
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. # 訓(xùn)練一個(gè)NLU模型。Args:config: Path to the config file for NLU. # NLU的配置文件路徑。nlu_data: Path to the NLU training data. # NLU訓(xùn)練數(shù)據(jù)的路徑。output: Output path. # 輸出路徑。fixed_model_name: Name of the model to be stored. # 要存儲(chǔ)的模型的名稱。persist_nlu_training_data: `True` if the NLU training data should be persisted with the model. # 如果NLU訓(xùn)練數(shù)據(jù)應(yīng)該與模型一起持久化,則為`True`。additional_arguments: Additional training parameters which will be passed to the `train` method of each component. # 將傳遞給每個(gè)組件的`train`方法的其他訓(xùn)練參數(shù)。domain: Path to the optional domain file/Domain object. # 可選domain文件/domain對(duì)象的路徑。model_to_finetune: Optional path to a model which should be finetuned or a directory in case the latest trained model should be used. # 可選路徑,指向應(yīng)該進(jìn)行微調(diào)的模型,或者在應(yīng)該使用最新訓(xùn)練的模型的情況下指向一個(gè)目錄。finetuning_epoch_fraction: The fraction currently specified training epochs in the model configuration which should be used for finetuning. # 模型配置中當(dāng)前指定的訓(xùn)練時(shí)期的fraction,應(yīng)該用于微調(diào)。Returns:Path to the model archive. # 模型歸檔的路徑。"""if not nlu_data: # 沒有NLU數(shù)據(jù)rasa.shared.utils.cli.print_error( # 打印錯(cuò)誤"No NLU data given. Please provide NLU data in order to train " # 沒有給出NLU數(shù)據(jù)。請(qǐng)?zhí)峁㎞LU數(shù)據(jù)以訓(xùn)練"a Rasa NLU model using the '--nlu' argument." # 使用--nlu參數(shù)訓(xùn)練Rasa NLU模型)return None# 只訓(xùn)練NLU,因此仍然必須選擇訓(xùn)練文件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數(shù)據(jù)if training_data.contains_no_pure_nlu_data(): # 如果沒有純NLU數(shù)據(jù)rasa.shared.utils.cli.print_error( # 打印錯(cuò)誤f"Path '{nlu_data}' doesn't contain valid NLU data in it. " # 路徑{nlu_data}中不包含有效的NLU數(shù)據(jù)f"Please verify the data format. " # 請(qǐng)驗(yàn)證數(shù)據(jù)格式f"The NLU model training will be skipped now." # 現(xiàn)在將跳過NLU模型訓(xùn)練)return Nonereturn _train_graph( # 訓(xùn)練圖file_importer, # 文件導(dǎo)入器training_type=TrainingType.NLU, # 訓(xùn)練類型output_path=output, # 輸出路徑model_to_finetune=model_to_finetune, # 模型微調(diào)fixed_model_name=fixed_model_name, # 固定模型名稱finetuning_epoch_fraction=finetuning_epoch_fraction, # 微調(diào)時(shí)期fractionpersist_nlu_training_data=persist_nlu_training_data, # 持久化NLU訓(xùn)練數(shù)據(jù)**(additional_arguments or {}), # 額外的參數(shù)).model # 模型
1.傳遞來的形參數(shù)據(jù)
??形參config=“config.yml”,nlu_data=“data”,output=“models”,persist_nlu_training_data=False,其它的都是None,如下所示:
2.train_nlu()函數(shù)組成
??該函數(shù)主要由3個(gè)方法組成,如下所示:
- file_importer = TrainingDataImporter.load_nlu_importer_from_config(*) #file_importer數(shù)據(jù)類型為NluDataImporter
- training_data = file_importer.get_nlu_data() #根據(jù)nlu數(shù)據(jù)創(chuàng)建一個(gè)TrainingData類對(duì)象
- return _train_graph(*) #訓(xùn)練config.yml文件中pipline對(duì)應(yīng)的圖
二.training_data數(shù)據(jù)類型
??training_data數(shù)據(jù)類型為rasa.shared.nlu.training_data.training_data.TrainingData
,如下所示:
1.MIN_EXAMPLES_PER_ENTITY=2
每個(gè)實(shí)體的最小樣本數(shù)量。
2.MIN_EXAMPLES_PER_INTENT=2
每個(gè)意圖的最小樣本數(shù)量。
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例子列表,列表中數(shù)據(jù)為rasa.shared.nlu.training_data.message.Message數(shù)據(jù)結(jié)構(gòu)。對(duì)于普通意圖,Message數(shù)據(jù)結(jié)構(gòu)如下所示:
??對(duì)于檢索意圖,Message數(shù)據(jù)結(jié)構(gòu)如下所示:
10.intents
具體數(shù)值為set(‘faq’, ‘goodbye’, ‘greet’)。
11.lookup_tables=[]
查找表。
12.nlu_examples=[25*Message]
內(nèi)容和intent_examples相同,不再介紹。
13.number_of_examples_per_entity
每個(gè)entity例子的數(shù)量。
14.number_of_examples_per_intent
每個(gè)intent例子的數(shù)量,即{‘faq’: 14, ‘goodbye’: 5, ‘greet’: 6}。
15.number_of_examples_per_response
??每個(gè)response例子的數(shù)量,如下所示:
{'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]
內(nèi)容和intent_examples相同,不再介紹。
參考文獻(xiàn):
[1]https://github.com/RasaHQ/rasa
[2]rasa 3.2.10 NLU模塊的訓(xùn)練:https://zhuanlan.zhihu.com/p/574935615