capstone项目clerkbot虚拟助手聊天机器人

本文是作者在Xccelerate数据科学与机器学习课程的顶点项目中创作的一部分,介绍了一个虚拟助手聊天机器人——Clerkbot的创建过程。文章详述了聊天机器人的框架、架构和设计,同时分享了实施过程中遇到的挑战。创建Clerkbot的动机包括创造实用产品以简化生活、探索聊天机器人的新颖概念,以及响应市场上日益增长的聊天机器人需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This article was written as part of a capstone project for Data Science & Machine Learning Immersive course at Xccelerate. We discussed our chatbot in detail including the framework, architecture, and design behind our bot, as well as some challenges we faced in the process.

本文是Xccelerate 数据科学与机器学习沉浸式课程的基本项目的一部分。 我们详细讨论了聊天机器人,包括其背后的框架,架构和设计,以及在此过程中面临的一些挑战。

前言 (Preface)

The idea of creating a virtual assistant chatbot first came to mind when we were brainstorming ideas for our capstone project. This sparked our interest for a few reasons:

当我们为顶峰项目集思广益时,首先想到了创建虚拟助手聊天机器人的想法。 这引起了我们的兴趣,原因如下:

1. We wanted to create a product that we would genuinely enjoy using and that it can make our lives easier in some way.

1.我们想要创建一种我们真正喜欢使用的产品,并且该产品可以使我们的生活更加轻松。

2. Making a chatbot is a relatively new concept to us but it is one that we are keen on learning more about because chatbots are fun to use.

2.制作聊天机器人对我们来说是一个相对较新的概念,但是我们渴望学习更多,因为聊天机器人使用起来很有趣。

3. We have the impression that the current market has a high demand for chatbots and its popularity is exponentially growing over the years.

3.我们给人的印象是,当前市场对聊天机器人的需求很高,并且其受欢迎程度多年来呈指数增长。

For the reasons given above, we began our journey to becoming self-proclaimed chatbot experts.

由于上述原因,我们开始了成为自称为聊天机器人专家的旅程。

问题陈述 (Problem Statement)

Upon further research, we learned that the chatbot industry is continuously growing and that chatbots have become a necessity in industries like finance. The accessibility and ease of a customized chatbot as well as the increased utilization among messaging apps have resulted in an inevitable growth in the tech and chatbot industry[1]. However, the problem we face today is that while chatbots can increase efficiencies on both business and consumer ends, there are still some technical limitations that hinder customer service experiences such as slow response time and poor connectivity.

通过进一步研究,我们了解到聊天机器人行业正在不断发展,并且聊天机器人已成为金融等行业的必需品。 定制的聊天机器人的可访问性和易用性以及消息传递应用程序之间的利用率不断提高,导致了技术和聊天机器人行业的必然增长[1]。 但是,我们今天面临的问题是,尽管聊天机器人可以提高业务和消费者端的效率,但仍然存在一些技术上的局限性,例如响应时间慢和连接性差,阻碍了客户服务体验。

In this project, we aim to develop a chatbot that can answer questions at any time of day, effectively addresses user’s requests, and able to drive a good conversation that resembles a human. Instead of creating one for a particular enterprise, we decide to create a digital assistant that can help everyone out. Our motivation stems from the fact that we are constantly juggling several tasks at once and going back and forth with different apps for different things. A good virtual assistant can save time and make life easier for its user. Hence, we are determined to develop a chatbot that combines several crucial functions for daily tasks.

在这个项目中,我们的目标是开发一个聊天机器人,该聊天机器人可以在一天中的任何时间回答问题,有效地解决用户的要求,并能够推动类似于人的良好对话。 我们决定创建一个可以帮助所有人的数字助理,而不是为特定企业创建一个。 我们的动力来自这样一个事实,即我们不断地同时处理多个任务,并使用不同的应用程序来处理不同的事情。 好的虚拟助手可以节省时间,并使用户的生活更轻松。 因此,我们决心开发一种聊天机器人,该机器人结合了日常任务的几个关键功能。

什么是CLERKbot? (What is CLERKbot?)

CLERKbot is a 6-in-1 chatbot that operates on Telegram. It allows users to connect to Google calendar, sets appointments, and displays reminders according to the schedule that day. It can activate Google Maps when users need directions to their destinations. Additionally, CLERKbot offers weather forecasts, searches for restaurants nearby, and provides a list of locations that patients with COVID-19 had visited in Hong Kong.

CLERKbot是在Telegram上运行的6合1聊天机器人。 它允许用户连接到Google日历, 设置约会并根据当天的时间表显示提醒 。 当用户需要前往目的地的路线时,它可以激活Google地图 此外,CLERKbot还提供天气预报,搜索附近的餐馆 ,并提供COVID-19患者在香港访问过地点的列表。

我们如何构建CLERKbot? (How did we build CLERKbot?)

We used Rasa by using Rasa Demo Bot to ensure the chatbot answers like a human being.

我们通过使用Rasa Demo Bot使用Rasa来确保聊天机器人像人类一样回答。

  • We used Google Calendar API to gain access to the calendar in order to add events to it and avoid time conflict

    我们使用Google Calendar API来访问日历,以便向其中添加事件并避免时间冲突
  • We used Google Geolocation API to get the user’s current location for location-related services

    我们使用了Google Geolocation API来获取用户当前的位置相关服务的位置
  • We used OpenWeather API to acquire the weather forecasts in the user’s location

    我们使用OpenWeather API来获取用户所在位置的天气预报
  • We used the Hong Kong Government’s API to obtain the COVID-19 locations

    我们使用了香港政府的API来获取COVID-19位置

We used ngrok to create a connection to our local computer that is publicly available on the Internet and deployed it on Telegram.

我们使用ngrok创建了到本地计算机的连接,该连接在Internet上公开可用,并已将其部署在Telegram上。

Rasa如何运作? (How does Rasa work?)

Image for post
The flow of conversation in Rasa [3]
Rasa中的对话流程[3]

Rasa is an open-source machine learning framework that is great at building contextual chatbots[2]. With Rasa, CLERKbot can learn to respond to phrases and understand the core meaning of words inside of phrases.

Rasa是一个开放源代码的机器学习框架,非常适合构建上下文聊天机器人[2]。 借助Rasa,CLERKbot可以学习对短语的响应并了解短语中单词的核心含义。

Rasa is comprised of two main components:

Rasa由两个主要组件组成:

Rasa NLU and Rasa Core

Rasa NLU和Rasa Core

Rasa NLU, aka natural language understanding, is the “ear” of the chatbot. It comprehends the user’s messages, determines the intent, and extracts entities from the message.

Rasa NLU(又称自然语言理解)是聊天机器人的“耳朵”。 它理解用户的消息,确定意图,并从消息中提取实体。

Rasa Core is the “brain” of the chatbot. It is a chatbot framework that manages the flow of the conversation, holds meaningful conversations with users, and decides what to do next.

Rasa Core是聊天机器人的“大脑”。 它是一个聊天机器人框架,用于管理对话的流程,与用户进行有意义的对话并决定下一步要做什么。

Rasa中使用的关键字 (Keywords Used In Rasa)

Image for post

Intents: Purposes or goals expressed in a user’s input. Once CLERKbot recognizes the intent of the user, it will proceed to an applicable next action.For example, if a user types “I want to update my calendar”,the user’s intent would be “request_create_schedule”.

意图 :意图或者目标在用户的输入表示。 CLERKbot识别出用户的意图后,将继续执行适用的下一个动作。例如,如果用户键入“我想更新日历” ,则用户的意图将为“ request_create_schedule”

Entities: Information in the user input that is relevant to the user’s intents. Given the example above, the entities would be:“event” : “Meeting with John”“location” : “central”“date” : “2020–08–17T09:00:00+08:00”

实体 :用户输入中与用户意图相关的信息。 在上面的示例中,实体将是: “事件”:“与约翰聚会”“位置”:“中心”“日期”:“ 2020–08–17T09:00:00 + 08:00”

Stories: Sample interactions between users and CLERKbot consisting of user intents and actions taken by the bot.

故事 :用户与CLERKbot之间的交互示例包括机器人的用户意图和采取的行动。

Actions: Operations performed by the bot either asking for more details to fill the entities or integrating with APIs.

动作 :由机器人执行的操作,要求提供更多详细信息以填充实体或与API集成。

Let’s explore more about how can Rasa recognize the user’s intent and extract the entities in the coming paragraphs.

让我们探索更多有关Rasa如何识别用户意图并在接下来的段落中提取实体的信息。

拉萨NLU (Rasa NLU)

We grouped examples by intent and assigned custom entity labels to words so the bot can define what a “location” and “summary” is.

我们按意图对示例进行了分组,并为单词分配了自定义实体标签,以便机器人可以定义“位置”和“摘要”是什么。

## intent:inform- Help me to create a [meeting with John](summary) on Wednesday at 2pm

## intent:inform-帮助我在星期三下午2点创建[与John的会议](摘要)

- [Mums Birthday dinner](summary) on March 9 at [Hotel Icon](location)

-3月9日,[妈妈生日晚宴](摘要)在[酒店图标](位置)

- I want to schedule a [doctor’s appointment](summary) on Sunday morning in [Wan Chai](location).

-我想在星期天早上在[湾仔](工作地点)安排一次[医生的任命](摘要)。

In Rasa, incoming messages are processed by a sequence of components. These components are executed one after another in a so-called processing pipeline. There are few components included:

在Rasa中,传入消息由一系列组件处理。 这些组件在所谓的处理管道中一个接一个地执行。 包含的组件很少:

  1. Tokenizer — to split the sentence into words

    分词器-将句子分解为单词
  2. Featurizerto transform the tokens into features that can be used in ML algorithms

    Featurizer 将令牌转换为可在ML算法中使用的功能

  3. DucklingHTTPExtractoran entity extractor for dates and numbers

    DucklingHTTPExtractor 日期和数字的实体提取器

  4. DIETClassifier — both an intent classifier and entity extractor

    DIETClassifier —意图分类器和实体提取器

DIETClassidier is a multi-task transformer architecture that can perform both intent classification and entities recognition together. It is an important part of our bot to understand a natural language by capturing relationships and the sequence of words in sentences.

DIETClassidier是一种多任务转换器体系结构,可以同时执行意图分类和实体识别。 通过捕获关系和句子中单词的顺序来理解自然语言是我们机器人的重要组成部分。

Image for post
DIET Interactive Demo[4]
DIET互动演示[4]

Rasa Core (Rasa Core)

Rasa Core decides what happens next in the conversation by providing different story paths, which is called dialogue management. Rather than using lots of if/else statements, it uses a machine learning model trained on example conversations to decide what to do next.

Rasa Core通过提供不同的故事路径(称为对话管理)来决定对话中下一步将发生什么。 它没有使用大量的if / else语句,而是使用在示例对话中训练的机器学习模型来决定下一步要做什么。

## event create path 1* greet- utter_greet* request_create_event- utter_more_info- event_form- form{“name”: “event_form”}- form{“name”: null}- utter_confirm_schedule_details> check_asked_schedule_details

##事件创建路径1 * greet- utter_greet * request_create_event- utter_more_info- event_form- form {“名称”:“ event_form”}-form {“名称”:null}-utter_confirm_schedule_details> check_asked_schedule_details

## user confirm details + event created> check_asked_schedule_details* affirm- action_create_event- slot{“success”:”success”}- action_set_reminder- action_route_plan- action_suggest

##用户确认详细信息+创建的事件 > check_asked_schedule_details *肯定-action_create_event- slot {“ success”:“ success”}-action_set_reminder- action_route_plan- action_suggest

Image for post

Furthermore, CLERKbot is not simply a FAQs chatbot because we defined our custom actions. We wrote custom actions in python to call external APIs. For instance, when the weather forecast action is called, the bot links to the weather API and retrieves the information as defined in our actions.py file.

此外,CLERKbot不仅仅是一个常见问题解答聊天机器人,因为我们定义了自定义操作。 我们在python中编写了自定义操作,以调用外部API。 例如,当调用天气预报动作时,该机器人会链接到天气API并检索我们的actions.py文件中定义的信息。

绩效评估 (Performance Evaluation)

Image for post
Image for post

Before we evaluated the performance of our model, we had to make sure the training data is free of conflicts and errors. We used a story structure validation tool to check for any conflicting stories. The example above indicates an instance of conflicting stories. The model identifies the user’s intent (“request_create_event”) but is not sure whether to “utter_more_info” or to provide an “event_form” as they both come after the “request_create_event” intent. Therefore, we try to avoid misleading training data as such so that Rasa does not get confused with what to do next.

在评估模型的性能之前,我们必须确保训练数据没有冲突和错误。 我们使用了故事结构验证工具来检查是否有冲突的故事。 上面的示例表明了一个相互矛盾的故事。 该模型可以识别用户的意图( “ request_create_event” ),但不确定是“ utter_more_info”还是要提供“ event_form”,因为它们都遵循 “ request_create_event”意图。 因此,我们尽量避免误导训练数据,以免Rasa与下一步的工作混淆。

交叉验证 (Cross-Validation)

We checked our training data by using cross-validation to understand how the model performed.

我们通过使用交叉验证来检查训练数据,以了解模型的性能。

The F1-score serves as a general ‘grade’ of the performance. It takes into account two metrics: precision and recall[5].

F1成绩是表现的一般“成绩”。 它考虑了两个指标:精度和召回率[5]。

Precision looks at all of the messages the model identified as intent A and measures how many were actually intent A.

Precision会查看模型识别为意图A的所有消息,并衡量实际有多少意图A。

“Out of all predictions of A, how many were correct?”

“在对A的所有预测中,有多少是正确的?”

Recall, on the other hand, looks at the total number of detecting A, out of all examples pertaining to A in reality.

另一方面, 回想一下 ,实际上是在与A有​​关的所有示例中,检测到A的总数。

“Out of all the examples in A, how many were detected?”

“在A中的所有示例中,有多少被检测到?”

Image for post

There are 17 intents and 20–80 user examples per intent in our model, the overall accuracy of recognizing the intent reach 85%; precision, recall, and f1-score are over 70%.

在我们的模型中,有17个意图和每个意图20-80个用户示例,识别意图的总体准确性达到85%; 准确性,召回率和f1得分均超过70%。

混淆矩阵 (Confusion Matrix)

Image for post
The horizontal axis indicates the intents the model predicted. The vertical axis indicates the actual intents. The numbers shown diagonally down the grid are the number of true positives or correct classifications.
横轴表示模型预测的意图。 纵轴表示实际意图。 网格对角线下方显示的数字是真实肯定或正确分类的数量。
Image for post

The confusion matrix shows how often a model made a correct classification. For example, here we see the “request_create_event” intent was misclassified as “ask_schedule”, “chitchat”, and “inform”. It is acceptable to be classified as “inform” as that leads to the same response; however, “ask_schedule” and “chitchat” will lead to different storylines.

混淆矩阵显示了模型进行正确分类的频率。 例如,在这里我们看到“ request_create_event”意图被错误地分类为“ ask_schedule”,“ chitchat”“ inform” 。 可以将其归类为“信息”,因为这会导致相同的响应; 但是, “提问时间”“讨论时间”将导致不同的故事情节。

DIETClassifier报告 (DIETClassifier report)

Image for post

In the beginning stage of our model, the f1-score of location and summary are relatively low, 60% and 39% respectively. Though after we provided over 150 samples for each of them, the location f1-score reached 74%.

在模型的初始阶段,位置和摘要的f1得分相对较低,分别为60%和39%。 尽管我们为每个样本提供了150多个样本后,位置f1得分却达到了74%。

However, the summary f-1 score can reach 60% only. We tried adding more training data but we slowly realized that the ways of titling an event are too vast so it’s hard to detect a pattern. Therefore, the results for the summary were not ideal.

但是,摘要f-1分数只能达到60%。 我们尝试添加更多的训练数据,但我们逐渐意识到,为事件添加标题的方式太多了,因此很难检测到模式。 因此,总结的结果并不理想。

结论 (Conclusion)

As people are always looking for ways to incorporate fun into boring tasks, we created CLERKbot to bring convenience in an efficient way but also a pleasure to talk to. We target those who prefer to text their assistant rather than saying commands out loud where everyone around you can hear.

由于人们一直在寻找将乐趣融入无聊的任务的方法,因此我们创建了CLERKbot,以高效的方式带来便利,但同时也带来了交谈的乐趣。 我们针对的是那些喜欢给助手发短信而不是大声说出周围所有人都能听到的命令的人。

As for future improvement, we plan on working on a few things: 1. We plan to deploy on more popular chat channels such as WhatsApp and Facebook Messenger. 2. Improve the flow of the conversation and response accuracy. 3. Allow users to connect to their own calendars. 4. Refine the functions of Clerkbot so that it can learn the user’s preferences and habits.

至于未来的改进,我们计划进行一些工作:1.我们计划在诸如WhatsApp和Facebook Messenger的更流行的聊天频道上进行部署。 2.提高对话流程和响应准确性。 3.允许用户连接到自己的日历。 4.完善Clerkbot的功能,以便它可以学习用户的喜好和习惯。

Due to the time constraint and the fact that this is our first attempt at creating a chatbot, we are fully aware that this chatbot is far from perfect and the room for improvement is endless. Please feel free to point out any mistakes. Any suggestions are welcome!

由于时间限制,而且这是我们首次创建聊天机器人,因此我们完全意识到,此聊天机器人远非完美,改进的空间无穷无尽。 请随时指出任何错误。 欢迎任何建议!

[1]https://www.businessinsider.com/chatbot-market-stats-trends

[1] https://www.businessinsider.com/chatbot-market-stats-trends

[2]https://rasa.com/docs/

[2] https://rasa.com/docs/

[3]http://ghostcode.in/2018/12/31/understanding-and-leveraging-machine-learning-in-conversational-ai/

[3] http://ghostcode.in/2018/12/31/understanding-and-leveraging-machine-learning-in-conversational-ai/

[4]http://bl.ocks.org/koaning/raw/f40ca790612a03067caca2bde81e7aaf/

[4] http://bl.ocks.org/koaning/raw/f40ca790612a03067caca2bde81e7aaf/

[5]https://medium.com/rasa-blog/write-tests-how-to-make-automated-testing-part-of-your-rasa-dev-workflow-29bd8fbe7b6f

[5] https://medium.com/rasa-blog/write-tests-how-to-make-automated-testing-part-of-your-rasa-dev-workflow-29bd8fbe7b6f

翻译自: https://medium.com/@xccproject12/capstone-project-clerkbot-a-virtual-assistant-chatbot-d7653f0233ae

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值