教程:对相关的数据进行分组和提取Tutorial: Group and extract related data

在本教程中,添加复合实体来将提取的各种类型的数据捆绑到单个内含实体中。In this tutorial, add a composite entity to bundle extracted data of various types into a single containing entity. 通过捆绑数据,客户端应用程序可以轻松提取各种数据类型的相关数据。By bundling the data, the client application can easily extract related data in different data types.

复合实体的目的是将相关实体分组为父类别实体。The purpose of the composite entity is to group related entities into a parent category entity. 在创建复合实体之前,这些现有信息都是单独的实体。The information exists as separate entities before a composite is created.

复合实体非常适合此类数据,因为此类数据:The composite entity is a good fit for this type of data because the data:

  • 彼此相关。Are related to each other.
  • 使用各种实体类型。Use a variety of entity types.
  • 需要由客户端应用作为一个信息单元进行分组和处理。Need to be grouped and processed by client app as a unit of information.

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

  • 导入示例应用Import example app
  • 创建意向Create intent
  • 添加复合实体Add composite entity
  • 定型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.

导入示例应用Import example app

  1. 从列表实体教程中下载并保存应用 JSON 文件Download and save the app JSON file from the List entity tutorial.

  2. 使用 LUIS 门户将 JSON 导入到新应用。Import the JSON into a new app using the LUIS portal.

  3. 在“管理”部分的“版本”选项卡上,克隆版本并将其命名为 compositeFrom the Manage section, on the Versions tab, clone the version, and name it composite. 克隆非常适合用于演练各种 LUIS 功能,且不会影响原始版本。Cloning is a great way to play with various LUIS features without affecting the original version. 由于版本名称用作 URL 路由的一部分,因此该名称不能包含任何在 URL 中无效的字符。Because the version name is used as part of the URL route, the name can't contain any characters that are not valid in a URL.

复合实体Composite entity

在此应用中,部门名称是在 Department 列表实体中定义的并且包括同义词。In this app, the department name is defined in the Department list entity and includes synonyms.

TransferEmployeeToDepartment 意向具有请求将员工移动到新部门的示例话语。The TransferEmployeeToDepartment intent has example utterances to request an employee be moved to a new department.

此意向的示例话语包括:Example utterances for this intent include:

示例陈述Example utterances
将 John W. Smith 转到会计部门move John W. Smith to the accounting department
将 Jill Jones 转到研发部门transfer Jill Jones from to R&D

移动请求应当包括部门名称和员工姓名。The move request should include the department name, and the employee name.

添加 PersonName 预构建实体以帮助提取常见数据类型Add the PersonName prebuilt entity to help with common data type extraction

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

  1. 从顶部导航栏中选择“生成”,然后从左侧导航菜单中选择“实体”。Select Build from the top navigation, then select Entities from the left navigation menu.

  2. 选择“管理预生成的实体”按钮。Select Manage prebuilt entity button.

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

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

    此实体可以帮助你向客户端应用程序中添加名称识别。This entity helps you add name recognition to your client application.

基于示例话语创建复合实体Create composite entity from example utterances

  1. 从左侧导航栏中选择“意向”。Select Intents from the left navigation.

  2. 从意向列表中选择“TransferEmployeeToDepartment”。Select TransferEmployeeToDepartment from the intents list.

  3. 在话语 place John Jackson in engineering 中,选择 personName 实体 John Jackson,然后从以下话语的弹出菜单列表中选择“包装进复合实体”。In the utterance place John Jackson in engineering, select the personName entity, John Jackson, then select Wrap in composite entity in the pop-up menu list for the following utterance.

    在下拉对话框中选择“包装复合实体”的屏幕截图

  4. 然后立即选择最后一个实体,话语中的 engineeringThen immediately select the last entity, engineering in the utterance. 在所选字词下面绘制的绿色条指示复合实体。A green bar is drawn under the selected words indicating a composite entity. 在弹出菜单中,输入复合名称 TransferEmployeeInfo,然后选择 Enter。In the pop-up menu, enter the composite name TransferEmployeeInfo then select enter.

    在下拉对话框中输入复合名称的屏幕截图

  5. 在“想要创建哪种类型的实体?”中,所有必需字段都在列表中:personNameDepartmentIn What type of entity do you want to create?, all the fields required are in the list: personName and Department. 选择“完成” 。Select Done. 请注意,预构建实体 personName 已添加到复合实体中。Notice that the prebuilt entity, personName, was added to the composite entity. 如果可能有预构建实体出现在复合实体的开始标记和结束标记之间,则复合实体必须包含那些预构建实体。If you could have a prebuilt entity appear between the beginning and ending tokens of a composite entity, the composite entity must contain those prebuilt entities. 如果未包括预构建实体,则不能正确预测复合实体,但可以正确预测每个个体元素。If the prebuilt entities are not included, the composite entity is not correctly predicted but each individual element is.

    在下拉对话框中输入复合名称的屏幕截图

使用复合实体标记示例话语Label example utterances with composite entity

  1. 在每个示例话语中,选择应在复合中的最左侧实体。In each example utterance, select the left-most entity that should be in the composite. 然后选择“在复合实体中包装”.Then select Wrap in composite entity.

  2. 选择复合实体中的最后一个单词,然后从弹出菜单中选择“TransferEmployeeInfo”。Select the last word in the composite entity then select TransferEmployeeInfo from the pop-up menu.

  3. 验证意向中的所有话语都已使用复合实体进行标记。Verify all utterances in the intent are labeled with the composite entity.

训练应用,以便可以测试对意向所做的更改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 的末尾,并输入 Move Jill Jones to DevOpsGo to the end of the URL in the address and enter Move Jill Jones to DevOps. 最后一个查询字符串参数为 q,表示话语查询。The last querystring parameter is q, the utterance query.

    由于此测试是为了验证是否正确提取复合,因此测试可以包括现有的示例话语或新话语。Since this test is to verify the composite is extracted correctly, a test can either include an existing sample utterance or a new utterance. 一个有效的测试是在复合实体中包含所有子实体。A good test is to include all the child entities in the composite entity.

    {
      "query": "Move Jill Jones to DevOps",
      "topScoringIntent": {
        "intent": "TransferEmployeeToDepartment",
        "score": 0.9882747
      },
      "intents": [
        {
          "intent": "TransferEmployeeToDepartment",
          "score": 0.9882747
        },
        {
          "intent": "None",
          "score": 0.00925369747
        }
      ],
      "entities": [
        {
          "entity": "jill jones",
          "type": "builtin.personName",
          "startIndex": 5,
          "endIndex": 14
        },
        {
          "entity": "devops",
          "type": "Department",
          "startIndex": 19,
          "endIndex": 24,
          "resolution": {
            "values": [
              "Development Operations"
            ]
          }
        },
        {
          "entity": "jill jones to devops",
          "type": "TransferEmployeeInfo",
          "startIndex": 5,
          "endIndex": 24,
          "score": 0.9607566
        }
      ],
      "compositeEntities": [
        {
          "parentType": "TransferEmployeeInfo",
          "value": "jill jones to devops",
          "children": [
            {
              "type": "builtin.personName",
              "value": "jill jones"
            },
            {
              "type": "Department",
              "value": "devops"
            }
          ]
        }
      ]
    }
    

    此话语返回复合实体数组。This utterance returns a composite entities array. 每个实体都有类型和值。Each entity is given a type and value. 若要查找每个子实体的更高精度,请使用复合数组项中的类型和值的组合来查找实体数组中的相应项。To find more precision for each child entity, use the combination of type and value from the composite array item to find the corresponding item in the entities array.

清理资源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.

后续步骤Next steps

本教程创建了一个复合实体来封装现有实体。This tutorial created a composite entity to encapsulate existing entities. 这使得客户端应用程序能够发现一组不同数据类型的相关数据以便继续进行对话。This allows the client application to find a group of related data in different datatypes to continue the conversation. 此人力资源应用的客户端应用程序可能会询问需要在哪一天的什么时间开始和结束搬迁。A client application for this Human Resources app could ask what day and time the move needs to begin and end. 它还可能会询问有关本次搬迁的其他后勤信息,例如实际电话。It could also ask about other logistics of the move such as a physical phone.