教程:从话语中获取文本完全匹配的数据Tutorial: Get exact text-matched data from an utterance

本教程介绍如何获取与项的预定义列表匹配的实体数据。In this tutorial, understand how to get entity data that matches a predefined list of items.

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

  • 创建应用Create app
  • 添加意向Add intent
  • 添加列表实体Add list 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.

什么是列表实体?What is a list entity?

列表实体是话语中的字词的文本完全匹配项。A list entity is an exact text match to the words in the utterance.

列表中的每个项可以包含一个同义词列表。Each item on the list can include a list of synonyms. 对于人力资源应用,可以通过多个关键信息来识别某个公司部门,例如官方名称、常用缩略词和计费部门代码。For the human resources app, a company department can be identified by several key pieces of information such as an official name, common acronyms, and billing department codes.

人力资源应用需要确定某位员工所调动到的部门。The Human Resources app needs to determine the department an employee is transferring to.

出现以下情况时,列表实体非常适合此类数据:A list entity is a good choice for this type of data when:

  • 数据值是已知的集。The data values are a known set.
  • 此集不超出此实体类型的最大 LUIS 边界The set doesn't exceed the maximum LUIS boundaries for this entity type.
  • 话语中的文本是同义项或规范名称的完全匹配。The text in the utterance is an exact match with a synonym or the canonical name. LUIS 不会使用除文本完全匹配项之外的列表。LUIS doesn't use the list beyond exact text matches. 仅仅有列表实体无法解析词干、复数形式和其他变体。Stemming, plurals, and other variations are not resolved with just a list entity. 若要管理变体,请考虑使用带有可选文本语法的模式To manage variations, consider using a pattern with the optional text syntax.

创建新应用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.

创建将员工调动到其他部门的意向Create an intent to transfer employees to a different department

  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 Create new intent.

  3. 在弹出对话框中输入 TransferEmployeeToDepartment,然后选择“完成”。Enter TransferEmployeeToDepartment in the pop-up dialog box then select Done.


  4. 将示例陈述添加到意向。Add example utterances to the intent.

    示例陈述Example utterances
    将 John W. Smith 转到会计部门move John W. Smith to the accounting department
    将 Jill Jones 转到研发部门transfer Jill Jones from to R&D
    1234 部门新增一位名为 Bill Bradstreet 的成员Dept 1234 has a new member named Bill Bradstreet
    将 John Jackson 安排在工程部门Place John Jackson in Engineering
    将 Debra Doughtery 转到内部销售部门move Debra Doughtery to Inside Sales
    将 Jill Jones 转到 IT 部门mv Jill Jones to IT
    将 Alice Anderson 转到开发运营部门Shift Alice Anderson to DevOps
    将 Carl Chamerlin 转到财务部门Carl Chamerlin to Finance
    将 Steve Standish 转到 1234 部门Steve Standish to 1234
    将 Tanner Thompson 转到 3456 部门Tanner Thompson to 3456

    带有示例话语的意图屏幕截图Screenshot of intent with example utterances

    这些话语仅用于演示。These few utterances are for demonstration purposes only. 实际应用应该至少有 15 个话语,这些话语的长度、单词顺序、时态、语法正确性、标点符号和单词计数各不相同。A real-world app should have at least 15 utterances of varying length, word order, tense, grammatical correctness, punctuation, and word count.

部门列表实体Department list entity

“TransferEmployeeToDepartment”意向有示例话语以后,LUIS 需了解什么是部门。Now that the TransferEmployeeToDepartment intent has example utterances, LUIS needs to understand what is a department.

每个项的主规范名称是部门名称。The primary, canonical, name for each item is the department name. 每个规范名称的同义词的示例如下:Examples of the synonyms of each canonical name are:

规范名称Canonical name 同义词Synonyms
计帐Accounting acctacct
开发操作Development Operations DevopsDevops
工程Engineering engeng
财务Finance finfin
信息技术Information Technology ITIT
内部销售Inside Sales isaleisale
研究和开发Research and Development R&DR&D
  1. 在左侧面板中选择“实体”。Select Entities in the left panel.

  2. 选择“创建新实体”。Select Create new entity.

  3. 在实体弹出对话框中,输入 Department 作为实体名称,输入“列表”作为实体类型。In the entity pop-up dialog, enter Department for the entity name, and List for entity type. 选择“完成” 。Select Done.

    创建新实体弹出项对话框的屏幕截图Screenshot of creating new entity pop-up dialog

  4. 在“部门”实体页上,输入 Accounting 作为新值。On the Department entity page, enter Accounting as the new value.

  5. 对于同义词,请从上表中添加同义词。For Synonyms, add the synonyms from the previous table.

  6. 继续添加所有规范名称及其同义词。Continue adding all the canonical names and their synonyms.

将话语示例添加到 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.


不要将“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 的末尾,并输入 shift Joe Smith to ITGo to the end of the URL in the address and enter shift Joe Smith to IT. 最后一个查询字符串参数为 q,表示陈述查询 (query)。The last querystring parameter is q, the utterance query. 此陈述不同于标记的任何陈述,因此,它非常适合用于测试,测试结果应返回提取了 DepartmentTransferEmployeeToDepartment 意向。This utterance is not the same as any of the labeled utterances so it is a good test and should return the TransferEmployeeToDepartment intent with Department extracted.

       "query": "shift Joe Smith to IT",
       "topScoringIntent": {
         "intent": "TransferEmployeeToDepartment",
         "score": 0.9775754
       "intents": [
           "intent": "TransferEmployeeToDepartment",
           "score": 0.9775754
           "intent": "None",
           "score": 0.0154493852
       "entities": [
           "entity": "it",
           "type": "Department",
           "startIndex": 19,
           "endIndex": 20,
           "resolution": {
             "values": [
               "Information Technology"

清理资源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 new intent, added example utterances, then created a list entity to extract exact text matches from utterances. 在训练并发布应用后,向终结点发出的查询识别了意向,并返回了提取的数据。After training, and publishing the app, a query to the endpoint identified the intention and returned the extracted data.

继续使用此应用,添加复合实体Continue with this app, adding a composite entity.