教程:添加常见的模式模板言语格式以改进预测Tutorial: Add common pattern template utterance formats to improve predictions

在本教程中,使用模式来改进意向和实体预测,这样可以提供更少的示例言语。In this tutorial, use patterns to increase intent and entity prediction, which allows you to provide fewer example utterances. 该模式是分配给意向的模板言语,包含用于标识实体和可忽略文本的语法。The pattern is a template utterance assigned to an intent, which contains syntax to identify entities and ignorable text.

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

  • 创建模式Create a pattern
  • 验证模式预测改进Verify pattern prediction improvements
  • 将文本标记为可忽略以及在模式中进行嵌套Mark text as ignorable and nest within pattern
  • 使用测试面板验证模式成功Use test panel to verify pattern success

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

意向和模式中的言语Utterances in intent and pattern

LUIS 应用中存储了两种类型的言语:There are two types of utterances stored in the LUIS app:

  • 意向中的示例言语Example utterances in the Intent
  • 模式中的模板言语Template utterances in the Pattern

将模板言语作为一种模式添加后,总体说来可以为意向提供更少的示例言语。Adding template utterances as a pattern allows you to provide fewer example utterances overall to an intent.

模式作为文本匹配和机器学习的组合来应用。A pattern is applied as a combination of text matching and machine learning. 模式中的模板言语以及意向中的示例言语使 LUIS 能够更好地理解哪些言语符合意向。The template utterance in the pattern, along with the example utterances in the intent, give LUIS a better understanding of what utterances fit the intent.

导入示例应用并克隆到新版Import example app and clone to new version

请使用以下步骤:Use the following steps:

  1. 下载并保存应用 JSON 文件Download and save the app JSON file.

  2. 登录到 LUIS 门户,选择“订阅”和“创作资源”以查看分配给该创作资源的应用。Sign in to the LUIS portal, and select your Subscription and Authoring resource to see the apps assigned to that authoring resource.

  3. 将 JSON 导入到 LUIS 门户的新应用中。Import the JSON into a new app into the LUIS portal. 在“我的应用”页上,选择“+ 新建聊天应用”,然后选择“作为 JSON 导入”。 On the My Apps page, select + New app for conversation , then select Import as JSON . 选择在上一步骤中下载的文件,将应用命名为 Patterns tutorialSelect the file you downloaded in the previous step, name the app, Patterns tutorial.

创建新意向及其话语Create new intents and their utterances

这两个意向根据言语文本查找经理或经理的直接下属。The two intents find the manager or the manager's direct reports, based on the utterance text. 难点在于,这两个意向的含义不同,而大部分单词是相同的,The difficulty is that the two intents mean different things but most of the words are the same. 只是单词顺序不同。Only the word order is different. 为了能够正确预测意向,必须提供更多示例。In order for the intent to be predicted correctly, it would have to have many examples.

  1. 从导航栏中选择“生成”。Select Build from the navigation bar.

  2. 在“意向”页上,选择“+ 创建”以创建新意向。 On the Intents page, select + Create to create a new intent.

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

    创建新消息弹出窗口

  4. 将示例陈述添加到意向。Add example utterances to the intent. 这些言语不完全相像,但确实有一种可以提取的模式。These utterances are not exactly alike but do have a pattern that can be extracted.

    示例陈述Example utterances
    Who is John W. Smith the subordinate of?
    Who does John W. Smith report to?
    Who is John W. Smith's manager?
    Who does Jill Jones directly report to?
    Who is Jill Jones supervisor?
  5. 在左侧导航栏中选择“意向”。Select Intents in the left navigation.

  6. 选择“+ 创建”以创建新意向。Select + Create to create a new intent. 在弹出对话框中输入 OrgChart-Reports,然后选择“完成”。Enter OrgChart-Reports in the pop-up dialog box then select Done .

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

    示例陈述Example utterances
    Who are John W. Smith's subordinates?
    Who reports to John W. Smith?
    Who does John W. Smith manage?
    Who are Jill Jones direct reports?
    Who does Jill Jones supervise?

有关示例话语数量的警告Caution about example utterance quantity

这些话语仅用于演示。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.

在测试或发布前训练应用Train the app before testing or publishing

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

    “训练”按钮

  2. 当“训练”按钮上的状态指示器为绿色时,即表示训练完成。Training is complete when status indicator on the Train button is green.

发布应用,从终结点进行查询Publish the app to query 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 prediction endpoint.

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

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

  2. 选择“生产”槽,然后选择“完成” 。Select the Production slot, then select Done.

    “LUIS 发布到终结点”的屏幕截图Screenshot of LUIS publish to endpoint

  3. 在通知中选择“访问终结点 URL”链接,转到“Azure 资源”页。 Select the Access your endpoint URLs link in the notification to go to the Azure Resources page. 终结点 URL 作为“示例查询”列出。The endpoint URLs are listed as the Example Query.

从终结点获取意向和实体Get intent and entities from endpoint

  1. 在“Azure 资源”页(左侧菜单)的“管理”部分(右上方菜单)中,复制“示例查询”URL,然后粘贴到新的浏览器选项卡中 。In the Manage section (top-right menu), on the Azure Resources page (left menu), copy the Example Query URL then paste into a new browser tab.

    终结点 URL 的格式如下所示,其中 APP-ID 和 KEY-ID 将替换为你自己的自定义子域、应用 ID 和终结点密钥:The endpoint URL looks like the following format, with your own custom subdomain, app ID, and endpoint key replacing APP-ID, and KEY-ID:

    https://YOUR-CUSTOM-SUBDOMAIN.api.cognitive.azure.cn/luis/prediction/v3.0/apps/APP-ID/slots/production/predict?subscription-key=KEY-ID&verbose=true&show-all-intents=true&log=true&query=YOUR_QUERY_HERE
    
  2. 转到地址栏中 URL 的末尾,将 YOUR_QUERY_HERE 替换为 Who is the boss of Jill Jones?Go to the end of the URL in the address bar and replace YOUR_QUERY_HERE with: Who is the boss of Jill Jones?.

    {
        "query": "Who is the boss of Jill Jones?",
        "prediction": {
            "topIntent": "OrgChart-Manager",
            "intents": {
                "OrgChart-Manager": {
                    "score": 0.326605469
                },
                "OrgChart-Reports": {
                    "score": 0.127583548
                },
                "EmployeeFeedback": {
                    "score": 0.0299124215
                },
                "MoveEmployee": {
                    "score": 0.01159851
                },
                "GetJobInformation": {
                    "score": 0.0104600191
                },
                "ApplyForJob": {
                    "score": 0.007508645
                },
                "Utilities.StartOver": {
                    "score": 0.00359402061
                },
                "Utilities.Stop": {
                    "score": 0.00336530479
                },
                "FindForm": {
                    "score": 0.002653719
                },
                "Utilities.Cancel": {
                    "score": 0.00263288687
                },
                "None": {
                    "score": 0.00238638581
                },
                "Utilities.Help": {
                    "score": 0.00226386427
                },
                "Utilities.Confirm": {
                    "score": 0.00211663754
                }
            },
            "entities": {
                "keyPhrase": [
                    "boss of Jill Jones"
                ],
                "EmployeeListEntity": [
                    [
                        "Employee-45612"
                    ]
                ],
                "$instance": {
                    "keyPhrase": [
                        {
                            "type": "builtin.keyPhrase",
                            "text": "boss of Jill Jones",
                            "startIndex": 11,
                            "length": 18,
                            "modelTypeId": 2,
                            "modelType": "Prebuilt Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ],
                    "EmployeeListEntity": [
                        {
                            "type": "EmployeeListEntity",
                            "text": "Jill Jones",
                            "startIndex": 19,
                            "length": 10,
                            "modelTypeId": 5,
                            "modelType": "List Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ]
                }
            }
        }
    }
    

可以预测正确的最高意向 OrgChart-Manager,但得分不超过 70%,并且距离次高意向还远远不够。The correct top intent was predicted, OrgChart-Manager, but the score is not above 70% and isn't far enough above the next highest intent. 使用模式使正确意向的分数在百分比上显着提高,并且距离下一个最高分数更远。Use patterns to make the correct intent's score significantly higher in percentage and farther from the next highest score.

使此第二个浏览器窗口保持打开。Leave this second browser window open. 稍后将在本教程中再次使用它。You will use it again later in the tutorial.

模板话语Template utterances

考虑到人力资源主题领域的性质,可通过几种常见方式询问组织中的员工关系。Because of the nature of the Human Resource subject domain, there are a few common ways of asking about employee relationships in organizations. 例如:For example:

陈述Utterances
Who does Jill Jones report to?
Who reports to Jill Jones?

在未提供“许多”陈述示例的情况下,这些陈述过于相近而无法确定每个陈述的上下文唯一性。These utterances are too close to determine the contextual uniqueness of each without providing many utterance examples. 通过为意向添加模式,LUIS 可了解意向的常见陈述模式,而无需提供许多陈述示例。By adding a pattern for an intent, LUIS learns common utterance patterns for an intent without the need of supplying many more utterance examples.

此意向的模板陈述示例包括:Template utterance examples for this intent include:

模板陈述示例Template utterances examples 语法含义syntax meaning
Who does {EmployeeListEntity} report to[?] 可交换 {EmployeeListEntity}interchangeable {EmployeeListEntity}
忽略 [?]ignore [?]
Who reports to {EmployeeListEntity}[?] 可交换 {EmployeeListEntity}interchangeable {EmployeeListEntity}
忽略 [?]ignore [?]

{EmployeeListEntity} 语法可标记模板陈述中的实体位置以及它是哪个实体。The {EmployeeListEntity} syntax marks the entity location within the template utterance as well as which entity it is. 可选语法 [?] 标记可选的单词或标点The optional syntax, [?], marks words, or punctuation that is optional. LUIS 匹配话语,忽略括号内的可选文本。LUIS matches the utterance, ignoring the optional text inside the brackets.

虽然语法类似于正则表达式,但它不是正则表达式。While the syntax looks like a regular expression, it is not a regular expression. 仅支持大括号 {} 和方括号 [] 语法。Only the curly bracket, {}, and square bracket, [], syntax is supported. 它们最多可以嵌套两层。They can be nested up to two levels.

为了使模式与言语匹配,言语中的实体必须首先匹配模板言语中的实体。In order for a pattern to be matched to an utterance, first the entities within the utterance have to match the entities in the template utterance. 这意味着,在带实体的模式成功之前,实体在预测度高的示例言语中必须有足够的示例。This means the entities have to have enough examples in example utterances with a high degree of prediction before patterns with entities are successful. 但是,模板不会帮助预测实体,仅预测意向。However, the template doesn't help predict entities, only intents.

尽管模式允许提供较少的示例话语,但如果未检测到实体,则该模式将不匹配。While patterns allow you to provide fewer example utterances, if the entities are not detected, the pattern does not match.

添加 OrgChart-Manager 意向的模式Add the patterns for the OrgChart-Manager intent

  1. 选择顶部菜单中的“生成”。Select Build in the top menu.

  2. 在左侧导航栏中,在“提高应用性能”下,从左侧导航栏中选择“模式” 。In the left navigation, under Improve app performance , select Patterns from the left navigation.

  3. 选择 OrgChart-Manager 意向,然后输入以下模板话语:Select the OrgChart-Manager intent, then enter the following template utterances:

    模板话语Template utterances
    Who is {EmployeeListEntity} the subordinate of[?]
    Who does {EmployeeListEntity} report to[?]
    Who is {EmployeeListEntity}['s] manager[?]
    Who does {EmployeeListEntity} directly report to[?]
    Who is {EmployeeListEntity}['s] supervisor[?]
    Who is the boss of {EmployeeListEntity}[?]

    这些模板陈述使用大括号表示法包含了“EmployeeListEntity”实体。These template utterances include the EmployeeListEntity entity with the curly bracket notation.

  4. 在“模式”页上选择“OrgChart-Reports”意向,然后输入以下模板言语:While still on the Patterns page, select the OrgChart-Reports intent, then enter the following template utterances:

    模板话语Template utterances
    Who are {EmployeeListEntity}['s] subordinates[?]
    Who reports to {EmployeeListEntity}[?]
    Who does {EmployeeListEntity} manage[?]
    Who are {EmployeeListEntity} direct reports[?]
    Who does {EmployeeListEntity} supervise[?]
    Who does {EmployeeListEntity} boss[?]

使用模式时查询终结点Query endpoint when patterns are used

将模式添加到应用后,在预测运行时终结点上训练、发布和查询应用。Now that the patterns are added to the app, train, publish, and query the app at the prediction runtime endpoint.

  1. 选择“训练”。Select Train . 训练完成后,请依次选择“发布”、“生产”槽、“完成”。 After training is complete, select Publish and select the Production slot then select Done .

  2. 发布完成后,请将浏览器标签页切换回终结点 URL 标签页。After publishing is complete, switch browser tabs back to the endpoint URL tab.

  3. 转到地址栏中 URL 的末尾,并确认查询仍然为 Who is the boss of Jill Jones?,然后提交 URL 以进行新的预测。Go to the end of the URL in the address bar and verify your query is still Who is the boss of Jill Jones? then submit the URL for a new prediction.

    {
        "query": "Who is the boss of Jill Jones?",
        "prediction": {
            "topIntent": "OrgChart-Manager",
            "intents": {
                "OrgChart-Manager": {
                    "score": 0.999999046
                },
                "OrgChart-Reports": {
                    "score": 3.237443E-05
                },
                "EmployeeFeedback": {
                    "score": 4.364242E-06
                },
                "GetJobInformation": {
                    "score": 1.616159E-06
                },
                "MoveEmployee": {
                    "score": 7.575752E-07
                },
                "ApplyForJob": {
                    "score": 5.234157E-07
                },
                "None": {
                    "score": 3.3E-09
                },
                "Utilities.StartOver": {
                    "score": 1.26E-09
                },
                "FindForm": {
                    "score": 1.13636367E-09
                },
                "Utilities.Cancel": {
                    "score": 1.13636367E-09
                },
                "Utilities.Confirm": {
                    "score": 1.13636367E-09
                },
                "Utilities.Help": {
                    "score": 1.13636367E-09
                },
                "Utilities.Stop": {
                    "score": 1.13636367E-09
                }
            },
            "entities": {
                "keyPhrase": [
                    "boss of Jill Jones"
                ],
                "EmployeeListEntity": [
                    [
                        "Employee-45612"
                    ]
                ],
                "$instance": {
                    "keyPhrase": [
                        {
                            "type": "builtin.keyPhrase",
                            "text": "boss of Jill Jones",
                            "startIndex": 11,
                            "length": 18,
                            "modelTypeId": 2,
                            "modelType": "Prebuilt Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ],
                    "EmployeeListEntity": [
                        {
                            "type": "EmployeeListEntity",
                            "text": "Jill Jones",
                            "startIndex": 19,
                            "length": 10,
                            "modelTypeId": 5,
                            "modelType": "List Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ]
                }
            }
        }
    }
    

现在,意向预测的置信度已明显提高,次高意向的分数显著降低。The intent prediction is now significantly more confident and the next highest intent's score is very low. 训练时,这两种意向不会反转。These two intents won't flip-flop when training.

使用可选文本和预构建的实体Working with optional text and prebuilt entities

本教程中前面的模式模板话语包含几个可选文本示例,例如字母 s 的所有格 's 的使用以及问号 ? 的使用。The previous pattern template utterances in this tutorial had a few examples of optional text such as the possessive use of the letter s, 's, and the use of the question mark, ?. 假设需要在言语文本中允许当前和未来日期。Suppose you need to allow for current and future dates in the utterance text.

示例话语如下:Example utterances are:

IntentIntent 包含可选文本和预构建的实体的示例话语Example utterances with optional text and prebuilt entities
OrgChart-ManagerOrgChart-Manager Who was Jill Jones manager on March 3?
OrgChart-ManagerOrgChart-Manager Who is Jill Jones manager now?
OrgChart-ManagerOrgChart-Manager Who will be Jill Jones manager in a month?
OrgChart-ManagerOrgChart-Manager Who will be Jill Jones manager on March 3?

这些示例每个都使用 LUIS 需要正确预测的动词时态 wasiswill be 以及日期 March 3nowin a monthEach of these examples uses a verb tense, was, is, will be, as well as a date, March 3, now, and in a month, that LUIS needs to predict correctly. 注意,除了 inon 之外,表中最后两个示例使用了几乎相同的文本。Notice that the last two examples in the table use almost the same text except for in and on.

允许此可选信息的示例模板言语:Example template utterances that allow for this optional information:

IntentIntent 包含可选文本和预构建的实体的示例话语Example utterances with optional text and prebuilt entities
OrgChart-ManagerOrgChart-Manager who was {EmployeeListEntity}['s] manager [[on]{datetimeV2}?]
OrgChart-ManagerOrgChart-Manager who is {EmployeeListEntity}['s] manager [[on]{datetimeV2}?]

可选语法方括号 [] 的使用使此可选文本易于添加到模板话语中,并且可以嵌套到另一个级别 [[]] 并包括实体或文本。The use of the optional syntax of square brackets, [], makes this optional text easy to add to the template utterance and can be nested up to a second level, [[]], and include entities or text.

问:为何所有 w 字母(每句模板话语中的第一个字母)都是小写?它们不应当任选使用大写或小写吗?Question: Why are all the w letters, the first letter in each template utterance, lowercase? Shouldn't they be optionally upper or lowercase? 由客户端应用程序提交到查询终结点的话语将转换为小写。The utterance submitted to the query endpoint, by the client application, is converted into lowercase. 模板话语可以为大写或小写,终结点话语也可以任意使用大写或小写。The template utterance can be uppercase or lowercase and the endpoint utterance can also be either. 比较始终在转换为小写后进行。The comparison is always done after the conversion to lowercase.

问:如果 March 3 被同时预测为数字 3 和日期 March 3,预构建的数字为何不是模板话语的一部分?Question: Why isn't prebuilt number part of the template utterance if March 3 is predicted both as number 3 and date March 3? 模板话语从上下文来看使用的是日期,无论是逐字表示为 March 3 还是抽象为 in a month.The template utterance contextually is using a date, either literally as in March 3 or abstracted as in a month. 日期可以包含数字,但数字不一定会被视为日期。A date can contain a number but a number may not necessarily be seen as a date. 请始终使用能够最好地表示你要在预测 JSON 结果中返回的类型的实体。Always use the entity that best represents the type you want returned in the prediction JSON results.

问:如果使用了措辞不当的话语(例如 Who will {EmployeeListEntity}['s] manager be on March 3?),将会怎样?Question: What about poorly phrased utterances such as Who will {EmployeeListEntity}['s] manager be on March 3?. 像这种在语法上不同的动词时态(其中 willbe 是独立的)需要作为一句新的模板话语。Grammatically different verb tenses such as this where the will and be are separated need to be a new template utterance. 现有模板话语将不会匹配它。The existing template utterance will not match it. 虽然话语的意向未更改,但是话语中的单词位置已更改。While the intent of the utterance hasn't changed, the word placement in the utterance has changed. 此更改会影响 LUIS 中的预测。This change impacts the prediction in LUIS. 可以使用 group 和 or 运算符来组合谓语时态,以合并这些言语。You can group and or the verb-tenses to combine these utterances.

注意

请记住:将首先查找实体,然后再匹配模式。Remember: entities are found first, then the pattern is matched.

添加新的模式模板话语Add new pattern template utterances

  1. 仍然停留在“生成”的“模式”部分中,添加几个新的模式模板话语。While still in the Patterns section of Build , add several new pattern template utterances. 从“意向”下拉菜单中选择“OrgChart-Manager”,然后输入下面的每条模板话语:Select OrgChart-Manager from the Intent drop-down menu and enter each of the following template utterances:

    IntentIntent 包含可选文本和预构建的实体的示例话语Example utterances with optional text and prebuilt entities
    OrgChart-ManagerOrgChart-Manager who was {EmployeeListEntity}['s] manager [[on]{datetimeV2}?]
    OrgChart-ManagerOrgChart-Manager who will be {EmployeeListEntity}['s] manager [[in]{datetimeV2}?]
    OrgChart-ManagerOrgChart-Manager who will be {EmployeeListEntity}['s] manager [[on]{datetimeV2}?]
  2. 选择导航栏的“训练”来训练该应用。Select Train in the navigation bar to train the app.

  3. 训练完成后,选择面板顶部的“测试”以打开测试面板。After training is complete, select Test at the top of the panel to open the testing panel.

  4. 输入多条测试话语来验证模式是否匹配以及意向得分是否很高。Enter several test utterances to verify that the pattern is matched and the intent score is significantly high.

    输入第一条话语后,选择结果下的“检查”,以便可以看到所有预测结果。After you enter the first utterance, select Inspect under the result so you can see all the prediction results. 每个陈述都应包含“OrgChart Manager”意向,并且应提取 EmployeeListEntitydatetimeV2 实体的值。Each utterance should have the OrgChart-Manager intent and should extract the values for the EmployeeListEntity and datetimeV2 entities.

    话语Utterance
    Who will be Jill Jones manager
    who will be jill jones's manager
    Who will be Jill Jones's manager?
    who will be Jill jones manager on March 3
    Who will be Jill Jones manager next Month
    Who will be Jill Jones manager in a month?

所有这些话语都在内部找到了实体,因此它们将匹配相同的模式,并且具有很高的预测得分。All of these utterances found the entities inside, therefore they match the same pattern, and have a high prediction score. 你添加了几个模式,这些模式将匹配多个言语变体。You added a few patterns that will match many variations of utterances. 无需在意向中添加任何示例言语,即可让模板言语在模式中工作。You didn't need to add any example utterances in the intent to have the template utterance work in the pattern.

这样使用模式提供了:This use of patterns provided:

  • 更高的预测评分Higher prediction scores
  • 意向中的相同示例言语With the same example utterances in the intent
  • 模式中一些构造良好的模板言语With just a few well-constructed template utterances in the pattern

使用 OR 运算符和 groupUse the OR operator and groups

前面的几个模板言语非常接近。Several of the previous template utterances are very close. 使用 group ()OR | 语法减少模板言语。Use the group () and OR | syntax to reduce the template utterances.

使用 group () 和 OR | 语法可将以下两种模式合并成单个模式。The following two patterns can combine into a single pattern using the group () and OR | syntax.

IntentIntent 包含可选文本和预构建的实体的示例话语Example utterances with optional text and prebuilt entities
OrgChart-ManagerOrgChart-Manager who will be {EmployeeListEntity}['s] manager [[in]{datetimeV2}?]
OrgChart-ManagerOrgChart-Manager who will be {EmployeeListEntity}['s] manager [[on]{datetimeV2}?]

新的模板言语为:The new template utterance will be:

who ( was | is | will be ) {EmployeeListEntity}['s] manager [([in]|[on]){datetimeV2}?] 列中的一个值匹配。who ( was | is | will be ) {EmployeeListEntity}['s] manager [([in]|[on]){datetimeV2}?].

此代码围绕所需的谓语时态使用 group ,并在两者之间结合 or 管道使用可选的 inonThis uses a group around the required verb tense and the optional in and on with an or pipe between them.

备注

使用“OR”符号、|(管道)时,请确保管道符号在示例模板中的前后都用空格分隔。When using the OR symbol , | (pipe), make sure to separate the pipe symbol with a space before and after it in the example template.

  1. 在“模式”页上,选择“OrgChart-Manager”筛选器。 On the Patterns page, select the OrgChart-Manager filter. 通过搜索 manager 来缩小列表范围。Narrow the list by searching for manager.

  2. 保留模板言语的一个版本(以便在下一步骤中编辑),并删除其他变体。Keep one version of the template utterance (to edit in next step) and delete the other variations.

  3. 将模板言语更改为:Change the template utterance to:

    who ( was | is | will be ) {EmployeeListEntity}['s] manager [([in]|[on]){datetimeV2}?]

  4. 选择导航栏的“训练”来训练该应用。Select Train in the navigation bar to train the app.

  5. 训练完成后,选择面板顶部的“测试”以打开测试面板。After training is complete, select Test at the top of the panel to open the testing panel.

    使用“测试”窗格测试言语的版本:Use the Test pane to test versions of the utterance:

    在“测试”窗格中输入的言语Utterances to enter in Test pane
    Who is Jill Jones manager this month
    Who is Jill Jones manager on July 5th
    Who was Jill Jones manager last month
    Who was Jill Jones manager on July 5th
    Who will be Jill Jones manager in a month
    Who will be Jill Jones manager on July 5th

通过使用更多模式语法,可以减少必须在应用中维护的模板言语的数量,同时仍保持高的预测评分。By using more pattern syntax, you reduce the number of template utterances you have to maintain in your app, while still having a high prediction score.

使用言语开头和结尾定位符Use the utterance beginning and ending anchors

模式语法提供包含脱字号 ^ 的开头和结尾言语定位符语法。The pattern syntax provides beginning and ending utterance anchor syntax of a caret, ^. 开头和结尾言语定位符可以结合使用,以针对非常具体的、可能是文本的言语;或者,可以单独使用以针对意向。The beginning and ending utterance anchors can be used together to target very specific and possibly literal utterance or used separately to target intents.

使用 Pattern.any 实体Using Pattern.any entity

通过 pattern.any 实体,可找到自由格式数据,其中实体的用语方式比较晦涩,难以从话语的其余部分来确定实体的结尾。The pattern.any entity allows you to find free-form data where the wording of the entity makes it difficult to determine the end of the entity from the rest of the utterance.

此人力资源应用有助于员工查找公司表单。A Human Resources app helps employees find company forms.

话语Utterance
HRF-123456 在哪里?Where is HRF-123456 ?
HRF-123234 的作者是谁?Who authored HRF-123234 ?
HRF-456098 是以法语发布的吗?HRF-456098 is published in French?

但是,每个表单都具有一个带格式的名称(如上表所使用的名称),以及一个易记名称,如 Request relocation from employee new to the company 2018 version 5However, each form has both a formatted name, used in the preceding table, as well as a friendly name, such as Request relocation from employee new to the company 2018 version 5.

具有易记表单名称的话语如下所示:Utterances with the friendly form name look like:

话语Utterance
“公司新员工请求调职 2018 年第 5 版”在哪里?Where is Request relocation from employee new to the company 2018 version 5 ?
“公司新员工请求调职 2018 年第 5 版”的作者是谁?Who authored "Request relocation from employee new to the company 2018 version 5" ?
“公司新员工请求调职 2018 年第 5 版”是以法语发布的吗?Request relocation from employee new to the company 2018 version 5 is published in French?

此可变长度包含可能导致 LUIS 无法正确识别实体结尾位置的单词。The varying length includes words that may confuse LUIS about where the entity ends. 在模式中使用 Pattern.any 实体,可指定表单名称的开头和结尾,以便 LUIS 正确提取表单名称。Using a Pattern.any entity in a pattern allows you to specify the beginning and end of the form name so LUIS correctly extracts the form name.

模板话语示例Template utterance example
{FormName} 在哪里[?]Where is {FormName}[?]
{FormName} 的作者是谁[?]Who authored {FormName}[?]
{FormName} 是以法语发布的吗[?]{FormName} is published in French[?]

查看模式。任何参考信息Review Pattern.any reference information

通过 Pattern.any 添加示例言语Add example utterances with Pattern.any

  1. 从顶部导航栏中选择“生成”,然后从左侧导航栏中选择“意向”。Select Build from the top navigation, then select Intents from left navigation.

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

  3. 添加一些示例言语。Add some example utterances. 应预测为 Pattern.any 的文本以粗体文本显示。The text that should be predicted as a Pattern.any is in bold text . 根据言语中两边的其他单词很难确定表单名称。The form name is difficult to determine from the other words around it in the utterance. Pattern.any 可以标记实体的边界,这样有助于找到表单名称。The Pattern.any will help by marking the boundaries of the entity.

    示例陈述Example utterance 窗体名称Form name
    “实验室着火时该怎么办”的表单在哪里,在我阅读该表单后需要谁签名?Where is the form What to do when a fire breaks out in the Lab and who needs to sign it after I read it? 实验室着火时该怎么办What to do when a fire breaks out in the Lab
    “公司新员工请求调职”在服务器上的哪里?Where is Request relocation from employee new to the company on the server? 公司新员工请求调职Request relocation from employee new to the company
    “主要校园的健康和保健请求”的作者是谁并且最新版本是什么?Who authored " Health and wellness requests on the main campus " and what is the most current version? 主要校园的健康和保健请求Health and wellness requests on the main campus
    我正在查找名为“包括物理资产的 Office 移动请求”的表单。I'm looking for the form named " Office move request including physical assets ". 包括物理资产的 Office 移动请求Office move request including physical assets

    如果没有 Pattern.any 实体,则 LUIS 很难理解表单标题的结束位置,因为表单名称有很多种变体。Without a Pattern.any entity, it would be difficult for LUIS to understand where the form title ends because of the many variations of form names.

创建 Pattern.any 实体Create a Pattern.any entity

Pattern.any 实体提取不同长度的实体。The Pattern.any entity extracts entities of varying length. 它仅适用于模式,因为模式会使用语法标记实体的开头和结尾。It only works in a pattern because the pattern marks the beginning and end of the entity with syntax.

  1. 在左侧导航栏中选择“意向”。Select Entities in the left navigation.

  2. 选择“+ 创建”,输入名称 FormName,然后选择“Pattern.any”作为类型。Select + Create , enter the name FormName, and select Pattern.any as the type. 选择“创建”。Select Create .

添加使用 Pattern.any 的模式Add a pattern that uses the Pattern.any

  1. 从左侧导航栏中选择“模式”。Select Patterns from the left navigation.

  2. 选择“FindForm”意向。Select the FindForm intent.

  3. 输入以下使用新实体的模板话语:Enter the following template utterances, which use the new entity:

    模板话语Template utterances
    Where is the form ["]{FormName}["] and who needs to sign it after I read it[?]
    Where is ["]{FormName}["] on the server[?]
    Who authored ["]{FormName}["] and what is the most current version[?]
    I'm looking for the form named ["]{FormName}["][.]
  4. 将应用定型。Train the app.

测试自由格式的数据提取的新模式Test the new pattern for free-form data extraction

  1. 从顶栏中选择“测试”,打开测试面板。Select Test from the top bar to open the test panel.

  2. 输入以下话语:Enter the following utterance:

    Where is the form Understand your responsibilities as a member of the community and who needs to sign it after I read it?

  3. 在结果下选择“检查”,查看实体和意向的测试结果。Select Inspect under the result to see the test results for entity and intent.

    首先找到 FormName 实体,然后找到模式,并确定意向。The entity FormName is found first, then the pattern is found, determining the intent. 如果测试结果中未检测到实体,因而未找到模式,则需要在意向(而不是模式)上添加更多示例陈述。If you have a test result where the entities are not detected, and therefore the pattern is not found, you need to add more example utterances on the intent (not the pattern).

  4. 选择顶部导航栏上的“测试”按钮,关闭测试面板。Close the test panel by selecting the Test button in the top navigation.

使用显式列表Using an explicit list

如果发现模式在包含 Pattern.any 时错误提取实体,请使用显式列表来更正此问题。If you find that your pattern, when it includes a Pattern.any, extracts entities incorrectly, use an explicit list to correct this problem.

本教程的目标是什么?What did this tutorial accomplish?

本教程添加了模式,以帮助 LUIS 通过明显更高的分数来预测意向,而无需添加更多的示例言语。This tutorial added patterns to help LUIS predict the intent with a significantly higher score without having to add more example utterances. 对实体和可忽略的文本进行标记使得 LUIS 可以将模式应用于更广泛的各种话语。Marking entities and ignorable text allowed LUIS to apply the pattern to a wider variety of utterances.

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