教程:生成 LUIS 应用以确定用户意向Tutorial: Build a LUIS app to determine user intentions

在本教程中,创建一个自定义应用,以便根据言语(文本)预测用户的意向。In this tutorial, you create a custom app that predicts a user's intention based on the utterance (text).

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

  • 创建新应用Create a new app
  • 创建意向Create intents
  • 添加示例话语Add example utterances
  • 训练应用Train app
  • 发布应用Publish app
  • 从终结点获取意向预测Get intent prediction from endpoint

将用户意向用作意向User intentions as intents

此应用的目的是确定聊天性的自然语言文本的意图:The purpose of the app is to determine the intention of conversational, natural language text:

I'd like to order a veggie pizza with a salad on the side.

这些意图可以归类为 意向These intentions are categorized into Intents.

IntentIntent 目的Purpose
ModifyOrder 确定用户的披萨订单。Determine user's pizza order.
Greeting 开始机器人对话。Begin bot conversation.
ConfirmOrder 确认披萨订单。Confirm pizza order.
None 确定用户是否正在询问 LUIS 应用不应回答的问题。Determine if user is asking something the LUIS app is not designed to answer. 此意向如果作为应用创建的一部分提供,则无法删除。This intent is provided as part of app creation and can't be deleted.

创建新应用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. 在弹出的对话框中输入名称 Pizza tutorial,保留默认的区域性“英语”。In the pop-up dialog, enter the name Pizza tutorial and keep the default culture, English. 其他字段是可选的,请勿设置。The other fields are optional, do not set them. 选择“完成”。Select Done.

    输入新 LUIS 应用的名称

创建新意向Create a new intent

意向用于根据用户的意图(根据自然语言文本确定)对用户言语进行分类。An intent is used to classify user utterances based on the user's intention, determined from the natural language text.

要对言语进行分类,意向需要使用应根据该意向分类的用户言语的示例。In order to classify an utterance, the intent needs examples of user utterances that should be classified with this intent.

  1. 在“意向”页面的“生成”部分中,选择“+ 创建”以创建新意向 。In the Build section, on the Intents page, select + Create to create a new intent. 输入新意向名称 OrderPizza,然后选择“完成”。Enter the new intent name, OrderPizza, then select Done.

    在用户想要订购披萨时,预测 OrderPizza 意向。The OrderPizza intent is predicted when a user wants to order a pizza.

  2. 将多个示例话语添加到你预期用户会请求的此意向:Add several example utterances to this intent that you expect a user to ask:

    OrderPizza 示例言语OrderPizza example utterances
    can i get a pepperoni pizza and a can of coke please
    can i get a small pizza with onions peppers and olives
    delivery for a small pepperoni pizza
    pickup a cheddar cheese pizza large with extra anchovies
    i need 2 large cheese pizzas 6 large pepperoni pizzas and 1 large supreme pizza
    Order a pizza for me

    在 LUIS 门户的意向页上添加示例言语的屏幕截图Screenshot of adding example utterances in LUIS portal on Intent page

    可通过提供示例话语来训练 LUIS,让其了解应该根据哪些类型的话语预测出此意向。By providing example utterances, you are teaching LUIS about what kinds of utterances should be predicted for this intent. 以下是几个正面示例。These are positive examples. 其他所有意向中的言语均被视为该意向的负面示例。The utterances in all the other intents are treated as negative examples for this intent.

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

创建其余意向Create remaining intents

  1. 创建 Greeting 意向,并添加以下示例言语。Create the Greeting intent and add the following example utterances. 这是用于确定用户是否开始新的披萨订单会话的意向。This is the intent to determine if a user is beginning a new pizza order conversation.

    Greeting 示例言语Greeting example utterances
  2. 创建 Confirm 意向,并添加以下示例言语。Create the Confirm intent and add the following example utterances. 这是一个意向,用于确定用户是否已完成订购并接受订单详细信息。This is the intent to determine if a user is done ordering and accepts the order details.

    Confirm 示例言语Confirm example utterances
    Go ahead

None 意向示例言语None intent example utterances

客户端应用程序需要知道某个话语是否对应用程序没有意义或不合适。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 shouldn'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.

如果将“无”意向留空,则将在现有主题域意向之一中预测应在主题域之外预测的言语。If you leave the None intent empty, an utterance that should be predicted outside the subject domain will be predicted in one of the existing subject domain intents. 因此,客户端应用程序(如聊天机器人)将基于错误的预测执行错误的操作。The result is that the client application, such as a chat bot, will perform incorrect operations based on an incorrect prediction.

  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 Pizza ordering app:

    None 示例言语None example utterances
    Barking dogs are annoying
    Penguins in the ocean

    这些示例不应使用预期在主题域中出现的字词,例如 pizzacheesecrustpickup deliverThese examples shouldn't use words you expect in your subject domain such as pizza, cheese, crust, pickup deliver.

训练应用Train the app

  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

若要在聊天机器人或其他客户端应用程序中接收 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 发布到终结点”按钮的屏幕截图Screenshot of LUIS publish to endpoint button in top right menu

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

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

  3. 在通知中选择“访问终结点 URL”,以转到“Azure 资源”页 。Select Access your endpoint URLs in the notification to go to the Azure Resources page. 只有你拥有与应用关联的预测资源时,才能看到 URL。You will only be able to see the URLs if you have a prediction resource associated with the app. 还可以单击“管理”来找到“Azure 资源”页 。You can also find the Azure Resources page by clicking Manage.

    指示应用已发布的消息A message that the app has been published

获取意向预测Get intent prediction

  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:

  2. 转到地址栏中 URL 的末尾,输入:Go to the end of the URL in the address bar and enter:

    get a medium vegetarian pizza for delivery

    查询字符串参数为 query,言语 query 会在 URI 中传递。The query string parameter is query, the utterance query is passed in the URI. 此话语不同于任何示例话语。This utterance is not the same as any of the example utterances. 这应该是一项很好的测试,可检查 LUIS 是否会学习 OrderPizza 意向并将它预测为得分最高的意向。This should be a good test to check if LUIS learns and predicts the OrderPizza intent as the top scoring intent.

        "query": "get a medium vegetarian pizza for delivery",
        "prediction": {
            "topIntent": "OrderPizza",
            "intents": {
                "OrderPizza": {
                    "score": 0.6488959
                "None": {
                    "score": 0.139966831
                "Confirm": {
                    "score": 0.00736504374
                "Greeting": {
                    "score": 0.003970454
            "entities": {}

    实体数组为空,因为此应用当前没有任何实体(言语中可供提取的数据单元)。The entities array is empty because this app currently does not have any entities (unit of data inside the utterance to extract).

    JSON 结果中标识了评分最高的意向作为 prediction.topIntent 属性。The JSON result identifies the top scoring intent as prediction.topIntent property. 所有评分介于 1 和 0 之间,评分越接近 1 越好。All scores are between 1 and 0, with the better score being closer to 1.

  3. 更改 URL 查询参数以符合“问候语”意向:Change the URL query parameter to target the Greeting intent:


    这与示例示例言语并不完全相同,因此,要查看 LUIS 是否可以了解通过此意向预测的内容。This is not exactly the same as an example utterance so it is a good test to see if LUIS can learn what should be predicted with this intent.

        "query": "howdy",
        "prediction": {
            "topIntent": "Greeting",
            "intents": {
                "Greeting": {
                    "score": 0.446016937
                "Confirm": {
                    "score": 0.2390079
                "None": {
                    "score": 0.09119555
                "OrderPizza": {
                    "score": 0.00109590159
            "entities": {}

    此预测的置信度分数为 44%。This prediction has a 44% confidence score. 若要提高置信度分数,请添加 15 到 30 个示例言语。To increase the confidence score, add between 15 and 30 example utterances.

客户端应用程序后续步骤Client-application next steps

本教程创建了 LUIS 应用、创建了意向、向每个意向添加了示例言语、向 None 意向添加了示例言语,并在终结点上进行了训练、发布和测试操作。This tutorial created a LUIS app, created intents, added example utterances to each intent, added example utterances to the None intent, trained, published, and tested at the endpoint. 这些是生成 LUIS 模型的基本步骤。These are the basic steps of building a LUIS model.

LUIS 在返回 JSON 响应后,就已经完成了此请求。After LUIS returns the JSON response, LUIS is done with this request. LUIS 不提供用户话语的应答,只会识别以自然语言请求的信息类型。LUIS doesn't provide answers to user utterances, it only identifies what type of information is being asked for in natural language. 聊天跟进由客户端应用程序提供。The conversational follow-up is provided by the client application.

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