api. feel.ai

tech2023-05-24  97

api. feel.ai

If you’re keen to learn more on AI, check out our screencast Microsoft Cognitive Services and the Text Analytics API, for AI sentiment in your bot.

如果您想了解有关AI的更多信息,请查看我们的截屏视频Microsoft Cognitive Services和Text Analytics API ,了解您机器人中的AI情绪。

Here at SitePoint, we’ve looked at the basics of setting up your own personal assistant using Api.ai and delved further into intents and context. In this article, you’ll be going one step further in the process, teaching your assistants completely custom concepts using Api.ai entities.

在SitePoint上,我们研究了使用Api.ai设置自己的个人助理的基础知识,并进一步研究了意图和上下文 。 在本文中,您将进一步前进,使用Api.ai实体教您的助手完全自定义的概念。

Note: this article was updated in 2017 to reflect recent changes to Api.ai.

注意:本文于2017年更新,以反映对Api.ai的最新更改。

使用Api.ai构建AI助手 (Building an AI assistant with Api.ai)

This post is one of a series of articles aimed to help you get a simple personal assistant running with Api.ai:

这篇文章是旨在帮助您获得一个使用Api.ai运行的简单个人助手的系列文章之一:

How to Build Your Own AI Assistant Using Api.ai

如何使用Api.ai构建自己的AI助手

Customizing Your Api.ai Assistant with Intent and Context

使用意图和上下文自定义Api.ai助手

Empowering Your Api.ai Assistant with Entities (this one!)

使用实体增强Api.ai助手的功能(这一点!)

How to Connect Your Api.ai Assistant to the IoT

如何将Api.ai助手连接到物联网

什么是实体? (What is an Entity?)

An entity is a concept you want your personal assistant to understand when it’s mentioned by the user in conversation. Each entity has a range of values and properties that contain the terms the assistant will need to understand to respond to this concept.

实体是一个概念,您希望您的私人助理在对话中被用户提及时理解它。 每个实体都有一系列值和属性,这些值和属性包含助手为响应此概念而需要理解的术语。

There are three types of entities in Api.ai:

Api.ai中有三种类型的实体:

System: Entity types defined by Api.ai such as date, color, email, number and so on, which Api.ai already understands. You can find a full list of these entities in Api.ai’s documentation on System Entities.

系统:由Api.ai定义的实体类型,例如日期,颜色,电子邮件,数字等,而Api.ai已经知道。 您可以在Api.ai有关系统实体的文档中找到这些实体的完整列表。

Developer: Entities which we create for our individual needs. These are what you’ll be focused on in this article.

开发人员:我们为满足个人需求而创建的实体。 这些就是您将在本文中重点介绍的内容。

User: These are created for individual users while they use the assistant and can be generated by the Api.ai API to be used within a single session. I won’t be covering these in this article, but if there’s enough reader interest, I might explore this in future!

用户:它们是在使用助手时为单个用户创建的,可以由Api.ai API生成以在单个会话中使用。 我不会在本文中介绍这些内容,但是如果读者有足够的兴趣,我将来可能会对此进行探讨!

Api.ai’s small talk is an example of a range of statements with no entities whatsoever. They’re listening for statements whose meaning doesn’t change based on keywords in the sentence. When someone asks “How are you?”, there’s no variation Api.ai understands. However, if we adjusted that to “How is Jimmy Olsen?”, we’re moving this sentence into the realm of entities. “Jimmy Olsen” would be an entity that represents a person. Teaching your agent that entity would mean if someone asks “How is Bruce Wayne?”, your agent would know that they mean to ask how a person is, and that they want to know about Bruce Wayne specifically.

Api.ai的闲聊是一系列没有实体的语句的示例。 他们正在听语句的含义不会根据句子中的关键字而改变的语句。 当有人问“你好吗?”时,Api.ai不会理解。 但是,如果我们将其调整为“吉米·奥尔森(Jimmy Olsen)怎么样?”,我们会将这句话移到实体领域。 “吉米·奥尔森”将是代表一个人的实体。 教您的代理人这个实体意味着,如果有人问“布鲁斯·韦恩(Bruce Wayne)怎么样?”,您的代理人就会知道他们是要问一个人如何,并且他们想特别了解布鲁斯·韦恩。

As another example, an entity of “superhero” is not something Api.ai knows about. You could train your assistant to understand a range of superheroes and their various names — “Superman”, “Batman”, “The Flash”, “Green Lantern”, “Wonder Woman”, “Santa” and so on. It could then understand that these are specific concepts you want to trigger actions with, such as contacting these heroes when villains strike via an API when you say things like “We need The Flash!”.

再举一个例子,“超级英雄”的实体不是Api.ai所了解的。 您可以训练您的助手了解一系列超级英雄及其各种名称-“超人”,“蝙蝠侠”,“闪光灯”,“绿灯侠”,“神奇女侠”,“圣诞老人”等等。 然后,他们可以理解,这些是您要触发动作的特定概念,例如,当您说出“我们需要Flash!”之类的消息时,当反派通过API袭击时,联系这些英雄。

You can also teach your assistant synonyms for each of these, so that alongside names like “Superman”, it would also understand that Superman is also known as “Kal-El”, “The Man of Steel”, “Supes” and “Smallville”. If you say a different name in the spur of the moment (or someone else tries to request help from your assistant and they call them something else), help from your hero will still come!

您还可以教您每种助手的同义词,以便与“超人”之类的名字一起使用,它也可以理解超人也被称为“ Kal-El”,“钢铁侠”,“ Supes”和“ Smallville” ”。 如果您一时冲动说一个不同的名字(或其他人试图向您的助手寻求帮助,而他们称他们为别的东西),您的英雄仍然会提供帮助!

While I’d have loved to keep that entity example going for the whole article, I thought it might be best to focus on a more realistic example in the demo itself! In your demo, you’ll teach your assistant to understand one important metric I get from my Jawbone Up — sleep. The end goal is for your assistant to understand statements like “How many hours of sleep did I get last night?” and “How much deep sleep did I get last night?”

尽管我很乐意在整个文章中继续使用该实体示例,但我认为最好还是在演示本身中关注一个更现实的示例! 在演示中,您将教您的助手了解我从Jawbone Up中获得的一项重要指标-睡眠。 最终目标是让您的助手理解诸如“昨晚我睡了几个小时?”之类的陈述。 和“昨晚我睡了多少次?”

In this article, I’ll look at the first step of this process — setting up the entities required for your assistant to understand these statements. In the next article in this series, I’ll look at connecting up your assistant web app to third party APIs to give it the information it needs to respond.

在本文中,我将介绍此过程的第一步-设置助手理解这些语句所需的实体。 在本系列的下一篇文章中,我将介绍如何将您的助手Web应用程序连接到第三方API,以向其提供需要响应的信息。

创建一个新实体 (Creating a New Entity)

To create a new entity, open the Api.ai console and go to the “Entities” page using the menu on the left. Then create an entity by clicking either “Create Entity”, the plus symbol on the “Entities” menu item or the “Create the first one” link which appears for those who have yet to create an entity:

要创建新实体,请打开Api.ai控制台,然后使用左侧菜单进入“实体”页面。 然后,通过单击“创建实体”,“实体”菜单项上的加号或“创建第一个”链接(针对尚未创建实体的人员出现)来创建实体:

In the page that appears, enter in your entity name. A common convention is to write this in lowercase with words separated by dashes. Call your new entity “sleep”. Leave “Define synonyms” checked and enter one term in the section below it — “sleep”. You can also add in synonyms, so cover a few more options by entering in “rest”, “doze” and “shut-eye” next to “sleep”. You add each synonym by pressing either the Enter key, Tab key or semicolon (;) key. When done, click Save:

在出现的页面中,输入您的实体名称。 一个常见的约定是用小写字母写这些,并用短划线隔开。 将您的新实体称为“睡眠”。 选中“定义同义词”,然后在其下面的部分中输入一个术语“睡眠”。 您还可以添加同义词,因此通过在“睡眠”旁边输入“休息”,“打ze”和“闭眼”来涵盖更多选项。 您可以通过按Enter键,Tab键或分号(;)键来添加每个同义词。 完成后,单击保存:

If you return to the “Entities” page, your new entity is shown with the name you’ll use to access it — @sleep.

如果返回“实体”页面,则会显示新实体,并带有用于访问它的名称- @sleep 。

在意图中使用实体 (Using Your Entity in an Intent)

You now need to create a new intent that will train your personal assistant to recognize the sentences that trigger your sleep-related requests. Start by heading to the “Intents” page and creating a new intent as you’ve done a few times by this point in the series.

现在,您需要创建一个新的意图,该意图将训练您的个人助理识别触发您的睡眠相关请求的句子。 首先转到“意图”页面,然后按照本系列教程中的几次操作,创建一个新的意图。

On your new intent page, include your entity within “User Says” statements. In the case of your sleep entity, enter in a statement that includes a generic word to represent an example of your entity. In this case, type in “How many hours of sleep did I get last night?” Your entity in this case is “sleep”.

在新的意图页面上,将您的实体包含在“用户说”语句中。 对于睡眠实体,请输入包含通用词的语句,以代表您的实体示例。 在这种情况下,键入“昨晚我睡了几个小时?” 在这种情况下,您的实体是“睡眠”的。

To teach Api.ai that “sleep” is your entity, highlight that word and a dropdown will appear. One of the options should be your new sleep entity — @sleep. Choose that and the word will be highlighted to represent that it can potentially change in statements spoken to your agent.

要让Api.ai知道“睡眠”是您的实体,请突出显示该单词,然后会出现一个下拉列表。 选项之一应该是您的新睡眠实体- @sleep 。 选择该单词,该单词将突出显示以表示它可能会改变与您的业务代表说的话。

You also have a field for the action name. This is the name that will be passed to your web app to show what Api.ai thinks the user wants to do. Name your action “sleepHours”.

您也有一个动作名称字段。 这是将传递给您的Web应用程序的名称,以显示Api.ai认为用户想要做什么。 将您的操作命名为“ sleepHours”。

Upon including your sleep entity, it should appear as parameters for the intent like so:

包含睡眠实体后,它应作为意图的参数显示,如下所示:

You can then add a variety of different ways to say the same sort of statement, just as you did in the previous article on creating intents. However, this time, include the word “sleep” within them whenever you’re referring to a type of sleep and Api.ai will automatically highlight them for you:

然后,您可以添加各种不同的方式来表达相同类型的语句,就像上一篇有关创建意图的文章中所做的那样。 但是,这一次,每当您提到某种睡眠时,都在其中包含“睡眠”一词,Api.ai会自动为您突出显示它们:

It might also find other pre-built entities that Api.ai understands, such as time period. In the screenshot above, Api.ai picked up that “Last night” was a time period and highlighted that too. This means that Api.ai should still understand the sentence “Last night’s sleep hours please” if it instead hears “Last week’s sleep hours please.”

它还可能会找到Api.ai可以理解的其他预建实体,例如时间段。 在上面的屏幕截图中,Api.ai注意到“昨晚”是一个时间段,并对其进行了突出显示。 这意味着,如果Api.ai听到“请上一周的睡眠时间”,它仍然应该理解“请您昨晚的睡眠时间”一句。

To finish up your intent, set up some responses to your intent about sleep hours. The assistant itself in Api.ai can’t look up the stats, so you’ll need to use your own web app for that. However, it’s nice for the assistant to at least keep up the illusion that it’s doing all the work. To do this, your responses say things like “I’ll retrieve your sleep stats for you now, one moment!” and “Looking up your sleep hours now.” It also gives us a bit of time for our web app to retrieve that data.

要完成您的意图,请针对您的睡眠时间设定一些意图。 Api.ai中的助手本身无法查看统计信息,因此您需要使用自己的网络应用程序。 但是,对于助手而言,至少要保持其正在完成所有工作的幻想是很好的。 为此,您的回复会说“我现在会为您检索您的睡眠状态,一会儿!”之类的信息。 和“现在检查您的睡眠时间。” 这也使我们的Web应用程序有一些时间来检索该数据。

Once you have your responses defined, click Save!

定义响应后,单击“保存”!

If you test your new intent by saying “How many hours of rest did I get last night?”, your assistant now returns a correct speech response and the action of “sleepHours” ready for your web app to respond. This is exactly what you want!

如果您通过说“昨晚我休息了几个小时?”来测试您的新意图,您的助手现在将返回正确的语音响应,并准备好“ sleepHours”操作以供您的Web应用程序响应。 这正是您想要的!

扩大实体 (Expanding Your Entity)

You have a working entity that lets your assistant understand when you want to look up how many hours of rest you’ve had, but the entity is still quite simple. Sleep is just sleep. Rest. Shut-eye. In reality, there are specific types of sleep that a user might ask about. What if the user asks “How many hours of REM sleep did I get last night?” “REM sleep”, “Deep sleep” and “Light sleep” are all different types of “sleep” that should be understood by your sleep entity. You’ll add those in.

您有一个工作实体,可以让您的助手了解何时要查询自己有多少小时的休息时间,但是该实体仍然非常简单。 睡眠就是睡眠。 休息。 闭上眼睛 实际上,用户可能会询问特定的睡眠类型。 如果用户问“昨晚我获得了REM睡眠几个小时?”,该怎么办? “ REM睡眠”,“深度睡眠”和“轻度睡眠”是睡眠实体应理解的所有不同类型的“睡眠”。 您将添加其中。

Return to the Entities page and open the @sleep entity. Underneath “sleep” and its synonyms of “sleep, rest, doze, shut-eye”, add new types of sleep such as “REM sleep” (also just called “REM”), “deep sleep” and “light sleep”. Include these as new rows, as they have distinct meanings and aren’t exactly the same as the generic term of “sleep”. To add a new row, click “Add a row”. Once you’ve added your new forms of sleep, click “Save” to save the changes:

返回到“实体”页面并打开@sleep实体。 在“睡眠”及其同义词“睡眠,休息,打ze,闭眼”下,添加了新的睡眠类型,例如“ REM睡眠”(也称为“ REM”),“深度睡眠”和“轻度睡眠”。 将它们作为新行包括在内,因为它们具有不同的含义,并且与“睡眠”的通用术语不完全相同。 要添加新行,请单击“添加行”。 添加新的睡眠方式后,请点击“保存”以保存更改:

If you now try a more specific sentence, like “How many hours of REM did I get last night?”, your assistant still recognizes that the request is one of “sleepHours”, but also contains the sleep parameter of “REM sleep” to tell your web app what particular sleep the user is asking about:

如果您现在尝试使用更具体的句子,例如“昨晚我获得了REM几个小时?”,您的助手仍会识别该请求是“ sleepHours”之一,而且还包含“ REM sleep”的睡眠参数告诉您的Web应用程序用户在问什么特别的睡眠:

If you click the “Show JSON” button underneath, you’ll see where the power of this truly comes into play. All of this information is returned to your web app in an easy-to-interpret JSON file that looks like so:

如果单击下面的“显示JSON”按钮,您将看到其真正发挥作用的地方。 所有这些信息都以易于理解的JSON文件形式返回到您的Web应用程序,如下所示:

{ "id": "7438", "timestamp": "2017-02-06T01:19:45.271Z", "result": { "source": "agent", "resolvedQuery": "How many hours of REM did I get last night?", "action": "sleepHours", "actionIncomplete": false, "parameters": { "sleep": "REM sleep" }, "contexts": [], "metadata": { "intentId": "25d04df", "intentName": "How many hours of @sleep:sleep did I get last night?" }, "fulfillment": { "speech": "Looking up your sleep hours now." } }, "status": { "code": 200, "errorType": "success" } }

The most important bits of this are the action name that has been requested and the parameters for that action:

其中最重要的位是已请求的操作名称和该操作的参数:

"action": "sleepHours", "parameters": { "sleep": "REM sleep" },

This is what you’ll use in your next article to build up your web app’s response to these queries.

这是您在下一篇文章中将用来构建Web应用程序对这些查询的响应的内容。

结论 (Conclusion)

Incredibly, after three articles looking into Api.ai, you’ve still just scratched the surface of what’s possible with the platform! Entities can contain other entities (both system entities and your own developer entities), you can set up intents that require certain information and prompt the user if they don’t provide it, you can use your previously mentioned entities in a conversation using their $alias … and so on!

令人难以置信的是,在研究了Api.ai的三篇文章之后,您仍然只是摸索了平台可能实现的功能! 实体可以包含其他实体(系统实体和您自己的开发者实体),您可以设置需要某些信息的意图,并在用户不提供信息时提示用户,您可以在会话中使用其前面提到的实体使用其$alias ……等等!

In the final article in the series, you’ll look at adding functionality to the web app that you created in the earlier article on How to Build Your Own AI Assistant Using Api.ai that pulls in Jawbone data to give you real answers to these queries!

在本系列的最后一篇文章中 ,您将了解如何在上一篇文章“ 如何使用Api.ai构建自己的AI助手”中创建的Web应用程序中添加功能,该功能可以获取Jawbone数据,从而为您提供真正的答案查询!

I’ve had feedback from a few readers who have been loving building their own personal assistants. If you’ve been following along, how’s your assistant going? What have you trained them to do? Let me know in the comments below, or get in touch with me on Twitter at @thatpatrickguy. I always love to hear the ideas that emerging tech spurs into developer minds!

我收到了一些喜欢建立自己的私人助理的读者的反馈。 如果您一直在关注,您的助手过得怎么样? 您训练了他们做什么? 在下面的评论中让我知道,或者在Twitter上通过@thatpatrickguy与我联系 。 我一直很乐意听到新兴技术激发开发者思想的想法!

Give your AI the human touch with a sentiment tool. Check out our screencasts on the Microsoft Cognitive Services and the Text Analytics API.

使用情感工具让您的AI具有人性化的感觉。 查看我们有关Microsoft Cognitive Services和Text Analytics API的截屏视频。

翻译自: https://www.sitepoint.com/teaching-our-api-ai-assistant-concepts-via-entities/

api. feel.ai

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)