ChatGPT Getting Started Case|Business Intelligence Dialogue Customer Service (1)

ChatGPT is a new artificial intelligence technology-driven natural language processing tool launched by the artificial intelligence research laboratory OpenAI. It uses the Transformer neural network architecture, which is also the GPT-3.5 architecture. This is a model for processing sequence data. Comprehension and text generation capabilities, especially it will train the model by connecting a large number of corpora, which contain dialogues in the real world, so that ChatGPT has the ability to know astronomy and geography, and also interact according to the context of the chat, It is possible to communicate in a chat scene that is almost the same as that of a real human being.

ChatGPT is not only a chat robot, but also can perform tasks such as writing emails, video scripts, copywriting, translation, and code.

This article brings you an introductory case related to ChatGPT - the results of "Business Intelligence Dialogue Customer Service". In the future, we will use examples to illustrate the application of remote interactive, local interactive and customized customer service.

01

Q&A Smart Customer Service Functional Architecture

Q&A Intelligent Customer Service Introduction

Question and Answer (QA) intelligent customer service retrieves answers based on questions and returns results that users can understand. It focuses on the process of question and answer, knowledge reasoning and question-answer matching. In the process of task processing, some functions of the question answering system are similar to information query. For example, they all need to retrieve answers based on the questions raised by users, but there may be differences in the specific content of input/output, information acquisition process, and application scenarios.

Question answering systems can be classified according to different perspectives (such as application domain, answer form, and corpus format, etc.). Based on the application field, it can be divided into limited domain question answering system and open domain question answering system. The limited domain question answering system means that the system can only deal with problems in a specific field or a specific range, such as only in the medical, business or financial fields, while the open domain question answering system can face a wider range of fields. According to the classification of supporting technologies, it can be divided into database system, dialogue system, reading comprehension system, question set system, knowledge base system, etc.

Functional Architecture of Smart Q&A Customer Service

A typical question answering system includes question input, question understanding, information retrieval, information extraction, answer ranking, answer generation, and result output. First, the user asks a question, and the retrieval operation obtains relevant information by querying the knowledge base, and extracts the corresponding candidate answer feature vector from the extracted information according to specific rules, and finally screens the candidate answer output results to the user, see Figure 9-1 .

■ 图9-1智能问答客服基本流程

02

智能问答客服框架

问答型自动应用客服主要围绕问题提出、问题理解和候选答案的筛选等这几个中心点展开,根据用户输入的问题信息,理解用户问题的主要意图并识别问题的主题范畴,从相应知识库或者数据库(如外部知识库或者内部知识库)中检索答案,无法检索信息时可能借助推理生成候选答案,通过机器学习或深度算法进行最佳答案甄别,并将最优答案以用户容易理解的方式输出,一般包含问题处理、问题映射、查询构建、知识推理以及消歧排序等主要处理模块。

问题处理

问题处理流程识别问题中包含的信息,判断问题的主题信息和主题范畴归属,比如一般问题和特定主题问题的区分,然后提取与主题相关的关键信息,如人物信息、地点信息和时间信息等。

问题映射

根据用户咨询的问题,进行问题映射。通过相似度匹配和同义词表等解决映射问题,可能需要执行拆分和合并操作。

查询构建

通过对输入问题进行处理,将问题转换为计算机可以理解的查询语言,然后查询知识图谱或者数据库,通过检索获得相应备选答案。

知识推理

根据问题属性进行推理,如果属于知识图谱或者数据库中已知定义信息,则直接查找并返回结果。如果问题属性未定义,则需要通过机器算法或深度学习推理生成答案。

消歧排序

根据知识图谱中查询返回的单数或者复数备选答案,结合问题属性进行消歧处理和优先级排序,输出最优答案。

03

问答智能客服实战

目前基于模板的客服应用程序比较多,介绍三种方法。第一种是基于远程模式的问答对话,需要提前创建问答知识库(QnA Maker Knowledge Base)服务,常见的知识库模板比较多,网址https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/create-publish-knowledge-base?tabs=v1提供了一种模板的相应信息。本实例的知识库使用微软Azure系统提供的模板文件qna_chitchat_caring.tsv,通过导出后导入方式上传到智能客服应用中。第二种是基于本地模板的问答对话应用,需要提前将模板下载到本地安装。第三种是基于用户定制的问答系统,这种方式用户需要编写自定义代码。后两种方法在下一篇展开。

基于Python框架的智能对话应用模板可以在网址https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python下载。使用到的其他应用包括Bot Framework Emulator(下载网址为https://github.com/Microsoft/BotFramework-Emulator/releases/tag/v4.13.0),代理应用程序Ngrok(下载网址为https://ngrok.com/download)。启动环境执行pip install botbuilder.ai安装智能客服相应库文件。

基于远程交互模式问答客服

基于远程服务器模板的交互模式的主要操作步骤如下。

(1) 在微软Azure官网主页注册账户,网址为https://azure.microsoft.com/en-us/。注册成功后登录到Azure Portal页面,网址为https://portal.azure.com/#home

(2) 切换到Azure Portal页面,选择QnA makers创建服务QnA Service,如图9-2所示。

■ 图9-2微软远程问答客服创建界面

(3) 单击QnA Maker Portal选项,如图9-3所示。

■ 图9-3问答创建选项

(4) 单击Create a QnA Service按钮创建知识库,参见图9-4。

■ 图9-4创建问答服务

(5) 根据提示完成步骤(1)~步骤(4),然后单击Create your KB按钮完成知识库创建,参见图9-5。

■ 图9-5创建知识库

(6) 知识库完成创建后,单击Save and train按钮,最后单击Publish按钮,如图9-6所示。

■ 图9-6发布智能客服

(7) 知识库完成创建后,单击My knowledge bases按钮确认知识库详细信息,参见图9-7。

■ 图9-7确认知识库信息

(8) 单击View Code按钮,确认并记录主机地址、知识库和认证键值。

POST /knowledgebases/knowledgebases-id/generateAnswerHost: https://host-addressAuthorization: EndpointKey EndpointKey -idContent-Type: application/json{"question":"<Your question>"}

(9) 新建app.py文件,从botbuilder.core库导入BotFrameworkAdapter、BotFrameworkAdapterSettings、TurnContext、ConversationState、MemoryStorage类,导入网页框架Flask库以及asynciobotbuilder.schema.Activity。主要代码如下。

app = Flask(__name__)loop = asyncio.get_event_loop()botframework = BotFrameworkAdapterSettings("","")botadapter = BotFrameworkAdapter(botframework)remotebot = RemoteBot()@app.route("/api/messages",methods=["POST"])def messages():    if "application/json" in request.headers["content-type"]:        context = request.json    else:        return Response(status = 415)    activity = Activity().deserialize(context)        if "Authorization" in request.headers:        outcome = request.headers["Authorization"]    else:        outcome=""    async def call_fun(turncontext):        await remotebot.on_turn(turncontext)    task = loop.create_task(        botadapter.process_activity(activity,outcome,call_fun)        )    loop.run_until_complete(task)if __name__ == '__main__':    app.run('localhost',4000)

(10) 新创建remotebot.py文件,主要代码如下。

from botbuilder.core import TurnContext,ActivityHandler,MessageFactoryfrom botbuilder.ai.qna import QnAMaker,QnAMakerEndpointclass RemoteBot(ActivityHandler):    def __init__(self):       endpoint = QnAMakerEndpoint("knowledgebases-id","EndpointKey -id","https://host-address")       self.botmaker = QnAMaker(endpoint)    async def on_message_activity(self,context:TurnContext):      response = await self.botmaker.get_answers(context)      if response and len(response) > 0:         await context.send_activity(MessageFactory.text(response[0].answer))

(11) 在app.py路径下启动命令行窗口,执行命令python app.py启动客服程序,命令行窗口提示Running on http://localhost:4000的信息,其中,4000是app.py中配置的端口PORT属性值,参见图9-8。

■ 图9-8启动页面

(12) 启动Bot Framework Emulator程序,单击左下角设置按钮,在Path to ngrok中选择下载的ngrok.exe的路径位置,勾选Bypass ngrok for local addresses,Run ngrok when the Emulator starts up以及Use version 1.0 authentication tokens复选框,参见图9-9和图9-10。

■ 图9-9智能客服客户端

■ 图9-10智能客服客户端模拟器设置

(13) 单击Open Bot按钮,在客服程序URL中输入“http://localhost:4000/api/messages”,然后单击Connect按钮,参见图9-11。

■ 图9-11远程连接设置

(14) 智能客服应用对话画面启动后,确认右边窗口中的日志输出正常,以及Ngrok应用处于代理监听状态,然后在左边窗口中输入需要咨询的问题,测试远程客服程序提供的回复结果,参见图9-12。

■ 图9-12远程连接对话测试

04

参考书籍

《Python自然语言处理——算法、技术及项目案例实战(微课视频版)》

ISBN:9787302606628

作者:(日)中本一郎、马冀、张积林、郭彦、庄伟卿、冯丽娟、江明、黄益

定价:59.90元

扫码优惠购书

本书全面介绍了数据挖掘和商务智能的基础知识、主要技术、基于Python语言的商务应用生成技术。全书共12章,主要内容包括数据挖掘、深度学习、Seq2Seq、商务智能应用创建及部署、Tensorflow、卷积神经网络、循环神经网络和Rasa技术。本书注重理论结合实战,实例部分配套操作步骤,重要代码讲解,中间图形和文本输出,将实战内容融合在课程教学过程中,使理论紧密联系实际,帮助学生在潜移默化中获得知识。

Guess you like

Origin blog.csdn.net/weixin_46579013/article/details/129127595