chatbot

by P. Daniel Tyreus

由P.Daniel Tyreus

我如何通过帮助我的ChatBot理解意图来使其变得更聪明 (How I made my ChatBot smarter by helping it understand intent)

Using deep learning tools to better understand conversations about seasonal allergies

使用深度学习工具更好地了解有关季节性过敏的对话

I’ve been working on a chatbot to help understand seasonal allergies as a side project for quite a while. This time every year, my allergies flare up and my motivation to improve Hayfever also has a resurgence.

我从事聊天机器人的工作已经很长时间了,以帮助您了解季节性过敏作为副项目。 每年的这个时候,我的过敏症突然发作,而我改善花粉症的动力也重新流行了。

Early this Spring, I took some time to review how well my chatbot was communicating with users. The results where humbling to say the least. So I looked into improving my chatbot’s performance by integrating a modern natural language understanding system based on deep learning. This article discusses what went wrong with my early approaches and how I fixed it.

今年春天初,我花了一些时间回顾我的聊天机器人与用户交流的情况。 结果简直是卑鄙的。 因此,我希望通过集成基于深度学习的现代自然语言理解系统来提高聊天机器人的性能。 本文讨论了我的早期方法出了什么问题以及如何解决它。

第一遍:对话框树 (First Pass: Dialog Trees)

I built the “intelligence” behind the first version of the Hayfever chatbot using an mechanic known as a dialog tree. Anyone who has ever seen a role playing video game has experienced a dialog tree. In it’s classic form, a character in the game speaks some dialog and the player is given a choice of responses.

我使用称为对话框树的机制在第一个版本的Hayfever聊天机器人后面构建了“智能”。 任何曾经看过玩电子游戏角色的人都经历过对话树。 按照经典的形式,游戏中的角色会说出一些对话,并且玩家可以选择回应。

An even more primitive ancestor is the interactive voice response (IVR) system. Most of us have probably had the displeasure of interacting with an IVR when dialing in to the customer support line at our bank. These mechanics are easy to program and work adequately when the domain of possible responses is limited to the choices presented.

更为原始的祖先是交互式语音响应( IVR )系统。 当我们拨入我们银行的客户支持热线时,我们大多数人可能不喜欢与IVR进行交互。 当可能的响应范围仅限于所提出的选择时,这些机制易于编程并且可以正常工作

In the computer game, you can only select from the choices on the screen, and with the IVR you can only press numbers based on the choices given.

在计算机游戏中,您只能从屏幕上的选项中进行选择,而使用IVR,您只能根据给定的选项按数字。

With chatbots, the possible answers are not at all limited. A user can type in whatever they has on their mind. But when I first implemented the Hayfever chatbot in Facebook Messenger, I didn’t have access to the technology to parse input in a sophisticated way. So I used the “quick reply” feature to try to force the conversation along specific lines, much like a dialog tree.

使用聊天机器人,可能的答案完全不受限制。 用户可以输入自己的想法。 但是,当我第一次在Facebook Messenger中实现Hayfever聊天机器人时,我无法使用该技术以复杂的方式解析输入。 因此,我使用“快速回复”功能来尝试沿特定行强制对话,就像对话树一样。

第二次尝试:会话图 (Second Try: Conversation Graphs)

After observing the chatbot in the wild, I understood almost immediately that this approach would not work. Even if users were presented with a few quick replies, there was nothing stopping them from typing in something altogether different.

在野外观察聊天机器人后,我几乎立即了解到这种方法将行不通。 即使向用户提供了一些快速答复,也没有阻止他们输入完全不同的内容的方法。

In the second iteration, I decided that a tree structure was too rigid and I needed to model the conversation as a directed graph instead. I couldn’t find any framework that quite fit my needs. So I wrote my own graph-based dialog engine called conversation-kit.

在第二次迭代中,我认为树结构过于僵化,因此需要将对话建模为有向图。 我找不到任何适合我需求的框架。 因此,我编写了自己的基于图形的对话框引擎,称为对话套件 。

A directed graph has some advantages over a tree structure, in this case because it can let the conversation fork and flow more naturally. Without getting too much into the details, the vertices on the graph represent statements or questions from the chatbot. The edges represent possible responses from the user. So the conversation flows from vertex to vertex along the edges that match the user’s response.

向图相对于树结构具有一些优势,因为在这种情况下,它可以使对话分叉并更自然地流动 。 无需过多讨论细节,图形上的顶点就代表了聊天机器人的陈述或问题。 边缘代表来自用户的可能响应。 因此,对话会沿着与用户响应匹配的边缘在顶点之间流动。

As long as the user didn’t stray far from the set of responses defined by the edges in the graph, this worked pretty well. For instance, below is a chat I had with Hayfever on Facebook Messenger.

只要用户离图表边缘所定义的响应集不远,它就可以很好地工作。 例如,以下是我与Hayfever在Facebook Messenger上进行的聊天。

Since I programmed the model, I basically knew what I could say to get the desired response. Other users would not have this knowledge. So while this version was better, it still suffered some serious drawbacks.

自从对模型进行编程以来,我基本上知道该说些什么才能获得所需的响应。 其他用户将没有此知识。 因此,尽管此版本更好,但仍存在一些严重的缺陷。

First, if a user’s response did not match any edges, the bot just got stuck in a loop of saying it did not understand. Second, the algorithm I wrote to match responses to edges was really primitive and frequently misunderstood what the user was saying. Finally, if the user wanted to change the subject while in the middle of a conversation, he or she would essentially need to know a trigger phrase like “help” to reset the position in the graph.

首先,如果用户的响应与任何边缘都不匹配,则该机器人只会陷入说不明白的循环中。 其次,我编写的用于匹配边缘响应的算法确实很原始,经常被用户误解 。 最终,如果用户想在对话过程中更改主题,则他或她将本质上需要知道触发短语(例如“帮助”)以重置图形中的位置。

Below are some examples of the resulting unnatural and frustrating conversations.

以下是导致不自然和令人沮丧的对话的一些示例。

In the examples above, it’s clear that my chatbot was not at all understanding what the user was intending to convey. In other words, it did not understand the intent of each statement.

在上面的示例中,很明显,我的聊天机器人根本不了解用户打算传达的内容。 换句话说, 它不理解每个语句的意图

Humans are incredibly good at understanding subtle intent from spoken conversation. Most people effortlessly combine cues from facial expressions, body language, and intonation to gauge intent. On top of that, we incorporate knowledge of the person we are talking to, contextual details from previous conversations, and possible cultural references to further refine the meaning of what a person is saying to us.

人类非常善于理解语音对话中的微妙意图。 大多数人会毫不费力地将面部表情,肢体语言和语调的线索结合起来以评估意图。 最重要的是,我们结合了所要交谈的人的知识,先前对话的上下文细节以及可能的文化参考,以进一步完善一个人对我们说的意思。

Modern artificial intelligence technologies are nowhere near as good as humans in this arena. But advances in deep learning over the last few years have significantly improved a computer’s ability to discern intent from spoken or written text. At the very least, the state of the art is far, far better than the primitive technology I was using to match responses to edges.

在这个领域,现代人工智能技术远不及人类。 但是近几年来深度学习的进步 极大地提高了计算机从语音或书面文字中识别意图的能力 。 至少,最先进的技术远比我用来匹配边缘响应的原始技术好得多。

第三次尝试:了解意图 (Third Try: Understanding Intent)

After studying the interactions my chatbot was having with users, I realized I needed a more sophisticated strategy. I really needed a way to better understand a user’s intent.

研究了我的聊天机器人与用户的互动之后,我意识到我需要一个更复杂的策略。 我确实需要一种更好地了解用户意图的方法。

My first experience with intent was when I was programming a custom skill for Amazon’s Alexa service. The Alexa service converts the words you speak to a device like an Echo into written text. It then checks to see if the words match any of the built in intents like “help” or “exit.”

我的初衷是在为Amazon的Alexa服务编程自定义技能时。 Alexa服务将您在诸如Echo之类的设备上说出的单词转换为书面文本。 然后,它会检查单词是否与任何内置意图(例如“帮助”或“退出”)相匹配。

As a developer, you can also define your own intents by defining utterances that match the same intent. For example, the utterances “what are the conditions today?”, “how much pollen is in the air?”, and “are the allergy conditions bad?” might all be the user expressing their intent to ask for a conditions report. The smarts behind this is that you don’t have to define every variation of an utterance for a given intent. The processing algorithm is often good enough to match similar utterances to the same intent.

作为开发人员,您还可以通过定义与同一意图匹配的话语来定义自己的意图。 例如,“今天的情况如何?”,“空气中有多少花粉?”和“过敏状况是否不好?”这样的话。 可能都是用户表达了要求条件报告的意图。 这样做的聪明之处在于,您不必为给定的意图定义发声的每种变化。 处理算法通常足够好,可以将相似的发音匹配到相同的意图

For a chatbot developer, this is great. Instead of dealing with generating responses for hundreds or thousands of different inputs, I can just focus on generating responses for a handful of pre-defined intents.

对于聊天机器人开发人员来说,这很棒。 除了处理针对成百上千种不同输入的响应之外,我还可以集中精力针对少数预定义的意图生成响应。

My primitive regular expression matching was easy to code on my own. But the state of the art technology behind converting an utterance into an intent is quite sophisticated. Fortunately, there are several well-known vendors who offer Natural Language Understanding as a service.

我原始的正则表达式匹配很容易自己编写。 但是,将话语转换为意图的最新技术非常复杂。 幸运的是,有几家提供自然语言理解服务的知名供应商。

  • Microsoft Cognitive Services Language Understanding (LUIS)

    Microsoft认知服务语言理解( LUIS )

  • Amazon Web Services Lex

    亚马逊网络服务Lex

  • Google Dialogflow

    Google Dialogflow

  • Facebooks wit.ai

    Facebook的wit.ai

All of these services advertise themselves as “advanced deep learning” technologies for “building conversational interfaces.” All of them are API-based, meaning that they can be integrated into almost any application that has a connection to the Internet. And all offer a free tier at the usage level I currently needed.

所有这些服务都将自己宣传为用于“建立对话界面”的“高级深度学习”技术。 所有这些都是基于API的,这意味着它们可以集成到几乎所有与Internet连接的应用程序中。 所有这些都提供了我目前所需的使用级别的免费套餐。

For this project, I chose Dialogflow. I found the user interface pleasant, the APIs understandable, and it required almost no vendor lock in. It also included a fun add-on called Small Talk that easily let my bot reply to casual conversation like “how are you?” and “what’s your name.” Oddly enough I noticed from the logs that plenty of users enjoyed exchanging casual pleasantries with my bot.

对于这个项目,我选择了Dialogflow。 我发现用户界面令人愉悦,API易于理解,几乎不需要任何供应商锁定。它还包含一个有趣的加载项,称为Small Talk ,可让我的机器人轻松响应诸如“你好吗”之类的随意对话。 那你叫什么名字。” 奇怪的是,我从日志中注意到,很多用户喜欢与我的机器人交换休闲时光。

使用Dialogflow (Using Dialogflow)

The application loop when using an NLU service is actually simpler than what I had before. The bot is completely event driven. It waits for input from a user via a Facebook Messenger web hook, passes the text to Dialogflow to parse the intent, generates the appropriate response for the intent, and sends the formatted response back to the Facebook Messenger API.

使用NLU服务时,应用程序循环实际上比以前更简单。 该机器人完全是事件驱动的。 它等待用户通过Facebook Messenger Web挂钩输入,然后将文本传递给Dialogflow来解析意图,为意图生成适当的响应,然后将格式化后的响应发送回Facebook Messenger API。

Updating Hayfever to use Dialogflow was relatively smooth, with a couple exceptions.

更新Hayfever以使用Dialogflow相对顺利,但有一些例外。

First, it seems like I caught Dialogflow in the middle of a migration from their V1 to V2 API and the documentation had not quite caught up. When searching StackOverflow and other blogs, there was quite a bit of outdated information that referred to the V1 API.

首先,似乎在从他们的V1到V2 API迁移的过程中我抓住了Dialogflow,而文档还没有完全掌握。 在搜索StackOverflow和其他博客时,有很多有关V1 API的过时信息。

Second, Hayfever is a Facebook Messenger bot. The JSON format for embedding Facebook Messenger responses in the DialogFlow API is quite poorly documented. If I had chosen Facebook’s wit.ai instead, I’m sure this part would have been easier. But I want Hayfever to work on any messaging platform as well as voice platforms in the future.

其次,Hayfever是Facebook Messenger机器人。 用于将Facebook Messenger响应嵌入到DialogFlow API中的JSON格式的文档记录很少。 如果我选择了Facebook的wit.ai,那么我相信这部分会更容易。 但我希望Hayfever将来能在任何消息传递平台以及语音平台上工作

So I completely decoupled the Dialogflow intent processing from the Messenger response formatting. So the Dialogflow code has no idea that input is coming from Messenger, and Messenger has no idea that Dialogflow is parsing the intents. It wasn’t the easiest way to build this, but it’s quite future-proof.

因此,我将Dialogflow意图处理与Messenger响应格式完全分离了。 因此,Dialogflow代码不知道输入来自Messenger,并且Messenger不知道Dialogflow正在解析意图。 这不是构建它的最简单方法,但是它可以面向未来。

Switching to the Dialogflow NLU immediately improved the quality of Hayfever’s conversations. The bot was no longer thrown off by subtle variations in expected inputs, it could make small talk with users, and it could even guess at intents from inputs it had never seen before. There is still a lot of training and optimizing I can do, but this is clearly a move in the right direction.

切换到Dialogflow NLU立即改善了Hayfever对话的质量。 该机器人不再被预期输入的细微变化所抛弃,它可以与用户闲聊,甚至可以从之前从未见过的输入中猜出意图 。 我仍然可以进行很多培训和优化,但这显然是朝着正确方向迈出的一步。

结语 (Wrapping Up)

Hayfever is chatbot designed to help users track and understand allergy symptoms. Early versions used primitive dialog tree mechanics and were quite poor at understanding natural conversation. Swapping in a deep learning-based natural language understanding (NLU) service like Dialogflow dramatically improved Hayfever’s ability to converse with users.

Hayfever是一款聊天机器人,旨在帮助用户跟踪和了解过敏症状。 早期版本使用原始对话树机制,并且在理解自然对话方面非常差。 交换诸如Dialogflow之类的基于深度学习的自然语言理解(NLU)服务,大大提高了Hayfever与用户交谈的能力。

By keeping the NLU processing separate from the platform-specific input and output, there was almost no increase in code complexity and no platform lock in.

通过将NLU处理与特定于平台的输入和输出分开,几乎不会增加代码复杂性,也不会锁定平台。

In the future I hope to make Hayfever available on voice devices like Amazon Alexa and Google Home, as well as additional messaging platforms like Telegram. I would also like to try combining the NLU with some of the graph-based conversation tools I used previously to perhaps give the chat bot better memory of what has already happened in the conversation.

将来,我希望在诸如Amazon Alexa和Google Home之类的语音设备以及诸如Telegram之类的其他消息传递平台上提供Hayfever。 我还想尝试将NLU与以前使用的一些基于图形的对话工具相结合,以使聊天机器人更好地记忆对话中已经发生的事情。

翻译自: https://www.freecodecamp.org/news/how-i-made-a-smarter-chatbot-with-intents-5e6ad6e0fd71/

chatbot

chatbot_我如何通过帮助我的ChatBot理解意图来使其变得更聪明相关推荐

  1. 使用Python从头开始构建简单的Siri机器人?

    如今,语音聊天机器人至少取代了85%的人工服务.今天我会带着大家一步一步用python实现简单的聊天机器人. 那么什么是聊天机器人? 聊天机器人是一种人工智能驱动的软件(比如苹果的Siri.小爱同学, ...

  2. 【NLP】创建强大聊天机器人的初学者指南

    作者 | Louis Teo 编译 | VK 来源 | Towards Data Science 你是否面临着太多来自客户的标准要求和问题,并且难以应对?你是否在寻找一种既不增加成本又扩大客户服务的方 ...

  3. 途虎养车三个创始人_3个来自非常规创始人的获奖技术和产品见解

    途虎养车三个创始人 by Henry 通过亨利 3个来自非常规创始人的获奖技术和产品见解 (3 Winning Technology & Product Insights from WeCha ...

  4. 《Python自然语言处理-雅兰·萨纳卡(Jalaj Thanaki)》学习笔记:07 规则式自然语言处理系统

    07 规则式自然语言处理系统 7.1 规则式系统 7.2 规则式系统的目的 7.2.1 为何需要规则式系统 7.2.2 使用规则式系统的应用 7.2.3 练习 7.2.4 开发规则式系统需要的资源 7 ...

  5. TensorFlow Lite,ML Kit 和 Flutter 移动深度学习:1~5

    原文:Mobile Deep Learning with TensorFlow Lite, ML Kit and Flutter 协议:CC BY-NC-SA 4.0 译者:飞龙 本文来自[Apach ...

  6. LLMs之InstructGPT:《Training language models to follow instructions with human feedback》翻译与解读

    LLMs之InstructGPT:<Training language models to follow instructions with human feedback>翻译与解读 导读 ...

  7. 一万年太久,只争朝夕 | Foundation model的进展仍不够快

    编者按:如今根基模型(Foundation Models)的应用和相关创新正在快速涌现,但仍有很大的提升空间,目前还无法充分发挥根基模型的潜能.将其高效快速地应用于企业级AI应用中. 根基模型的加速应 ...

  8. 【CSDN AI周刊】第22期 柯洁对战AlphaGo 微软小冰出诗集 百度是AI公司

    欢迎人工智能相关的技术投稿.约稿.行业分析.热点新闻.编译等,请发送邮件至baiyan@csdn.net,期待大家投稿 人机对决 李开复预测AlphaGo对战柯洁:人类胜率几乎为零 日前谷歌联合中国棋 ...

  9. 机器学习做自动聊天机器人_当您14岁时建立和销售聊天机器人会是什么样的感觉...

    机器学习做自动聊天机器人 by Alec Jones 通过亚历克琼斯 当您14岁时建立和销售聊天机器人会是什么样的感觉 (What it's like to build and market a ch ...

最新文章

  1. cascader 动态加载 回显_Element中的Cascader(级联列表)动态加载省\市\区数据的方法...
  2. boost::stl_interfaces::iterator_interface相关的测试程序
  3. 热门的“挑战视频”,凭什么火起来的?
  4. 9. 弹出键盘挡住input
  5. dojo还有人用吗_我的Dojo中有一个Mojo(如何编写Maven插件)
  6. java的case_java中的switch case语句使用详解
  7. Centos服务器查看当前的并发数
  8. 回顾2017系列篇(二):移动端APP设计趋势
  9. border-box
  10. 性能之巅:Linux网络性能分析工具
  11. 计算机专业内卷严重,考研,这6个专业“内卷”严重,竞争较为激烈!
  12. n1 linux wifi,【教程】N1在EMMC安装LINUX和HASSIO实现智能家居中枢
  13. eclipse集群tomcat
  14. 如何手动优化机器学习模型超参数
  15. 5.3 数据通路-专用通路
  16. CAD转KML乱码处理
  17. java 压制警报_适用于Java开发人员的微服务:监视和警报
  18. python 豆瓣源安装_python pip使用豆瓣源技巧和pip配置文件更改豆瓣源
  19. JN5169 ZigBee3.0软硬件开发环境
  20. Windows系统介绍

热门文章

  1. PS5 VS XSX 谁是最强次世代主机?
  2. 云豹智能发布全功能云霄DPU网卡,引领数据中心新趋势
  3. linux常用命令2
  4. 机器学习完整项目实战附代码(一):探索型数据分析+特征工程+建模+报告
  5. 阿里云容器镜像服务(Docker Registry)
  6. 美元指数K线图怎么看?
  7. 【WY】数据分析 — 空间数据阶段一 :进阶语法 二 —— 3D图表
  8. Excel里关于if的9个函数,如何指定条件求和、计数、平均等
  9. MATLAB 2020a的参考安装教程
  10. Hexo系列(四) NexT主题配置