快速入门:使用预构建的家庭自动化应用Quickstart: Use prebuilt Home automation app

在本快速入门中,请使用预生成的域 HomeAutomation 来创建 LUIS 应用,以便打开和关闭灯和设备。In this quickstart, create a LUIS app that uses the prebuilt domain HomeAutomation for turning lights and appliances on and off. 此预生成的域为你提供意向、实体和示例话语。This prebuilt domain provides intents, entities, and example utterances for you. 完成本教程后,你会有一个在云中运行的 LUIS 终结点。When you're finished, you'll have a LUIS endpoint running in the cloud.

登录到 LUIS 门户Sign in to LUIS portal

LUIS 的新用户需要执行此过程:A new user to LUIS needs to follow this procedure:

  1. 登录到 LUIS 门户(预览版),选择你的国家/地区,并同意使用条款。Sign in to LUIS portal (preview), select your country and agree to the terms of use. 如果看到“我的应用” ,则 LUIS 资源已存在,你应该跳过此过程,开始创建应用。If you see My Apps instead, a LUIS resource already exists and you should skip ahead to create an app.

  2. 选择“创建 Azure资源” ,然后选择“创建要将应用迁移到的创作资源”。Select Create Azure resource then select Create an authoring resource to migrate your apps to.

    选择语言理解创作资源的类型

  3. 填写资源的详细信息。Fill in the details for the resource.

    创建创作资源

    创建新的创作资源时,请提供以下信息:When creating a new authoring resource, provide the following information:

    • 资源名称 - 你选择的自定义名称,用作创作和预测终结点查询的 URL 的一部分。Resource name - a custom name you choose, used as part of the URL for your authoring and prediction endpoint queries.
    • 租户 - 与 Azure 订阅关联的租户。Tenant - the tenant your Azure subscription is associated with.
    • 订阅名称 - 将对资源计费的订阅。Subscription name - the subscription that will be billed for the resource.
    • 资源组 - 你选择或创建的自定义资源组名称。Resource group - a custom resource group name you choose or create. 使用资源组可将 Azure 资源分组,以便进行访问和管理。Resource groups allow you to group Azure resources for access and management.
    • 位置 - 位置选项基于资源组选择。Location - the location choice is based on the resource group selection.
    • 定价层 - 定价层确定每秒和每月的最大事务数。Pricing tier - the pricing tier determines the maximum transaction per second and month.
  4. 此时将显示要创建的资源的摘要。A summary of the resource to be created is displayed. 选择“下一步”。Select Next.

    创建创作资源

  5. 选择“继续”进行确认 。Confirm by selecting Continue.

    创建创作资源

选择订阅和创作资源Select subscription and authoring resource

在 LUIS 门户中,若要查看应用列表或创建应用,请选择订阅和创作资源。In the LUIS portal, to see a list of apps or to create an app, select the subscription and authoring resource. 通过 LUIS 创作资源访问应用。Apps are accessed by the LUIS authoring resource.

选择创作订阅和创作资源

创建新应用Create a new app

可在“我的应用”中创建和管理应用程序 。You can create and manage your applications on My Apps.

  1. LUIS 门户的“我的应用”列表中,选择“+ 创建” 。In the LUIS portal, on the My apps list, select + Create.

    在 LUIS 门户的“我的应用”列表中,选择“+ 创建”。

  2. 在对话框中,将应用程序命名为 Home Automation,然后选择“完成” 。In the dialog box, name your application Home Automation then select Done. LUIS 创建应用程序。LUIS creates the app. 说明是可选的,不会用于创作或预测。The description is optional and isn't used for authoring or prediction. 创建 LUIS 应用时,预测资源也是可选的。The prediction resource is also optional when creating a LUIS app. 将应用发布到生产环境时,应该分配一个预测资源,使应用能够处理多个请求。When you publish your app to production, you should assign a prediction resource so your app can handle many requests.

    在对话框中,将应用程序命名为“家庭自动化”

    备注

    创建应用程序后将无法更改区域性。The culture cannot be changed once the application is created.

意向和实体Intents and entities

在左侧导航窗格中选择“意向”,以便查看 HomeAutomation 域意向。Select Intents in the left-side navigation pane to review the HomeAutomation domain intents. 每个意向都有示例话语。Each intent has sample utterances.

HomeAutomation 意向列表的屏幕截图]Screenshot of HomeAutomation intents list]

备注

“无”是由所有 LUIS 应用提供的意向。None is an intent provided by all LUIS apps. 可以使用它来处理与应用提供的功能无法对应的话语。You use it to handle utterances that don't correspond to functionality your app provides.

选择 HomeAutomation.TurnOff 意向。Select the HomeAutomation.TurnOff intent. 可以看到,此意向包含一系列使用实体标记的话语。You can see that the intent contains a list of utterances that are labeled with entities.

HomeAutomation.TurnOff 意向的屏幕截图Screenshot of HomeAutomation.TurnOff intent

训练 LUIS 应用Train the LUIS app

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

    “训练”按钮

  2. 当你看到确认成功的状态时,训练已完成。Training is complete when you see the status confirming success.

    提示

    “通知” 在右上方导航中提供,并包含历史记录。Notifications is available in the top-right navigation and includes a history.

测试应用程序Test your app

训练完应用以后,即可测试它。Once you've trained your app, you can test it. 选择“测试”。 Select Test. 在“交互式测试”窗格中键入 Turn off the lights 之类的测试言语,然后按 Enter。Type a test utterance like Turn off the lights into the interactive test pane, and press Enter.

Turn off the lights

检查评分最高的意向是否对应于每个测试话语的预期意向。Check that the top scoring intent corresponds to the intent you expected for each test utterance.

在以下示例中,Turn off the lights 被正确标识为“HomeAutomation.TurnOff” 的评分最高的意向。In this example, Turn off the lights is correctly identified as the top scoring intent of HomeAutomation.TurnOff.

“测试”面板的屏幕截图,其中突出显示了话语

选择“检查” 以查看有关预测的详细信息。Select Inspect to review more information about the prediction.

包含检查信息的测试面板的屏幕截图

再次选择“测试” ,折叠测试窗格。Select Test again to collapse the test pane.

发布应用以获取终结点 URLPublish the app to get the endpoint URL

若要在聊天机器人或其他客户端应用程序中接收 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 status bar at the top of the page confirming success.

    LUIS 发布到终结点

  4. 在通知中选择“访问终结点 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.

查询 V3 API 预测终结点Query the V3 API prediction endpoint

  1. 在 LUIS 门户中,在“管理”部分(右上方菜单)的“密钥和终结点”页(左侧菜单)上,选择页面底部的“终结点 URL”。In the LUIS portal, 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 browser tab with the endpoint URL in the address bar.

    该 URL 具有应用 ID、密钥和槽名称。The URL has your app ID, key, and slot name. V3 预测终结点 URL 如下所示:The V3 prediction endpoint URL looks like:

    https://REGION.api.cognitive.azure.cn/luis/prediction/v3.0/apps/APP-ID/slots/SLOT-NAME/predict?subscription-key=YOUR-KEY&<optional-name-value-pairs>&query=UTTERANCE-TEXT.

  1. 对于查询字符串,在浏览器地址栏中确保以下名称和值栏在 URL 中。In the browser address bar, for the query string, make sure the following name and value bars are in the URL. 如果它们不在查询字符串中,请添加它们:If they are not in the query string, add them:

    名称/值对Name/value pair
    verbose=true
    show-all-intents=true
  2. 在浏览器地址栏中,转到 URL 末尾,对于查询,输入 turn off the living room light 值,然后按 Enter 。In the browser address bar, go to the end of the URL and enter turn off the living room light for the query value, then press Enter.

    {
        "query": "turn off the living room light",
        "prediction": {
            "topIntent": "HomeAutomation.TurnOff",
            "intents": {
                "HomeAutomation.TurnOff": {
                    "score": 0.984315455
                },
                "HomeAutomation.QueryState": {
                    "score": 0.009912962
                },
                "HomeAutomation.TurnDown": {
                    "score": 0.00626645749
                },
                "HomeAutomation.TurnUp": {
                    "score": 0.00572059769
                },
                "HomeAutomation.SetDevice": {
                    "score": 0.00379381469
                },
                "HomeAutomation.TurnOn": {
                    "score": 0.00366983772
                },
                "None": {
                    "score": 0.000623856
                }
            },
            "entities": {
                "HomeAutomation.Location": [
                    "living room"
                ],
                "HomeAutomation.DeviceName": [
                    [
                        "living room light"
                    ]
                ],
                "HomeAutomation.DeviceType": [
                    [
                        "light"
                    ]
                ],
                "$instance": {
                    "HomeAutomation.Location": [
                        {
                            "type": "HomeAutomation.Location",
                            "text": "living room",
                            "startIndex": 13,
                            "length": 11,
                            "score": 0.907323956,
                            "modelTypeId": 1,
                            "modelType": "Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ],
                    "HomeAutomation.DeviceName": [
                        {
                            "type": "HomeAutomation.DeviceName",
                            "text": "living room light",
                            "startIndex": 13,
                            "length": 17,
                            "modelTypeId": 5,
                            "modelType": "List Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ],
                    "HomeAutomation.DeviceType": [
                        {
                            "type": "HomeAutomation.DeviceType",
                            "text": "light",
                            "startIndex": 25,
                            "length": 5,
                            "modelTypeId": 5,
                            "modelType": "List Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ]
                }
            }
        }
    }
    

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