在预测运行时扩展应用Extend app at prediction runtime

应用的架构(模型和功能)经过训练后将发布到预测终结点。The app's schema (models and features) is trained and published to the prediction endpoint. 此发布的模型用于预测运行时。This published model is used on the prediction runtime. 可以将新信息以及用户的言语传递到预测运行时以增加预测。You can pass new information, along with the user's utterance, to the prediction runtime to augment the prediction.

预测运行时架构的两个更改包括:Two prediction runtime schema changes include:

外部实体External entities

外部实体可让 LUIS 应用在运行时识别和标记实体,这些实体可用作现有实体的特征。External entities give your LUIS app the ability to identify and label entities during runtime, which can be used as features to existing entities. 这样,在将查询发送到预测终结点之前,便可以使用自己的独立自定义实体提取器。This allows you to use your own separate and custom entity extractors before sending queries to your prediction endpoint. 此操作是在查询预测终结点上执行的,因此不需要重新训练并发布模型。Because this is done at the query prediction endpoint, you don't need to retrain and publish your model.

客户端应用程序将提供其自身的实体提取器,它会管理实体匹配操作并确定匹配实体的言语中的位置,然后连同请求一起发送该信息。The client-application is providing its own entity extractor by managing entity matching and determining the location within the utterance of that matched entity and then sending that information with the request.

外部实体是用于扩展任何实体类型,同时仍可用作其他模型的信号的机制。External entities are the mechanism for extending any entity type while still being used as signals to other models.

这对于仅在查询预测运行时才提供数据的实体而言非常有用。This is useful for an entity that has data available only at query prediction runtime. 此类数据的示例包括不断变化的数据,或者每个用户的具体数据。Examples of this type of data are constantly changing data or specific per user. 可以使用用户联系人列表中的外部信息扩展 LUIS 联系人实体。You can extend a LUIS contact entity with external information from a user's contact list.

外部实体是 V3 创作 API 的一部分。External entities are part of the V3 authoring API. 详细了解如何迁移到此版本。Learn more about migrating to this version.

实体已在应用中存在Entity already exists in app

发出请求时,在终结点请求 POST 正文中传递的外部实体 entityName 值必须事先在已训练且发布的应用中存在。The value of entityName for the external entity, passed in the endpoint request POST body, must already exist in the trained and published app at the time the request is made. 实体的类型无关紧要,因为支持所有类型。The type of entity doesn't matter, all types are supported.

聊天中的第一个轮次First turn in conversation

假设在聊天机器人的第一段聊天言语中,用户输入了以下不完整的信息:Consider a first utterance in a chat bot conversation where a user enters the following incomplete information:

Send Hazem a new message

聊天机器人发送给 LUIS 的请求可以在 POST 正文中传入有关 Hazem 的信息,以便将此信息直接匹配为用户的联系人之一。The request from the chat bot to LUIS can pass in information in the POST body about Hazem so it is directly matched as one of the user's contacts.

    "externalEntities": [
        {
            "entityName":"contacts",
            "startIndex": 5,
            "entityLength": 5,
            "resolution": {
                "employeeID": "05013",
                "preferredContactType": "TeamsChat"
            }
        }
    ]

预测响应包含该外部实体以及其他所有预测实体,因为该实体已在请求中定义。The prediction response includes that external entity, with all the other predicted entities, because it is defined in the request.

聊天中的第二个轮次Second turn in conversation

在聊天机器人中输入的下一段用户言语使用较模糊的字词:The next user utterance into the chat bot uses a more vague term:

Send him a calendar reminder for the party.

在这一轮会话中,言语使用 him 作为对 Hazem 的引用。In this turn of the conversation, the utterance uses him as a reference to Hazem. 在 POST 正文中,聊天机器人可将 him 映射到从第一段言语 Hazem 提取的实体值。The conversational chat bot, in the POST body, can map him to the entity value extracted from the first utterance, Hazem.

    "externalEntities": [
        {
            "entityName":"contacts",
            "startIndex": 5,
            "entityLength": 3,
            "resolution": {
                "employeeID": "05013",
                "preferredContactType": "TeamsChat"
            }
        }
    ]

预测响应包含该外部实体以及其他所有预测实体,因为该实体已在请求中定义。The prediction response includes that external entity, with all the other predicted entities, because it is defined in the request.

重写现有模型预测Override existing model predictions

preferExternalEntities 选项属性指定如果用户发送与同名的预测实体重叠的外部实体,LUIS 将选择传入的实体还是模型中存在的实体。The preferExternalEntities options property specifies that if the user sends an external entity that overlaps with a predicted entity with the same name, LUIS chooses the entity passed in or the entity existing in the model.

例如,考虑查询 today I'm freeFor example, consider the query today I'm free. LUIS 检测到 today 为 datetimeV2,响应如下:LUIS detects today as a datetimeV2 with the following response:

"datetimeV2": [
    {
        "type": "date",
        "values": [
            {
                "timex": "2019-06-21",
                "value": "2019-06-21"
            }
        ]
    }
]

如果用户发送外部实体:If the user sends the external entity:

{
    "entityName": "datetimeV2",
    "startIndex": 0,
    "entityLength": 5,
    "resolution": {
        "date": "2019-06-21"
    }
}

如果 preferExternalEntities 设置为 false,则 LUIS 将返回响应就像未发送外部实体一样。If the preferExternalEntities is set to false, LUIS returns a response as if the external entity were not sent.

"datetimeV2": [
    {
        "type": "date",
        "values": [
            {
                "timex": "2019-06-21",
                "value": "2019-06-21"
            }
        ]
    }
]

如果 preferExternalEntities 设置为 true,则 LUIS 将返回包括以下内容的响应:If the preferExternalEntities is set to true, LUIS returns a response including:

"datetimeV2": [
    {
        "date": "2019-06-21"
    }
]

解决方法Resolution

可选的 resolution 属性将在预测响应中返回,可让你传入与外部实体关联的元数据,然后在响应中接收该元数据。The optional resolution property returns in the prediction response, allowing you to pass in the metadata associated with the external entity, then receive it back out in the response.

主要目的是扩展预生成实体,但并不局限于该实体类型。The primary purpose is to extend prebuilt entities but it is not limited to that entity type.

resolution 属性可以是数字、字符串、对象或数组:The resolution property can be a number, a string, an object, or an array:

  • "Dallas""Dallas"
  • {"text": "value"}{"text": "value"}
  • 1234512345
  • ["a", "b", "c"]["a", "b", "c"]

动态列表Dynamic lists

使用动态列表可以扩展已包含在 LUIS 应用中的已训练并发布的现有列表实体。Dynamic lists allow you to extend an existing trained and published list entity, already in the LUIS app.

需要定期更改列表实体值时,请使用此功能。Use this feature when your list entity values need to change periodically. 使用此功能可以扩展已训练并发布的列表实体:This feature allows you to extend an already trained and published list entity:

  • 发出查询预测终结点请求时。At the time of the query prediction endpoint request.
  • 对于单个请求。For a single request.

列表实体在 LUIS 应用中可为空,但必须存在。The list entity can be empty in the LUIS app but it has to exist. LUIS 应用中的列表实体不会更改,但终结点上的预测功能将会扩展,以最多包含 2 个列表,其中有大约 1,000 个项。The list entity in the LUIS app isn't changed, but the prediction ability at the endpoint is extended to include up to 2 lists with about 1,000 items.

动态列表 JSON 请求正文Dynamic list JSON request body

发送以下 JSON 正文,以向列表发送包含同义词的新子列表,并使用 POST 查询预测请求预测文本 LUIS 的列表实体:Send in the following JSON body to add a new sublist with synonyms to the list, and predict the list entity for the text, LUIS, with the POST query prediction request:

{
    "query": "Send Hazem a message to add an item to the meeting agenda about LUIS.",
    "options":{
        "timezoneOffset": "-8:00"
    },
    "dynamicLists": [
        {
            "listEntity*":"ProductList",
            "requestLists":[
                {
                    "name": "Azure Cognitive Services",
                    "canonicalForm": "Azure-Cognitive-Services",
                    "synonyms":[
                        "language understanding",
                        "luis",
                        "qna maker"
                    ]
                }
            ]
        }
    ]
}

预测响应包含该列表实体以及其他所有预测实体,因为该实体已在请求中定义。The prediction response includes that list entity, with all the other predicted entities, because it is defined in the request.

后续步骤Next steps