基于rasa_nlu 模塊的多意圖識別

什么是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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容