Language UnderstandingLanguage Understanding


Bot 可以使用各種對話風格,從結構化和引導式到自由形式和開放式。Bots can use a variety of conversational styles, from the structured and guided to the free-form and open-ended. Bot 需要根據使用者的談話內容來決定在對話流程中下一步該做什麼,而在開放式對話中,使用者的回覆還有更多可能。A bot needs to decide what to do next in its conversation flow, based on what the user said, and in an open-ended conversation, there is a wider range of user replies.

引導式Guided 開啟Open
我是旅遊 Bot。I'm the travel bot. 請選取下列選項之一:尋找班機、尋找旅館、尋找租車。Select one of the following options: find flights, find hotels, find rental car. 我可以協助您預訂旅遊行程。I can help you book travel. 您要執行什麼動作?What would you like to do?
您還需要其他項目嗎?Do you need anything else? 請按一下 [是] 或 [否]。Click yes or no. 您還需要其他項目嗎?Do you need anything else?

使用者與 Bot 通常會以自由形式進行互動,因此 Bot 需要了解自然語言及與內容相關的語言。The interaction between users and bots is often free-form, and bots need to understand language naturally and contextually. 這篇文章說明 Language Understanding (LUIS) 如何幫助您判斷使用者想要什麼、識別句子中的概念和實體,最終讓您的 Bot 以適當的動作來回應。This article explains how Language Understanding (LUIS) help you to determine what users want, to identify concepts and entities in sentences, and ultimately to allow your bots to respond with the appropriate action.

辨識意圖Recognize intent

LUIS 可協助您判斷使用者的 意圖,也就是他們所說的意思,讓您的 bot 可以適當地回應。LUIS helps you by determining the user's intent, which is what they want to do, from what they say, so your bot can respond appropriately. 當使用者對 bot 所說的內容不符合可預測的結構或特定模式時,LUIS 特別有用。LUIS is especially helpful when what they say to your bot doesn't follow a predictable structure or a specific pattern. 如果 Bot 擁有對話式使用者介面,使用者可在其中說話或輸入回應,「語句」 可能會有無數的變化 (語句是使用者的口語或文字輸入)。If a bot has a conversational user interface, in which the user speaks or types a response, there can be endless variations on utterances, which are the spoken or textual input from the user.

例如,設想旅遊 Bot 的使用者要求預訂班機可使用的許多表達方法。For example, consider the many ways a user of a travel bot can ask to book a flight.


這些語句可以有不同的結構,並且包含您未想像的各種「航班」同義字。These utterances can have different structures and contain various synonyms for "flight" that you haven't thought of. 對 Bot 而言,撰寫符合所有語句的邏輯,並與其他包含相同字組的意圖區別開來十分困難。In your bot, it can be challenging to write the logic that matches all the utterances, and still distinguishes them from other intents that contain the same words. 此外,Bot 必須擷取「實體」 ,也就是其他重要的字組,例如位置和時間。Additionally, your bot needs to extract entities, which are other important words like locations and times. LUIS 可在內容中為您識別意圖和實體,以簡化此程序。LUIS makes this process easy by contextually identifying intents and entities for you.

當您設計用於自然語言輸入的 Bot 時,您要判斷 Bot 必須辨識哪些意圖和實體,並思考其如何連接到 Bot 所採取的動作。When you design your bot for natural language input, you determine what intents and entities your bot needs to recognize, and think about how they'll connect to actions that your bot takes. (英文) 中,藉由為每個意圖提供範例,並標記其中的實體,您可以定義自訂意圖和實體並指定其行為。In, you define custom intents and entities and you specify their behavior by providing examples for each intent and labeling the entities within them.

Bot 會使用由 LUIS 辨識的意圖來判斷對話主題,或開始對話流程。Your bot uses the intent recognized by LUIS to determine the conversation topic, or begin a conversation flow. 例如,當使用者說:「我想要預訂班機」,Bot 會偵測到 BookFlight 意圖,並叫用開始搜尋航班的對話流程。For example, when a user says "I'd like to book a flight", your bot detects the BookFlight intent and invokes the conversation flow for starting a search for flights. LUIS 會在觸發意圖的原始語句以及在對話流程中,偵測目的地城市和起飛日期等實體。LUIS detects entities like the destination city and the departure date, both in the original utterance that triggers the intent and later in the conversation flow. 當 Bot 擁有所需的所有資訊後,就可以滿足使用者意圖。Once the bot has all the information it needs, it can fulfill the user's intent.

由 BookFlight 意圖觸發與 Bot 的對話

在常見案例中辨識意圖Recognize intent in common scenarios

為了節省開發時間,LUIS 提供預先訓練的語言模型,可辨識 Bot 常見類別的常見語句。To save development time, LUIS provides pre-trained language models that recognize common utterances for common categories of bots.

預先建置的領域 是預先訓練且已就緒可供使用的意圖和實體集合,可搭配用於常見案例,如約會、提醒、管理、保健、娛樂、通訊、預約等。Prebuilt domains are pre-trained, ready-to-use collections of intents and entities that work well together for common scenarios like appointments, reminders, management, fitness, entertainment, communication, reservations, and more. 公用程式 預先建置領域可協助 Bot 處理一般工作,如取消、確認、說明、重複、及停止。The Utilities prebuilt domain helps your bot handle common tasks like Cancel, Confirm, Help, Repeat, and Stop. 查看 LUIS 提供的預先建置的網域Take a look at the prebuilt domains that LUIS offers.

預先建置的實體 可協助 Bot 辨識常見類型的資訊,例如日期、時間、數字、溫度、貨幣、地理和年齡。Prebuilt entities help your bot recognize common types of information like dates, times, numbers, temperature, currency, geography, and age. 請參閱使用預先建置的實體,了解 LUIS 可辨識的類型背景資訊。See use prebuilt entities for background on the types that LUIS can recognize.

您的 Bot 如何從 LUIS 取得訊息How your bot gets messages from LUIS

一旦您已設定 LUIS 並與之連線,您的 Bot 就可以傳送訊息給 LUIS 應用程式,以傳回包含意圖和實體的 JSON 回應。Once you have set up and connected LUIS, your bot can send the message to your LUIS app, which returns a JSON response that contains the intents and entities. 然後,您可以使用 Bot 回合處理常式 中的 回合內容,根據 LUIS 回應中的意圖來路由傳送對話流程。Then, you can use the turn context in your bot's turn handler to route the conversation flow based on the intent in the LUIS response.

意圖和實體如何傳遞至您的 Bot

若要開始搭配使用 LUIS 應用程式與 Bot,請參閱使用 LUIS 理解語言To get started using a LUIS app with your bot, check out using LUIS for language understanding.

Language Understanding 的最佳做法Best practices for Language Understanding

為您的 Bot 設計語言模型時,請考慮下列做法。Consider the following practices when designing a language model for your bot.

考慮意圖數目Consider the number of intents

LUIS 應用程式會將語句分類成多個類別以辨識意圖。LUIS apps recognize intent by classifying an utterance into one of multiple categories. 結果自然是,要從一大堆意圖中判斷正確類別,可能會降低 LUIS 應用程式區分意圖的能力。A natural result is that determining the correct category from among a large number of intents can reduce a LUIS app's ability to distinguish between them.

減少意圖數目的其中一種方法是使用階層式設計。One way of reducing the number of intents is to use a hierarchical design. 想像個人助理 Bot 的情況,它有三個與天氣相關的意圖、三個與居家自動化相關的意圖,以及三個其他公用程式的意圖,分別是說明、取消和問候。Consider the case of a personal assistant bot that has three intents related to weather, three intents related to home automation, and three other utility intents which are Help, Cancel and Greeting. 如果您將所有意圖放在同一 LUIS 應用程式中,就有 9 個意圖,而當您將功能新增到 Bot 時,就會有數十個意圖。If you put all the intents in the same LUIS app, you already have 9, and as you add features to the bot, you could end up with dozens. 因此,您可以使用發送器 LUIS 應用程式,判斷使用者的要求是針對天氣、居家自動化或公用程式,然後針對發送器決定的類別呼叫 LUIS 應用程式。Instead, you can use a dispatcher LUIS app to determine whether the user's request is for weather, home automation, or utility, then call the LUIS app for the category that the dispatcher determines. 在此情況下,每個 LUIS 應用程式只會從 3 個意圖開始。In this case each of the LUIS apps only starts with 3 intents.

使用 None 意圖Use a None intent

通常情況是 Bot 的使用者會說出非預期或與目前對話流程不相關的內容。It's often the case that users of your bot will say something unexpected or unrelated to the current conversation flow. None 意圖即是用來處理這些訊息。The None intent is provided for handling those messages.

如果您未訓練意圖來處理後援、預設或「非上述之一」的情況,LUIS 應用程式只能將訊息分類到已定義的意圖中。If you don't train an intent for handling the fallback, default or "none of the above" cases, your LUIS app can only classify messages into the intents it has defined. 比方說,假設您的 LUIS 應用程式具有兩個意圖:HomeAutomation.TurnOnHomeAutomation.TurnOffSo for example, let's say you have a LUIS app with two intents: HomeAutomation.TurnOn and HomeAutomation.TurnOff. 如果這些是僅有的意圖,而輸入是像「安排星期五的約會」等無關項目,您的 LUIS 應用程式仍必須將該訊息分類為 HomeAutomation.TurnOn 或 HomeAutomation.TurnOff。If those are the only intents, and the input is something unrelated like "schedule an appointment on Friday", your LUIS app has no choice but to classify that message as either HomeAutomation.TurnOn or HomeAutomation.TurnOff. 如果您的 LUIS 應用程式有一些 None 意圖的範例,您可以在 Bot 中提供一些後援邏輯來處理非預期的語句。If your LUIS app has a None intent with a few examples, you can provide some fallback logic in your bot to handle unexpected utterances.

None 意圖對於改善辨識結果非常有用。The None intent is very useful for improving recognition results. 在此居家自動化案例中,「在星期五安排約會」可能會產生信心較低的 HomeAutomation.TurnOn 意圖,而您的 Bot 應該會加以拒絕。In this home automation scenario, "schedule an appointment on Friday" may produce the HomeAutomation.TurnOn intent with a low confidence, and your bot should reject it. 您可以將這類詞組新增至您模型的 None 意圖之下,使其正確地解析為 NoneYou can add such phrases to your model under the None intent, so that they resolve correctly to None.

檢閱 LUIS 應用程式收到的語句Review the utterances that LUIS app receives

LUIS 應用程式提供功能,可藉由檢閱使用者傳送的訊息,改善應用程式效能。LUIS apps provide a feature for improving your app performance, by reviewing messages that users sent to it. 請參閱建議語句的逐步解說。See suggested utterances for a step-by-step walkthrough.

使用分派工具整合多個 LUIS 應用程式和 QnA 服務Integrate multiple LUIS apps and QnA services with the Dispatch tool

建置可了解多個對話主題的多用途 Bot 時,您可以開始分別為每個功能開發服務,然後將其整合在一起。When building a multi-purpose bot that understands multiple conversational topics, you can start to develop services for each function separately, and then integrate them together. 這些服務可包括 Language Understanding (LUIS) 應用程式和 QnAMaker 服務。These services can include Language Understanding (LUIS) apps and QnAMaker services. 以下是一些範例案例,其中 Bot 可能會結合多個 LUIS 應用程式、多個 QnAMaker 服務或兩者的組合:Here are a few example scenarios in which a bot might combine multiple LUIS apps, multiple QnAMaker services or a combination of the two:

  • 個人助理 Bot 可讓使用者叫用各種命令。A personal assistant bot lets the user invoke a variety of commands. 每個類別的命令會形成可個別開發的「技能」,且每項技能都具有 LUIS 應用程式。Each category of commands form a "skill" that can be developed separately, and each skill has a LUIS app.
  • Bot 會搜尋許多知識庫來尋找常見問題集 (FAQ) 的解答。A bot searches many knowledge bases to find answers to frequently asked questions (FAQs).
  • 用於企業的 Bot 擁有可建立客戶帳戶和下訂單的 LUIS 應用程式,也有針對常見問題集的 QnAMaker 服務。A bot for a business has LUIS apps for creating customer accounts and placing orders, and also has a QnAMaker service for its FAQ.

分派工具The Dispatch tool

分派工具可透過建立「分派應用程式」 (這是新的 LUIS 應用程式,可將訊息路由傳送至適當的 LUIS 和 QnAMaker 服務),協助您將多個 LUIS 應用程式和 QnA Maker 服務與您的 Bot 整合。The Dispatch tool helps you integrate multiple LUIS apps and QnA Maker services with your bot, by creating a dispatch app, which is a new LUIS app that routes messages to the appropriate LUIS and QnAMaker services. 請參閱分派教學課程,取得在一個 Bot 中結合多個 LUIS 應用程式和 QnA Maker 的逐步教學。See the dispatch tutorial for a step-by-step tutorial that combines multiple LUIS apps and QnA Maker in one bot.

使用 LUIS 改善語音辨識Use LUIS to improve speech recognition

對於使用者會與其對話的 Bot,與 LUIS 整合可協助 Bot 識別從語音轉換文字時可能會遭誤解的字組。For a bot that users will speak to, integrating it with LUIS can help your bot identify words that might be misunderstood when converting speech to text. 例如,在西洋棋的情境中,使用者可能會說:「騎士移動到 A 7 (Move knight to A 7)」。For example, in a chess scenario, a user might say: "Move knight to A 7". 若沒有使用者意圖的背景,該語句可能會識別為:「移動晚上 287 (Move night 287)」。Without context for the user's intent, the utterance might be recognized as: "Move night 287". 藉由建立代表西洋棋和座標的實體,並將其標記在語句中,您可以提供語音辨識的背景來識別它們。By creating entities that represent chess pieces and coordinates and labeling them in utterances, you provide context for speech recognition to identify them.

其他資源Additional resources

如需詳細資訊,請參閱認知服務文件。Refer to Cognitive Services documentation for more information.