什么是nlu?
即自然语言理解(Natural Language Understanding),wiki中解释为 deals with machine reading comprehension。(◔◡◔)
jieba+mitie+sklearn 的不足之处:
1.官方文档mitie训练建议所需内存128G
2.针对用户所说的一句话存在多个意图,无法识别
基于tensorflow的pipeline尝试解决以上两个问题。这里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:告诉模型这是多意图,需要根据占位符进行意图切分
intent_split_symbol: "+" 多意图间按“+”切分
准备训练数据:
数据格式如下:
## 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?
模型训练及测试:
模型训练:
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?"))
结果如下:
{
'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的标签概率较大。也可以大致看出,这里的多标签分类采用的策略是:多标签分类策略中的方式三,将问题转化为多分类问题。
参考文献:
官方源码及实验数据: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