什么是nlu?
即自然語言理解(Natural Language Understanding),wiki中解釋為 deals with machine reading comprehension。(???)
jieba+mitie+sklearn 的不足之處:
1.官方文檔mitie訓(xùn)練建議所需內(nèi)存128G
2.針對用戶所說的一句話存在多個(gè)意圖,無法識別
基于tensorflow的pipeline嘗試解決以上兩個(gè)問題。這里pipeline定義的是如何解析用戶的輸入,分詞(符號化),以及特征提取的方式。pipeline:定義如下
pipeline:
- name: "intent_featurizer_count_vectors"
- name: "intent_classifier_tensorflow_embedding"
intent_tokenization_flag: true
intent_split_symbol: "+"
intent_featurizer_count_vectors:用于特征提取
intent_classifier_tensorflow_embedding:采用tensorflow做意圖分類
intent_tokenization_flag: true:告訴模型這是多意圖,需要根據(jù)占位符進(jìn)行意圖切分
intent_split_symbol: "+" 多意圖間按“+”切分
準(zhǔn)備訓(xùn)練數(shù)據(jù):
數(shù)據(jù)格式如下:
## intent: meetup
- I am new to the area. What meetups I could join in Berlin?
- I have just moved to Berlin. Can you suggest any cool meetups for
me?
## intent: affirm+ask_transport
- Yes. How do I get there?
- Sounds good. Do you know how I could get there from home?
模型訓(xùn)練及測試:
模型訓(xùn)練:
python -m rasa_nlu.train -c config.yml --data data/nlu_data.md -o models --fixed_model_name nlu_model --project current --verbose
模型測試:
interpreter = Interpreter.load('models/current/nlu_model')
print(interpreter.parse("Yes. Can you give me suggestions on how to get there?"))
結(jié)果如下:
{
'intent':{
'name':'affirm+ask_transport',
'confidence':0.918471097946167
},
'entities':[
],
'intent_ranking':[
{
'name':'affirm+ask_transport',
'confidence':0.918471097946167
},
{
'name':'ask_transport',
'confidence':0.32662829756736755
},
{
'name':'thanks+goodbye',
'confidence':0.004435105249285698
},
{
'name':'meetup',
'confidence':-0.06692223995923996
},
{
'name':'deny',
'confidence':-0.07153981924057007
},
{
'name':'goodbye',
'confidence':-0.08976072818040848
},
{
'name':'greet',
'confidence':-0.09185336530208588
},
{
'name':'thanks',
'confidence':-0.1762458086013794
},
{
'name':'affirm',
'confidence':-0.3415682911872864
}
],
'text':'Yes. Can you give me suggestions on how to get there?'
}
可以看出
affirm+ask_transport的標(biāo)簽概率較大。也可以大致看出,這里的多標(biāo)簽分類采用的策略是:多標(biāo)簽分類策略中的方式三,將問題轉(zhuǎn)化為多分類問題。
參考文獻(xiàn):
官方源碼及實(shí)驗(yàn)數(shù)據(jù):https://github.com/RasaHQ/tutorial-tf-pipeline
文檔說明:https://medium.com/rasa-blog/how-to-handle-multiple-intents-per-input-using-rasa-nlu-tensorflow-pipeline-75698b49c383