教程:确定常见意向和实体Tutorial: Identify common intents and entities

在本教程中,我们将预生成的意向和实体添加到人力资源教程应用,以便快速了解意向预测和数据提取。In this tutorial, add prebuilt intents and entities to a Human Resources tutorial app to quickly gain intent prediction and data extraction. 不需要使用预生成的实体标记任何话语,因为会自动检测实体。You do not need to mark any utterances with prebuilt entities because the entity is detected automatically.

预生成的模型(域、意向和实体)可帮助你快速生成模型。Prebuilt models (domains, intents, and entities) help you build your model quickly.

本教程介绍如何执行下列操作:In this tutorial, you learn how to:

  • 创建新应用Create new app
  • 添加预生成意向Add prebuilt intents
  • 添加预生成的实体Add prebuilt entities
  • 定型Train
  • 发布Publish
  • 从终结点获取意向和实体Get intents and entities from endpoint

在本文中,可以使用免费 LUIS 帐户来创作 LUIS 应用程序。For this article, you can use the free LUIS account in order to author your LUIS application.

创建新应用Create a new app

  1. 使用 URL https://luis.azure.cn 登录到 LUIS 门户。Sign in to the LUIS portal with the URL of https://luis.azure.cn.

  2. 选择“创建新应用”。Select Create new app.

    语言理解 (LUIS) 我的应用页的屏幕截图Screenshot of Language Understanding (LUIS) My Apps page

  3. 在弹出的对话框中输入名称 HumanResources,保留默认的区域性“英语”。In the pop-up dialog, enter the name HumanResources and keep the default culture, English. 将说明保留为空。Leave the description empty.

    创建 LUIS 新 HumanResources 应用

  4. 选择“完成” 。Select Done. 接下来,应用会显示具有 None 意向的“意向”页。Next, the app shows the Intents page with the None Intent.

添加预生成的意向以帮助获取常见用户意向Add prebuilt intents to help with common user intentions

LUIS 提供几个预生成意向,以便提供常见用户意向。LUIS provides several prebuilt intents to help with common user intentions.

  1. LUIS 的“生成”部分包含你的人力资源应用。Make sure your Human Resources app is in the Build section of LUIS. 在右上方的菜单栏中选择“生成”可切换到此部分。You can change to this section by selecting Build on the top, right menu bar.

  2. 选择“添加预生成域意向”。Select Add prebuilt domain intent.

  3. 搜索 UtilitiesSearch for Utilities.

    “预生成意向”对话框的屏幕截图,其中的搜索框中包含“实用工具”Screenshot of prebuilt intents dialog with Utilities in the search box

  4. 选择以下意向,然后选择“完成”:Select the following intents and select Done:

    • Utilities.CancelUtilities.Cancel

    • Utilities.ConfirmUtilities.Confirm

    • Utilities.HelpUtilities.Help

    • Utilities.StartOverUtilities.StartOver

    • Utilities.StopUtilities.Stop

      这些意向有助于确定用户在聊天中所处的位置及其需求。These intents are helpful to determine where, in the conversation, the user is and what they are asking to do.

添加预生成的实体以帮助提取常见数据类型Add prebuilt entities to help with common data type extraction

LUIS 为常见数据提取提供多个预生成的实体。LUIS provides several prebuilt entities for common data extraction.

  1. 在左侧导航菜单中选择“实体”。Select Entities from the left navigation menu.

  2. 选择“添加预生成的实体”按钮。Select Add prebuilt entity button.

  3. 从预生成的实体列表中选择以下实体,然后选择“完成”:Select the following entities from the list of prebuilt entities then select Done:

    • PersonNamePersonName

    • GeographyV2GeographyV2

      在“预生成的实体”对话框中选择的数字的屏幕截图

      这些实体可帮助你在客户端应用程序中添加名称和位置识别。These entities will help you add name and place recognition to your client application.

将话语示例添加到 None 意向Add example utterances to the None intent

客户端应用程序需要知道某个话语是否对应用程序没有意义或不合适。The client application needs to know if an utterance is not meaningful or appropriate for the application. 在创建过程中,“None”意向将添加到每个应用程序,以确定客户端应用程序是否无法回答某个话语。The None intent is added to each application as part of the creation process to determine if an utterance can't be answered by the client application.

如果 LUIS 对于某个话语返回“None”意向,客户端应用程序可以询问用户是否要结束聊天或提供更多指示以继续聊天。If LUIS returns the None intent for an utterance, your client application can ask if the user wants to end the conversation or give more directions for continuing the conversation.

Caution

不要将“None”意向留空。Do not leave the None intent empty.

  1. 在左侧面板中选择“意向”。Select Intents from the left panel.

  2. 选择“None”意向。Select the None intent. 添加用户可能会输入但与人力资源应用无关的 3 个话语:Add three utterances that your user might enter but are not relevant to your Human Resources app:

    示例陈述Example utterances
    Barking dogs are annoyingBarking dogs are annoying
    Order a pizza for meOrder a pizza for me
    Penguins in the oceanPenguins in the ocean

训练应用,以便可以测试对意向所做的更改Train the app so the changes to the intent can be tested

  1. 在 LUIS 网站的右上方,选择“训练”按钮。In the top right side of the LUIS website, select the Train button.

    “训练”按钮

  2. 当网站顶部出现确认成功的绿色状态栏时,表示训练已完成。Training is complete when you see the green status bar at the top of the website confirming success.

    已训练状态栏

发布应用,以便可以从终结点查询已训练的模型Publish the app so the trained model is queryable from the endpoint

若要在聊天机器人或其他客户端应用程序中接收 LUIS 预测,需要将应用发布到终结点。In order to receive a LUIS prediction in a chat bot or other client application, you need to publish the app to the endpoint.

  1. 在右上方的导航栏中选择“发布”。Select Publish in the top right navigation.

    右上方菜单中的“LUIS 发布到终结点”按钮

  2. 选择“生产”槽和“发布”按钮。Select the Production slot and the Publish button.

    LUIS 发布到终结点

  3. 当网站顶部出现确认成功的绿色状态栏时,表示发布已完成。Publishing is complete when you see the green status bar at the top of the website confirming success.

    LUIS 发布到终结点

  4. 选择绿色状态栏中的“终结点”链接,转到“密钥和终结点”页。Select the endpoints link in the green status bar to go to the Keys and endpoints page. 终结点 URL 列在底部。The endpoint URLs are listed at the bottom.

从终结点获取意向和实体预测结果Get intent and entity prediction from endpoint

  1. 在“管理”部分(右上方菜单)的“密钥和终结点”页(左侧菜单)中,选择页面底部的终结点 URL。In the Manage section (top right menu), on the Keys and endpoints page (left menu), select the endpoint URL at the bottom of the page. 此操作会打开另一个浏览器标签页,其地址栏中包含终结点 URL。This action opens another browser tab with the endpoint URL in the address bar.

    终结点 URL 如 https://<region>.api.cognitive.azure.cn/luis/v2.0/apps/<appID>?verbose=true&subscription-key=<YOUR_KEY>&<optional-name-value-pairs>&q=<user-utterance-text> 所示。The endpoint URL looks like https://<region>.api.cognitive.azure.cn/luis/v2.0/apps/<appID>?verbose=true&subscription-key=<YOUR_KEY>&<optional-name-value-pairs>&q=<user-utterance-text>.

  2. 将光标定位到浏览器地址栏中 URL 的末尾,并输入 I want to cancel my trip to Seattle to see Bob SmithGo to the end of the URL in the browser address bar and enter I want to cancel my trip to Seattle to see Bob Smith. 最后一个查询字符串参数为 q,表示陈述查询 (query)。The last query string parameter is q, the utterance query.

    {
      "query": "I want to cancel my trip to Seattle to see Bob Smith",
      "topScoringIntent": {
        "intent": "Utilities.Cancel",
        "score": 0.807676256
      },
      "intents": [
        {
          "intent": "Utilities.Cancel",
          "score": 0.807676256
        },
        {
          "intent": "Utilities.StartOver",
          "score": 0.0487322025
        },
        {
          "intent": "Utilities.Help",
          "score": 0.0208660364
        },
        {
          "intent": "None",
          "score": 0.008789532
        },
        {
          "intent": "Utilities.Stop",
          "score": 0.006929268
        },
        {
          "intent": "Utilities.Confirm",
          "score": 0.00136293867
        }
      ],
      "entities": [
        {
          "entity": "seattle",
          "type": "builtin.geographyV2.city",
          "startIndex": 28,
          "endIndex": 34
        },
        {
          "entity": "bob smith",
          "type": "builtin.personName",
          "startIndex": 43,
          "endIndex": 51
        }
      ]
    }
    

    结果中预测了置信度为 80% 的 Utilities.Cancel 意向,并提取了城市和人名数据。The result predicted the Utilities.Cancel intent with 80% confidence and extracted the city and person name data.

清理资源Clean up resources

不再需要 LUIS 应用时,请将其删除。When no longer needed, delete the LUIS app. 为此,请在左上角的菜单中选择“我的应用”。To do so, select My apps from the top left menu. 在应用列表中选择应用名称右侧的省略号 (...),然后选择“删除”。Select the ellipsis (...) to the right of the app name in the app list, select Delete. 在弹出的“删除应用?”对话框中,选择“确定”。On the pop-up dialog Delete app?, select Ok.

详细了解预生成的模型:Learn more about prebuilt models:

  • 预生成的域:这是一些常见的域,可以减少 LUIS 应用创作的总体工作量Prebuilt domains: these are common domains that reduce overall LUIS app authoring
  • 预生成的意向:这是常见域的各个意向。Prebuilt intents: these are the individual intents of the common domains. 可以单独添加意向,而无需添加整个域。You can add intents individually instead of adding the entire domain.
  • 预生成的实体:这是可用于大多数 LUIS 应用的常见数据类型。Prebuilt entities: these are common data types useful to most LUIS apps.

详细了解如何使用 LUIS 应用:Learn more about working with your LUIS app:

后续步骤Next steps

通过添加预生成的意向和实体,客户端应用程序可以确定常见的用户意向并提取常见的数据类型。By adding prebuilt intents and entities, the client application can determine common user intentions and extract common datatypes.