美文网首页rasa
rasa对话系统踩坑记(六)

rasa对话系统踩坑记(六)

作者: colin_gao | 来源:发表于2018-12-16 15:31 被阅读0次

说是不更新的,觉得这个文章也只是自己的一个流水账式的踩坑记录,应该也没什么人关注。但最近好几个人给我提issure,发email,才知道原来现在国内也不少公司在关注并使用rasa(话说几个月前我用rasa的时候好像没那么多人关注的)。所以继续更新rasa-core相关的踩坑文章吧,而且最近rasa-core版本确实也变动了不少。

rasa_chatbot_cn这个demo中,开始使用的是rasa-core==0.11.4的版本,但因为最近的几个功能我升级到了0.12.3。这篇先说说,compare policy的实现。

之前的项目一直使用的是KerasPolicy,就算是自定义的policy也是继承自KerasPolicy。而KerasPolicy的模型很简单,只是单一的LSTM+Dense+softmax。导致的问题是我们需要不断地完善自己的story,把各种情况下的story进行补充,花费了大量的人工。

然后后面就在尝试使用EmbeddingPolicy,因为它综合了很多方法。


embeddint-dialogue-policy.png

EmbeddingPolicy包含以下的步骤:

  • apply dense layers to create embeddings for user intents, entities and system actions including previous actions and slots(稠密嵌入,包括用户意图、实体和系统行为:以前的动作和槽)
  • use the embeddings of previous user inputs as a user memory and embeddings of previous system actions as a system memory.(使用以前的用户输入作为用户memory和以前的系统行为作为系统memory)
  • concatenate user input, previous system action and slots embeddings for current time into an input vertor to rnn(合并用户输入,以前系统行为和槽作为当前时间用户的输入向量给rnn模型)
  • using user and previous system action embeddings from the input vector, calculate attention probabilities over the user and system memories(使用输入向量中用户输入和以前的系统行为嵌入,来计算用户和系统的注意力向量)
  • sum the user embedding and user attention vector and feed it and the embeddings of the slots as an input to an LSTM cell(用户词嵌入和用户注意力向量相加再和槽向量一起作为LSTM的输入)
  • apply a dense layer to the output of the LSTM to get a raw recurrent embedding of a dialogue(应用LSTM的输出来获得一个对话的原始循环嵌入)
  • sum this raw recurrent embedding of a dialogue with system attention vector to create dialogue level embedding, this step allows the algorithm to repeat previous system action by copying its embedding vector directly to the current time output(将对话的原始循环嵌入和系统注意力向量相加,来创建对话层的嵌入。这一步允许算法通过直接拷贝它的向量到当前的输出来重复之前的系统行为)
  • weight previous LSTM states with system attention probabilities to get the previous action embedding, the policy is likely payed attention to(加权以前的LSTM状态和系统注意力来获取以前的行为嵌入,policy最有可能需要注意的)
  • if the similarity between this previous action embedding and current time dialogue embedding is high, overwrite current LSTM state with the one from the time when this action happened(如果以前的行为嵌入和当前的对话嵌入相似度很高,overwrite当前的LSTM状态)
  • for each LSTM time step, calculate the similarity between the dialogue embedding and embedded system actions(对于LSTM的每一步,计算对话嵌入和系统行为嵌入的相似度)

所以EmbeddingPolicy效果上来说会比较好,但是它有个问题是耗时,而且尤其是官网的源码,它并没有使用GPU、没有充分利用CPU资源。这个问题我进行了改善,后续会分享。因为比较耗时耗资源,所以需要在小数量级上对policy进行比较。

下图是我在rasa_chatbot_cn上比较了KerasPolicy和EmbeddingPolicy的结果:

policy-compare.png

图中很明显可以看出policy的优劣。至于如何使用,首先需要建立要进行对比的policy.yml文件,这里分别是embed_policy.yml和keras_policy.yml文件。然后就是两个命令,一个是compare policy,一个是evaluate policy:

python -m rasa_core.train compare -c keras_policy.yml embed_policy.yml \
    -d mobile_domain.yml -s data/mobile_edit_story.md -o comparison_models/ --runs 3 --percentages \
    0 25 50 70
python -m rasa_core.evaluate compare -s data/mobile_edit_story.md --core comparison_models/ -o comparison_results/

具体的参数不做过多解释,官网有详细说明。原创文章,转载请说明出处

相关文章

  • rasa对话系统踩坑记(九)

    实现在rasa-core中给policy提速 之前在rasa对话系统踩坑记(六)中提到过EmbeddingPoli...

  • rasa对话系统踩坑记(六)

    说是不更新的,觉得这个文章也只是自己的一个流水账式的踩坑记录,应该也没什么人关注。但最近好几个人给我提issure...

  • rasa资源收集

    简书文章 rasa对话系统踩坑记 官方视频教程笔记 生成NLU训练数据: 1. npm install -g ch...

  • rasa对话系统踩坑记(八)

    如何将bert应用在rasa-nlu-gao 将BERT应用到rasa-nlu-gao,其实在rasa对话系统踩坑...

  • rasa对话系统踩坑记(三)

    在rasa对话系统踩坑记(二)中我自定义过两个component组件。也好久没更新采坑系列了,随着项目的进展迭代最...

  • rasa对话系统踩坑记(一)

    前言 最近接到了一个任务,要做遗传方面的医疗诊断对话系统。经过前期的调研最终决定使用rasa_nlu和rasa_c...

  • rasa对话系统踩坑记(二)

    rasa_nlu模型训练 当我们准备好了rasa_nlu需要的训练数据后,就可以开始训练rasa_nlu模型。gi...

  • rasa对话系统踩坑记(四)

    前面几篇介绍了rasa-nlu-gao中自定义的几个模块,最近也没有怎么新增特别的模块,只是在词向量这块不断在尝试...

  • rasa对话系统踩坑记(五)

    上篇谈到增加了第三方闲聊的功能,避免了对话的时候遇到能识别意图之外的问题而回答“不好意思,我听不懂”这样的默认设置...

  • rasa对话系统踩坑记(七)

    如何在rasa-core框架下使用第三方nlu服务 现阶段我们rasa-core都是配合rasa-nlu使用的,但...

网友评论

    本文标题:rasa对话系统踩坑记(六)

    本文链接:https://www.haomeiwen.com/subject/ndfxkqtx.html