什么是语言理解 (LUIS)?What is Language Understanding (LUIS)?

语言理解 (LUIS) 是一种基于云的 API 服务,可将自定义机器学习智能应用到自然语言文本,以便预测整体含义并提炼出相关的详细信息。Language Understanding (LUIS) is a cloud-based API service that applies custom machine-learning intelligence to natural language text to predict overall meaning, and pull out relevant, detailed information.

例如,当客户端应用程序发送文本 find me a wireless keyboard for $30 时,LUIS 使用以下 JSON 对象进行响应。For example, when a client application sends the text, find me a wireless keyboard for $30, LUIS responds with the following JSON object.

{
    "query": "find me a wireless keyboard for $30",
    "prediction": {
        "topIntent": "Finditem",
        "intents": {
            "Finditem": {
                "score": 0.934672
            }
        },
        "entities": {
            "item": [
                "wireless keyboard"
            ],
            "money": [
        {
            "number": 30,
            "units": "Dollar"
        }
           ]
        }
        
    }
}

在上面的示例中, 意向 或者说短语的整体含义为用户正在尝试查找某个项。In the example above, the intent, or overall meaning of the phrase is that the user is trying to find an item. LUIS 提取的详细信息片段称为 实体The detailed pieces of information that LUIS extracts are called entities. 在本例中,实体为用户要查找的项的名称以及他们要花费的资金的金额。In this case, the entities are the name of the item the user is looking for and the amount of money they want to spend.

客户端应用程序使用 LUIS 的返回的 JSON、意向(类别)和_实体_(提取的详细信息)来驱动客户端应用程序中的操作。Client applications use LUIS's returned JSON, the intent (category), and entities (extracted detailed information), to drive actions in the client application. LUIS 的客户端应用程序通常是对话应用程序,其使用自然语言与用户通信,以便完成任务。A client application for LUIS is often a conversational application that communicates with a user in natural language to complete a task. 这些客户端应用程序包括社交媒体应用、聊天机器人以及支持语音的桌面应用程序。Examples of client applications include social media apps, chat bots, and speech-enabled desktop applications.

3 个客户端应用程序使用认知服务语言理解 (LUIS) 的概念图Conceptual image of 3 client applications working with Cognitive Services Language Understanding (LUIS)

在聊天机器人中使用 LUIS 示例Example use LUIS in a chat bot

客户端应用程序向已发布的 LUIS 自然语言处理终结点 [API][endpoint-apis] 发送言语(文本)并将结果作为 JSON 响应接收。A client application sends utterances (text) to the published LUIS natural language processing endpoint [API][endpoint-apis] and receives the results as JSON responses. LUIS 的常用客户端应用程序是聊天机器人。A common client application for LUIS is a chat bot.

LUIS 使用聊天机器人以通过自然语言理解 (NLP) 预测用户文本的概念图Conceptual imagery of LUIS working with Chat bot to predict user text with natural language understanding (NLP)

步骤Step 操作Action
11 客户端应用程序将用户_话语_(采用自己的词汇的文本)“我想要呼叫 HR 代表”作为 HTTP 请求发送The client application sends the user utterance (text in their own words), "I want to call my HR rep." 给 LUIS 终结点。to the LUIS endpoint as an HTTP request.
22 LUIS 将学习过的模型应用到自然语言文本,以便提供有关用户输入的智能理解。LUIS applies the learned model to the natural language text to provide intelligent understanding about the user input. LUIS 返回包含得分最高意向“HRContact”的 JSON 格式的响应。LUIS returns a JSON-formatted response, with a top intent, "HRContact". JSON 终结点响应至少包含查询话语和得分最高的意向。The minimum JSON endpoint response contains the query utterance, and the top scoring intent. 它还可以提取数据,例如“联系人类型”实体。It can also extract data such as the Contact Type entity.
33 客户端应用程序根据 JSON 响应来决定如何处理用户的请求。The client application uses the JSON response to make decisions about how to fulfill the user's requests.

LUIS 应用提供的智能有助于客户端应用程序进行智能选择。The LUIS app provides intelligence so the client application can make smart choices. LUIS 不提供这些选择。LUIS doesn't provide those choices.

自然语言处理Natural language processing

LUIS 应用包含特定于域的自然语言模型,这些模型协同工作。Your LUIS app contains domain-specific natural language models, which work together. 可通过一个或多个预生成的模型启动 LUIS 应用、生成自己的模型,还可将预生成的模型与自己的自定义信息混合。You can start the LUIS app with one or more prebuilt models, build your own model, or blend prebuilt models with your own custom information.

  • 预生成的模型 LUIS 具有许多预生成的域,其中包括用于完成常见使用方案的意向和实体模型,这些意向和实体模型协同工作。Prebuilt model LUIS has many prebuilt domains that include intent and entity models that work together to complete common usage scenarios. 这些域包括可进行检查和编辑的已标记言语,让你能够对其进行自定义。These domains include labeled utterances that can be inspected and edited, allowing you to customize them. 预生成域模型为你提供了整个设计,是快速开始使用 LUIS 的好方法。Prebuilt domain models include the entire design for you and are a great way to start using LUIS quickly. 此外,还有一些预生成的实体,例如可独立于预生成的域使用的货币和数字。In addition, there are prebuilt entities such as currency and number that you can use independently from the prebuilt domains.

  • 自定义模型 LUIS 提供多种方法用于生成自己的自定义模型,包括意向和实体。Custom model LUIS gives you several ways to build your own custom models including intents, and entities. 实体包括机器习得实体、模式匹配实体,以及机器习得实体和模式匹配实体的组合。Entities include machine-learned entities, pattern matching entities, and a combination of machine-learned and pattern matching.

生成 LUIS 应用Build the LUIS app

使用创作 API 或 LUIS 门户生成应用。Build the app with the authoring APIs or with the LUIS portal.

LUIS 应用从称为 意向 的输入文本类别入手。The LUIS app begins with categories of input text called intents. 每个意向都需要用户 话语 的示例。Each intent needs examples of user utterances. 每个言语都可以提供需要提取的数据。Each utterance can provide data that needs to be extracted.

示例用户话语Example user utterance IntentIntent 提取的数据Extracted data
Book a flight to __Seattle__? BookFlightBookFlight 西雅图Seattle
When does your store __open__? 店铺营业时间和位置StoreHoursAndLocation 开门open
Schedule a meeting at __1pm__ with __Bob__ in Distribution 安排谈话ScheduleMeeting 下午 1 点,何石1pm, Bob

查询预测终结点Query prediction endpoint

在训练应用并将其发布到终结点以后,客户端应用程序会将言语发送到预测终结点 API。After your app is trained and published to the endpoint, the client application sends utterances to the prediction endpoint API. API 将应用程序应用到言语进行分析,并使用 JSON 格式的预测结果进行响应。The API applies the app to the utterance for analysis and responds with the prediction results in a JSON format.

JSON 终结点响应至少包含查询话语和得分最高的意向。The minimum JSON endpoint response contains the query utterance, and the top scoring intent. 它还可以提取数据,例如下面的“联系人类型” 实体和整体情绪。It can also extract data such as the following Contact Type entity and overall sentiment.

{
    "query": "I want to call my HR rep",
    "prediction": {
        "normalizedQuery": "i want to call my hr rep",
        "topIntent": "HRContact",
        "intents": {
            "HRContact": {
                "score": 0.8582669
            }
        },
        "entities": {
            "Contact Type": [
                "call"
            ]
        },
        "sentiment": {
            "label": "negative",
            "score": 0.103343368
        }
    }
}

改进模型预测Improve model prediction

发布 LUIS 应用并收到真实用户言语后,LUIS 提供终结点言语的主动学习以提高预测准确性。After your LUIS app is published and receives real user utterances, LUIS provides active learning of endpoint utterances to improve prediction accuracy.

迭代开发生命周期Iterative development lifecycle

LUIS 提供工具、版本控制以及与其他 LUIS 创建者的协作,以便集成到完整的迭代开发生命周期LUIS provides tools, versioning, and collaboration with other LUIS authors to integrate into the full iterative development life cycle.

实现 LUISImplementing LUIS

作为 REST API,语言理解 (LUIS) 可以与任何发送 HTTP 请求的产品、服务或框架配合使用。Language Understanding (LUIS), as a REST API, can be used with any product, service, or framework with an HTTP request. 以下列表包含与 LUIS 配合使用的顶级 Microsoft 产品和服务。The following list contains the top Microsoft products and services used with LUIS.

通过机器人快速轻松地使用 LUIS 的工具:Tools to quickly and easily use LUIS with a bot:

  • LUIS CLI:NPM 包以独立命令行工具或导入的形式提供创作和预测。LUIS CLI The NPM package provides authoring and prediction with as either a stand-alone command line tool or as import.
  • LUISGen:LUISGen 是一个用于从导出的 LUIS 模型生成强类型 C# 和 typescript 源代码的工具。LUISGen LUISGen is a tool for generating strongly typed C# and typescript source code from an exported LUIS model.
  • 启用调度时,可以使用调度程序模型通过父应用使用多个 LUIS 和 QnA Maker 应用。Dispatch allows several LUIS and QnA Maker apps to be used from a parent app using dispatcher model.
  • LUDown:LUDown 是一个命令行工具,可帮助你管理机器人的语言模型。LUDown LUDown is a command line tool that helps manage language models for your bot.

与 LUIS 配合使用的其他认知服务:Other Cognitive Services used with LUIS:

  • [QnA Maker][qnamaker] 可将多种类型的文本组合到一个问题答案知识库中。[QnA Maker][qnamaker] allows several types of text to combine into a question and answer knowledge base.

使用 LUIS 的示例:Samples using LUIS:

后续步骤Next steps

使用预生成域创作新的 LUIS 应用。Author a new LUIS app with a prebuilt domain. [flow]: https://docs.microsoft.com/connectors/luis/ [authoring-apis]: https://aka.ms/luis-authoring-api [endpoint-apis]: https://aka.ms/luis-endpoint-apis [qnamaker]: https://qnamaker.ai/