ChatBot

微信中有类似Facebook messenger中chatbot的功能吗?用什么技术开发

https://www.zhihu.com/question/48114310/answer/112473923

by 田暻

不知道你是是不是说的智能聊天机器人? 如果是的话其实很简单也很复杂,在于关键的几个技术: 1.搜索算法 2.中文分词算法 3.机器学习 4.机器推理

当我们谈论 Bot 的时候,我们在谈论什么

2016-08-08 王守崑

从应用的场景来看,Chatbot 可以分为开放域(Open-Domain)问题和封闭域(Closed-Domain)问题两大类。

从表现形式看,Chatbot可以分为单轮对话和多轮对话两种类型。单轮对话其实可以看做是问答系统(Question Answering System)的变形, 一般是一问一答的形式,用户提问,机器生成相应答案的文本或者是综合与答案相关的各种信息返回给用户。多轮对话则更接近我们通常理解的人与人之间的对话模式,通常是有问有答,除了用户提问,机器也会主动向用户询问,并且会根据上下文来判断该给出什么样的答案或提出什么样的问题。 而多轮对话服务,往往会应用在信息搜集、商品和服务导购推荐、专业方案咨询等等一系列结构复杂、会话行程长的深度服务项目里,用户通过使用这类产品会在某一领域获得相对完整的服务,解决一个复杂问题,或者获得某种方向性的引导。

事实上,的确有一些 Chatbot 项目就是用开源搜索引擎来实现的。 在规则匹配和文档排序上可以加入各种复杂的启发式规则或者机器学习算法,从而提高匹配精度。

深度 | 王守崑:AI 时代,产品经理的机遇和挑战

产品的对话式交互(conversation UI, CUI)特性

新的 GPT —— 人工智能

经济历史学家 Gavin Wright 对于通用技术( GPT General Purpose Technology )下了一个定义:「 Deep new ideas and techniques that have the potential for important impacts on many sectors of the economy 」。一门通用技术可以做到显著提升生产率,并被应用在各行各业。人工智能正是发生在 21 世纪的新的通用技术,但一门新通用技术的行业的成熟期是极其漫长的。不但需要基础设施的支持,还需要各种类型的 人才积累 。目前人工智能技术正处于这个漫长的行业积累当中,人工智能在学术、实验室的效果很好,各行各业都在关注他在业界中的实践表现,但是目前从事这个领域的绝大部分是技术专家,很少其他领域的专业人士参与。特别是交互领域的 AI 产品,很多时候还是只个「 人工智障 」。产生 新的团队组织架构和工作范式 ,这里面也会衍生新的就业机会。

Andrew Ng 的观点,一秒钟法则:如果人的判断或者人做的事情能在一秒钟之内完成的话,这件事情就很有可能会被 AI 替代。

所有能用一秒法则去做的事情一定是 大规模和重复性 的,并且背后含义是这件事一定是在 限定的、非常窄 的领域。如果这个场景 涉及到复杂领域,就没有办法用一秒法则去做 。比如,计划暑假去哪里玩儿?这回涉及到很多领域的问题,比如目的地的情况,机票是不是订得到,预算是多少等等一系列问题。

另外一个场景特征就是,就是可以 快速获得反馈 。实际工作中的产品经理经常要考虑问题,就是能不能快速获得反馈。无论是不是用人工智能的技术,越快获得反馈的产品或场景,其实越适合用算法。原因在于它能够快速的去做优化调整,去调整参数、调整模型,它拥有足够多的训练数据,而且它会是足够快的。反过来说,有比较长的反馈周期的场景,是很难做优化的,因为中间可能会发生很多事情,要控制的变量太多,很难把这个周期中的因和果联系起来。

所以产品经理做是否可以借助 AI 技术做一定程度上的优化的判断依据就是,是否能获得大规模的重复性数据,领域足够垂直足够窄,并且事情做得好不好可以很快收到反馈。

CUI :一种新的交互模式

说到 CUI 对话式交互和 GUI 图形式交互,首先明确一点,CUI 肯定不是去替代 GUI 的。两者互相之间不是替代关系,而是各有擅长的关系的。

从效率的角度来看,GUI 的一个界面上可以展示非常多的内容,所以更适合做 广度展示 。而 CUI 更适合做 深度展示 。在 GUI 的情况下,完成一项任务需要点击十次二十次鼠标,需要十到二十个页面才能完成这项工作的话,你会觉得这个设计过于繁琐。如果是个浅的场景,需要广度的展示,那 GUI 是合适的;如果场景需要一个深度的、若干次的沟通,有可能 CUI 是更合适。

从用户体验上来讲,GUI 会更强调空间感,CUI 更强调时间感。在做 CUI 设计的时候,或者说你在寻找什么内容适合 CUI 场景的时候,需要找到那些对时间感非常敏感,或者说随着时间的流逝会发生变化的东西。

其次,从预期 (Anticipation) 的角度来看,人们对 GUI 的感受是公共的。我过去有八年时间,在 GUI 上做个性化推荐这件事,希望做到千人千面。但在 GUI 的界面下用户普遍预期还是,我看到的东西跟别人看到的东西是一样的。

但是对于对话这件事大家没有这个预期,用户认为对话机器人应该针对我说一些我所预期的东西,由此用户会有更强的参与感。

我们现在实际上是 多了一种表达方式 。过去由于技术条件的限制,我们只能做 GUI 的事情,所以专注做有信息广度的、空间感强的、公共页面的产品。但现在有一天,有这样的技术,让我们有机会去做信息深度的展示,去做时间感的设计、去做个性化的参与感的设计,做一些能够自我进化的设计。

硅谷创投教父 Peter Thiel 写的《从0到1》 这本书曾一再强调,创业公司不要进入充分竞争的行业,做企业的目标一定是做垄断。如果想要在足够细分领域中做到这一点的话,就 一定要寻找用户价值高同时具备稀缺性的事情,同时也就意味着这件事的技术成熟度一定是低的 。也就是说 我们要主动去承担技术成熟度低的这样一个风险

稀缺性的潜在含义是,要成为细分领域的关键业务环节既然选择了细分领域,就不要再想周边那些「可有可无」的东西了 。一定要在关键环节形成垄断,这样才能给你带来稀缺性;技术成熟度是我们需要承担的风险,反过来也意味着说我们要选择合适的技术,做产品/市场匹配的事情。

我们可以由此推演出来商用机器人的场景特征:

  • 清晰的知识结构和边界 ? 怎么由上面的介绍推演出来的
  • 非标准化服务,信息不对称
  • 能够通过 数据积累 提升服务质量
  • 能够建立知识和技术壁垒

对话只是粘合剂

对话不是机器人的目的,我希望对话是作为一个粘合剂存在的。我认为 真正提供价值的其实是它的特别属性带来的意义 ,比如他可以给用户做个性化推荐、推送定向广告、通过数据挖掘出来的 Patent 和 领域知识与模型 等等才是真正有价值的东西。

A Chatbot Design Framework

Craig Borysowich Aug 15, 2016

http://it.toolbox.com/blogs/enterprise-solutions/a-chatbot-design-framework-74153

On my current project as well as several others, there is a noted increase in interest and curiosity about adding and integrating chatbots to digital platforms for Banks and Financial Institutions . This has spawned a wide variety of offerings in the marketplace – especially from the big players like Microsoft, IBM, Google, and Facebook.

Buy vs. Build?

The initial question that most organization might tackle is whether or not to adopt one or multiple platform offerings in the marketplace or to grab some open source components and try to create your own chatbot engine.

It is becoming very clear that a chatbot ecosystem is going to be made up of a series of components that will help organize and manage chatbot interactions. Here is a breakdown:

  • Chatbot Connectors – you will need an API interface that links your chatbot to various different venues where you want people to be able to interact with your chatbot. This could be linking an interactive chat button on a website to creating personas on Facebook Messenger, Whatsapp, SMS or where ever you want to have a customer interaction point.
  • Natural Language Processor (NLP) – This is your AI engine that will try to parse questions and generate competent answers . Examples would be Watson from IBM or Wit.AI which is owned by Facebook .
  • Context Manager – This will be your base of information for the chatbot to try and assemble its answers. It is a collection of topics and synonyms with a series of weighted correlations that tie to the detailed information about a given topic area. // 好像这里的意思是知识库,而不是会话上下文管理。
  • Session/User Manager – This module lets a chatbot actually have some sort of continuity to a conversation where it at least has some basic understanding of the topic being discussed and what has been asked and answered previously . This tool will also be able to log conversations on a user by user basis for later review and quality evaluations.
  • Bot Manager – While many platforms can leverage machine learning capabilities to hone a chatbot independently, there is still the need for humans to create and tune chatbots to make sure that they are answering questions accurately. This means that it will likely be easier for people to create smaller topically focused bots than to try to create a single bot that can answer every question . So there would likely be a triage bot that evaluates what you want to discuss and then that would hand you off to an RRSP(Registered Retirement Savings Plan, 注册退休储蓄计划) chatbot that would be able to handle the detailed questions about RRSPs. Then if you want to talk about mortgages, it would hand you to a mortgage specialist chatbot and so on. The chatbot manager will help to link and manage the chatbot ecosystem for an organization
  • Human chat Integrator – more mature platforms like Microsoft offer the capability for a chatbot to seamlessly hand off a conversation that is getting too complicated for the chatbot to a human to continue the chat with the user in a manner that is invisible to the user . Machine learning modules can be applied to monitor these person to person interactions in order to grow the context manager database so that the bot can handle those questions better in future conversations.
  • Machine Learning Module – This extends the use of AI beyond the language parsing aspects to help build and grow the context database
  • Voice enablement module – The chatbot engine can leverage voice to text and text to voice capabilities to use the same chatbots for assisting callers in an IVR setting - the same way that they are used to chat on a text messenger.
  • Reporting Engine – statistics and detailed reporting on chatbot interactions and activity

Other components may be integrated for special features or biometric authentication of a user as this space matures.

Answer:

agreed - there are a lot of offerings in the open source space related to chatbots that covers many aspects of these same components that I have identified above. Look at pandorabots.com for some specific usages of the ROSIE open source chatbot platform

ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots. http://chatterbot.readthedocs.io/ https://github.com/gunthercox/ChatterBot

Author: Gunther Cox @ Rediker Software http://salvius.org/

import uuid
from chatterbot.queues import ResponseQueue

class Session(object):
        """
        A session is an ordered collection of statements
        that are related to each other.
        """

        def __init__(self):
                # A unique identifier for the chat session
                self.uuid = uuid.uuid1()
                self.id_string = str(self.uuid)
                self.id = str(self.uuid)

                # The last 10 statement inputs and outputs
                self.conversation = ResponseQueue(maxsize=10)


class ConversationSessionManager(object):
        """
        Object to hold and manage multiple chat sessions.
        """

        def __init__(self):
                self.sessions = {}

        def new(self):
                """
                Create a new conversation.
                """
                session = Session()
                self.sessions[session.id_string] = session
                return session


   def get(self, session_id, default=None):
                """
                Return a session given a unique identifier.
                """
                return self.sessions.get(str(session_id), default)


   def update(self, session_id, conversance):
                """
                Add a conversance to a given session if the session exists.
                """
                session_id = str(session_id)
                if session_id in self.sessions:
                        self.sessions[session_id].conversation.append(conversance)

Each session object holds a queue of the most recent communications that have occurred during that session. The queue holds tuples with two values each, the first value is the input that the bot received and the second value is the response that the bot returned .

一次 request 的处理过程

会创建一个目录 $HOME/nltk_data . nltk(Natural Language Toolkit)

preprocessor - /chatterbot/preprocessors.py

  • clean whitespace. Remove any consecutive whitespace characters from the statement text.

adpater

  • chatterbot.logic.best_match.BestMatch 和有 response 的 storage statement 逐句比较相似度,取相似度最高的结果 - Select the closest match to the input statement 使用下面两个工具之一

    • from Levenshtein.StringMatcher import StringMatcher as SequenceMatcher Python extension for computing string edit distances and similarities.
    • from difflib import SequenceMatcher
    • Get all statements that are in response to the closest match 这里只是一个简单的 contains 判断
  • chatterbot.logic.no_knowledge_adapter.NoKnowledgeAdapter

learn

  • Learn that the user’s input was a valid response to the chat bot’s previous output

update conversation sessions

  • 将这次的 request Statement 和 response Statement 追加到 conversation.queue 中
  • Statement 的结构 {'confidence': 0.65, 'text': 'Very well, thanks.', 'created_at': datetime.datetime(2017, 6, 20, 14, 33, 56, 986000, tzinfo=<bson.tz_util.FixedOffset object at 0x108112bd0>), 'storage': None, 'extra_data': {}, 'in_response_to': [<Response text:How are you doing?>]}

TODO 怎么使用 conversation 的历史记录

学习它记录 log 的点

pandorabots.com

Pandorabots是建立聊天机器人的集成开发环境。人工智能即服务(AIaaS)为机器人托管平台和SDK提供API访问,允许开发人员将对话界面集成到应用程序中。使用与勒布纳人工智能奖( Loebner Prize )获奖者相同的内容库。Pandorabots还可以根据你的规则构建虚拟代理,甚至可以帮助整合头像或语音功能。 Source: http://www.sohu.com/a/134985781_374240

Facebook Messenger