使用rasa-nlu理解_如何用rasa创建一个开源的nlu api

使用rasa-nlu理解

介绍(Introduction)

There is much hype regarding chatbots and conversational AI in general.

一般而言,有关聊天机器人和对话式AI的炒作很多。

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第1张图片
Rasa Rasa NLU API called from Postman NLU API

Technologies are often compared to each other in order to find the best fit for an organization or task.

通常将技术进行相互比较,以找到最适合组织或任务的技术。

The problem is that with all the technology available, the initial decisions are easy to make.

问题在于,利用所有可用的技术,很容易做出最初的决定。

The subsequent design & architecture decisions are harder, once the system is established.

一旦建立了系统,后续的设计和架构决策将变得更加困难。

In this article I would like to focus on using an opensource option which will serve well for a seed-project.

在本文中,我将重点介绍使用开源选项,该选项非常适合种子项目。

But more then that, a framework which can evolve and support a fully fledged enterprise solution.

但是,更重要的是,可以发展并支持成熟的企业解决方案的框架。

Starting with the NLU API will lay a good foundation to grow the solution into a fully fledged conversational interface.

从NLU API开始,将为将解决方案发展为成熟的对话界面奠定良好的基础。

NLU和核心 (NLU & Core)

There are a few chatbot platforms which have a clear separation between the NLU portion and the dialog management and integration portions. This allows for the development of a stand-alone NLU API.

有些聊天机器人平台在NLU部分与对话框管理和集成部分之间有明确的分隔。 这允许开发独立的NLU API。

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第2张图片
Rasa chatbot architecture with NLU portion marked. Rasa chatbot架构。

The Rasa architecture gives you the opportunity to have a NLU API which can also be used for natural language understanding tasks not related to live conversations. This includes conversations archived on email, live agent conversations etc.

Rasa架构使您有机会拥有NLU API,该API也可以用于与实时对话无关的自然语言理解任务。 这包括通过电子邮件存档的对话,实时座席对话等。

NLU数据格式 (NLU Data Format)

There are exceptionally good videos by Rasa on how to install in different environments.

Rasa提供了关于如何在不同环境中安装的非常出色的视频。

Here you can find a video by Rachel for Widows 10 installation.

在这里,您可以找到Rachel制作的Widows 10安装视频。

Secondly, to get started, Rasa has a series of Masterclass videos which is a time efficient way of getting up to speed with the whole Rasa stack.

其次,Rasa拥有一系列Masterclass视频,这是一种快速掌握整个Rasa堆栈的省时方法。

But, back to creating a NLU API…

但是,回到创建NLU API ...

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第3张图片
The NLU.md file within the Rasa file structure Rasa文件结构中的NLU.md文件

The examples below used for NLU training are based on a GitHub project.

以下用于NLU培训的示例基于GitHub项目。

The NLU training file has the entities annotated within the intents. Hence we see the healthy trend of intents and entities merging.

NLU培训文件在意图内标注了实体。 因此,我们看到了意图和实体合并的健康趋势。

Intents and entities are in a text file in markdown format.

意向和实体位于降价格式的文本文件中。

意图和实体 (Intents & Entities)

简单的例子(Simple Examples)

The simplest example is just having an intent defined with some examples sans any entities. Below is the check_balance intent with a few examples.

最简单的示例只是在没有任何实体的情况下用一些示例定义了一个意图。 以下是一些示例的check_balance意图。

## intent:check_balance
- How much money is on my account?
- what's my balance?
- what's my current balance?
- What's left on that account?
- How much do I have on that account?

Let’s add an entity of type account_type with the example credit card.

让我们使用示例信用卡添加一个account_type类型的实体

- what's my [credit](account_type) account balance?

The result:

结果:

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第4张图片
check_balance and the entity is check_balance ,实体是 account_type of credit的 credit. account_type

常用表达 (Regular Expressions)

This is how regular expressions are defined within the nlu.md file…

这就是在nlu.md文件中定义正则表达式的方式…

## regex:accountNumber
- [0-9]{9}## intent:inform_accountNumber
- my account number is [123454434](accountNumber)
- my account number is [334564343](accountNumber)
- my account number is [940564343](accountNumber)

And the output…

和输出...

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第5张图片
The entity of accountNumber is extracted. 标记了 accountNumber实体

规范化数据 (Normalize Data)

Data captured in the entity can be normalize. The entity related to to credit cards accounts is captured under the entity of account_type, but always with the value of credit.

实体中捕获的数据可以标准化。 与信用卡帐户有关的实体是在account_type实体下捕获的但始终带有credit的值

{"text":"Pay off my [credit card]{"entity": "account_type", "value": "credit"}, please"}

And the result…

结果是……

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第6张图片
creditcard accout is normalized to 信用卡账户的输入被标准化为 credit in the account_type实体中的 account_type entity. credit

Here you see the rather skewed input of creditcard accout is normalized to the value of credit in the account_type entity.

在这里,您可以看到信用卡accout的偏斜输入已标准化为account_type实体中的credit值。

楷模 (Models)

Each time you train your model, a new model file is created in the models folder. This allows you to change between models for your API, roll back to previous versions etc.

每次训练模型时,都会在models文件夹中创建一个新的模型文件。 这使您可以在API的模型之间进行切换,回滚到以前的版本等。

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第7张图片
Different trained models can be invoked when running the API 运行API时可以调用不同的训练模型

创建API(Creating The API)

With a single command the API is launched on port 5005. But first, make sure you have activated your anaconda virtual environment with:

使用单个命令即可在端口5005上启动API。 但是首先,请确保已使用以下命令激活了anaconda虚拟环境:

conda activate rasa2

My virtual environment is called rasa2.

我的虚拟环境称为rasa2。

Run the API:

运行API:

rasa run --enable-api -m models/nlu-20200917-225530.tar.gz

You can access the API on the URL

您可以通过URL访问API

http://localhost:5005/model/parse

Interact with your API via a client like Postman.

通过Postman之类的客户端与您的API进行交互。

使用rasa-nlu理解_如何用rasa创建一个开源的nlu api_第8张图片
Sending a JSON query string to the Rasa API 将JSON查询字符串发送到Rasa API

结论 (Conclusion)

There are other features also available when defining the training data. The features mentioned here are the primary ones, IMO. In a following article I want to look at the structures available to entities.

定义训练数据时,还有其他功能可用。 此处提到的功能是IMO的主要功能。 在下一篇文章中,我想看看实体可用的结构。

在这里阅读更多 (Read More Here)

翻译自: https://medium.com/@CobusGreyling/how-to-create-an-opensource-nlu-api-with-rasa-856598973da7

使用rasa-nlu理解

你可能感兴趣的:(java,python)