教學課程:建置 LUIS 應用程式來判斷使用者的用意Tutorial: Build LUIS app to determine user intentions

在本教學課程中,您會建立自訂人力資源 (HR) 應用程式,以根據語句 (文字) 預測使用者的用意。In this tutorial, you create a custom Human Resources (HR) 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 from endpoint

在本文中,您可以使用免費 LUIS 帳戶來撰寫 LUIS 應用程式。For this article, you can use the free LUIS account in order to author your LUIS application.

使用者用意成為意圖User intentions as intents

應用程式的目的是要判斷交談式自然語言文字的用意:The purpose of the app is to determine the intention of conversational, natural language text:

Are there any new positions in the Seattle office?

這些用意可歸類為各種意圖These intentions are categorized into Intents.

此應用程式有幾個意圖。This app has a few intents.

意圖Intent 目的Purpose
ApplyForJobApplyForJob 判斷使用者是否應徵工作。Determine if user is applying for a job.
GetJobInformationGetJobInformation 判斷使用者是否正在尋找有關一般工作或特定工作的資訊。Determine if user is looking for information about jobs in general or a specific job.
NoneNone 判斷使用者是否詢問應用程式不該回答的事項。Determine if user is asking something app is not supposed to answer. 此意圖是在應用程式建立過程中提供,且無法刪除。This intent if provided as part of app creation and can't be deleted.

建立新的應用程式Create a new app

  1. 使用 https://www.luis.ai 的 URL 登入 LUIS 入口網站。Sign in to the LUIS portal with the URL of https://www.luis.ai.

  2. 選取 [建立新的應用程式] 。Select Create new app.

    Language Understanding (LUIS) 我的應用程式 頁面的螢幕擷取畫面Screenshot of Language Understanding (LUIS) My Apps page

  3. 在快顯對話方塊中,輸入名稱 HumanResources,並保留預設文化特性 [英文] 。In the pop-up dialog, enter the name HumanResources and keep the default culture, English. 讓描述保留空白。Leave the description empty.

    建立 LUIS 的新 HumanResources 應用程式

  4. 選取 [完成] 。Select Done.

建立工作資訊的意圖Create intent for job information

  1. 選取 [Create new intent] (建立新意圖)。Select Create new intent. 輸入新的意圖名稱 GetJobInformationEnter the new intent name GetJobInformation. 當使用者想要公司內職缺的相關資訊時,系統就會預測此意圖。This intent is predicted when a user wants information about open jobs in the company.

    Language Understanding (LUIS) [新增意圖] 對話方塊的螢幕擷取畫面Screenshot of Language Understanding (LUIS) New intent dialog

  2. 選取 [完成] 。Select Done.

  3. 將您預期使用者會要求的數個範例語句新增至此意圖:Add several example utterances to this intent that you expect a user to ask:

    範例語句Example utterances
    今天是否有發佈任何新職位?Any new jobs posted today?
    西雅圖辦公室是否有任何新職位?Are there any new positions in the Seattle office?
    工程師是否有任何遠端工作者或遠距工作職缺?Are there any remote worker or telecommute jobs open for engineers?
    是否有資料庫方面的工作?Is there any work with databases?
    我正在尋找坦帕市 (Tampa) 辦公室的共同工作情況。I'm looking for a co-working situation in the tampa office.
    舊金山辦公室是否有實習職缺?Is there an internship in the san francisco office?
    是否有適合大專學生的兼職工作?Is there any part-time work for people in college?
    尋找會計職責方面的新局面Looking for a new situation with responsibilities in accounting
    尋找紐約市內適合雙話語者的工作。Looking for a job in new york city for bilingual speakers.
    尋找會計職責方面的新局面。Looking for a new situation with responsibilities in accounting.
    有新職位嗎?New jobs?
    為我顯示在最近 2 天新增的所有工程師相關工作。Show me all the jobs for engineers that were added in the last 2 days.
    今天發佈的工作?Today's job postings?
    倫敦辦公室有哪些會計職缺?What accounting positions are open in the london office?
    有哪些適合資深工程師的職位?What positions are available for Senior Engineers?
    職位清單在哪Where is the job listings

    針對 MyStore 意圖輸入新語句的螢幕擷取畫面Screenshot of entering new utterances for MyStore intent

    藉由提供_範例語句_,您可訓練 LUIS 應針對此意圖預測哪些種類的語句。By providing example utterances, you are training LUIS about what kinds of utterances should be predicted for this intent.

    這幾個語句僅供示範之用。These few utterances are for demonstration purposes only. 實際的應用程式應至少有 15 個具有不同長度、文字順序、時態、文法正確性、標點符號和字數的語句。A real-world app should have at least 15 utterances of varying length, word order, tense, grammatical correctness, punctuation, and word count.

將範例語句新增至 None 意圖Add example utterances to the None intent

用戶端應用程式必須知道語句是否對應用程式沒有意義或不適當。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 can'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.

警告

請勿將 None 意圖留空。Do not leave the None intent empty.

  1. 選取左面板中的 [意圖]。Select Intents from the left panel.

  2. 選取 [無] 意圖。Select the None intent. 新增您的使用者可能輸入但與您的人力資源應用程式無關的三個語句:Add three utterances that your user might enter but are not relevant to your Human Resources app:

    範例語句Example utterances
    狗一直叫很煩人Barking dogs are annoying
    幫我訂披薩Order a pizza for me
    海裡面的企鵝Penguins in the ocean

在測試或發佈之前訓練應用程式Train the app before testing or publishing

  1. 在 LUIS 網站的右上方,選取 [Train] (定型) 按鈕。In the top right side of the LUIS website, select the Train button.

    [Train] (定型) 按鈕

  2. 當您在網站頂端看到確認成功的綠色狀態列時,就表示定型完成。Training is complete when you see the green status bar at the top of the website confirming success.

    已定型狀態列

發佈應用程式以從端點進行查詢Publish the app to query from the endpoint

若要在聊天機器人或其他應用程式中收到 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 green status bar at the top of the website confirming success.

    LUIS 發佈到端點

  4. 選取綠色狀態列中的 [端點] 連結,以移至 [金鑰和端點] 頁面。Select the endpoints link in the green status bar to go to the Keys and endpoints page. 端點 URL 會列在底部。The endpoint URLs are listed at the bottom.

從端點取得意圖預測Get intent prediction from the endpoint

  1. 在 [管理] 區段 (右上方功能表) 的 [金鑰和端點] 頁面 (左側功能表) 中,選取頁面底部的端點 URL。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 another browser tab with the endpoint URL in the address bar.

    端點 URL 看起來像這樣:https://<region>.api.cognitive.microsoft.com/luis/v2.0/apps/<appID>?verbose=true&subscription-key=<YOUR_KEY>&<optional-name-value-pairs>&q=<user-utterance-text>The endpoint URL looks like https://<region>.api.cognitive.microsoft.com/luis/v2.0/apps/<appID>?verbose=true&subscription-key=<YOUR_KEY>&<optional-name-value-pairs>&q=<user-utterance-text>.

  2. 移至位址中的 URL 尾端並輸入 I'm looking for a job with Natural Language ProcessingGo to the end of the URL in the address bar and enter I'm looking for a job with Natural Language Processing. 最後一個查詢字串參數是 q,也就是語句查詢The last query string parameter is q, the utterance query. 此語句與所有範例語句不同。This utterance is not the same as any of the example utterances. 這是很好的測試,而且應傳回 GetJobInformation 意圖作為評分最高的意圖。It is a good test and should return the GetJobInformation intent as the top scoring intent.

    {
      "query": "I'm looking for a job with Natural Language Processing",
      "topScoringIntent": {
        "intent": "GetJobInformation",
        "score": 0.9923871
      },
      "intents": [
        {
          "intent": "GetJobInformation",
          "score": 0.9923871
        },
        {
          "intent": "None",
          "score": 0.007810574
        }
      ],
      "entities": []
    }
    

    verbose=true querystring 參數表示在應用程式的查詢結果中包含所有意圖The verbose=true querystring parameter means include all the intents in the app's query results. 實體陣列是空的,因為此應用程式目前沒有任何實體。The entities array is empty because this app currently does not have any entities.

    JSON 結果會將評分最高的意圖識別為 topScoringIntent 屬性。The JSON result identifies the top scoring intent as topScoringIntent property. 所有分數都介於 1 到 0,分數越好者越接近 1。All scores are between 1 and 0, with the better score being close to 1.

建立應徵工作的意圖Create intent for job applications

返回 LUIS 入口網站並建立新的意圖,以判斷使用者語句是否關於應徵工作。Return to the LUIS portal and create a new intent to determine if the user utterance is about applying for a job.

  1. 在右上方的功能表中選取 [建置],以返回應用程式建置。Select Build from the top, right menu to return to app building.

  2. 選取左功能表中的 [意圖],以取得意圖清單。Select Intents from the left menu to get to the list of intents.

  3. 選取 建立新意圖,然後輸入名稱 ApplyForJobSelect Create new intent and enter the name ApplyForJob.

    用來建立新意圖的 LUIS 對話方塊

  4. 將您預期使用者會要求的數個語句新增至意圖,例如:Add several utterances to this intent that you expect a user to ask for, such as:

    範例語句Example utterances
    填寫職位 123456 的應徵文件Fill out application for Job 123456
    這是我的履歷,Here is my c.v. 應徵的職位是 654234for position 654234
    以下是我應徵兼職接待員職位的履歷。Here is my resume for the part-time receptionist post.
    我要以此書面文件應徵美工內勤工作。I'm applying for the art desk job with this paperwork.
    我要應徵聖地牙哥研發中心的暑期大學實習工作I'm applying for the summer college internship in Research and Development in San Diego
    我請求將履歷提交至自助餐廳的臨時職位。I'm requesting to submit my resume to the temporary position in the cafeteria.
    我正在針對俄亥俄州哥倫布市的新汽車小組提交履歷I'm submitting my resume for the new Autocar team in Columbus, OH
    我想要應徵新的會計職位I want to apply for the new accounting job
    工作 456789 會計實習工作書面文件在此Job 456789 accounting internship paperwork is here
    職位 567890 和我的文件Job 567890 and my paperwork
    我已附上應徵土爾沙市 (Tulsa) 會計實習工作的文件。My papers for the tulsa accounting internship are attached.
    我用於應徵假日快遞職位的書面文件My paperwork for the holiday delivery position
    請針對西雅圖的新會計工作傳送我的履歷Please send my resume for the new accounting job in seattle
    投遞履歷以應徵工程師職缺Submit resume for engineering position
    這是我的履歷,This is my c.v. 針對坦帕市的職位 234123 投遞。for post 234123 in Tampa.

再次訓練Train again

  1. 在 LUIS 網站的右上方,選取 [Train] (定型) 按鈕。In the top right side of the LUIS website, select the Train button.

    [Train] (定型) 按鈕

  2. 當您在網站頂端看到確認成功的綠色狀態列時,就表示定型完成。Training is complete when you see the green status bar at the top of the website confirming success.

    已定型狀態列

再次發佈Publish again

若要在聊天機器人或其他應用程式中收到 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 green status bar at the top of the website confirming success.

    LUIS 發佈到端點

  4. 選取綠色狀態列中的 [端點] 連結,以移至 [金鑰和端點] 頁面。Select the endpoints link in the green status bar to go to the Keys and endpoints page. 端點 URL 會列在底部。The endpoint URLs are listed at the bottom.

再次取得意圖預測Get intent prediction again

  1. 在 [管理] 區段 (右上方功能表) 的 [金鑰和端點] 頁面 (左側功能表) 中,選取頁面底部的端點 URL。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 another browser tab with the endpoint URL in the address bar.

    端點 URL 看起來像這樣:https://<region>.api.cognitive.microsoft.com/luis/v2.0/apps/<appID>?verbose=true&subscription-key=<YOUR_KEY>&<optional-name-value-pairs>&q=<user-utterance-text>The endpoint URL looks like https://<region>.api.cognitive.microsoft.com/luis/v2.0/apps/<appID>?verbose=true&subscription-key=<YOUR_KEY>&<optional-name-value-pairs>&q=<user-utterance-text>.

  2. 在新的瀏覽器視窗中,於 URL 結尾輸入 Can I submit my resume for job 235986In the new browser window, enter Can I submit my resume for job 235986 at the end of the URL.

    {
      "query": "Can I submit my resume for job 235986",
      "topScoringIntent": {
        "intent": "ApplyForJob",
        "score": 0.9634406
      },
      "intents": [
        {
          "intent": "ApplyForJob",
          "score": 0.9634406
        },
        {
          "intent": "GetJobInformation",
          "score": 0.0171300638
        },
        {
          "intent": "None",
          "score": 0.00670867041
        }
      ],
      "entities": []
    }
    

    結果會包含新的意圖 ApplyForJob 以及現有意圖。The results include the new intent ApplyForJob as well as the existing intents.

用戶端應用程式的後續步驟Client-application next steps

在 LUIS 傳回 JSON 回應之後,隨著此要求完成 LUIS。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. Azure Bot 等用戶端應用程式會提供交談式後續追蹤。The conversational follow-up is provided by the client application such as an Azure Bot.

清除資源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. 在 [Delete app?] (刪除應用程式?) 快顯對話方塊上,選取 [Ok] (確定)。On the pop-up dialog Delete app?, select Ok.

後續步驟Next steps

本教學課程已在端點上建立人力資源 (HR) 應用程式、建立 2 個意圖、新增每個意圖的範例語句、進行訓練、發佈及測試。This tutorial created the Human Resources (HR) app, created 2 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.

繼續使用這個應用程式,新增簡單實體和片語清單Continue with this app, adding a simple entity and phrase list.