0%

LUIS - 微軟的 Nature Language Processing

Bot Composer 中使用 intent 與 entity

  1. 點擊 New Trigger 建立新的進入口

    截圖 2020-06-05 下午3.14.49

  2. 選取第一個選項 intent recognized

![截圖 2020-06-05 下午3.20.48](https://tva1.sinaimg.cn/large/007S8ZIlgy1gfhfv82b6vj31hd0q8n1z.jpg)
  1. 輸入 intent 名稱與 intent 的規則,例如下面這樣,然後按下 Submit 送出

    截圖 2020-06-05 下午3.24.32

  2. 送出之後應該會進入這個 intent 的編輯頁面,在這邊就可以設定如果 composer 判定說使用者的句子應該是符合這個 intent 的話要做什麼事,以我們的例子 問天氣 來看,這邊就可以去 call 天氣 api 並顯示給 user 看

    1. 輸入要進入這個 intent 的關鍵字清單

      截圖 2020-06-05 下午4.18.35

    2. 把流程設定好

      截圖 2020-06-05 下午4.20.22

    3. 在 emulator 上測試

      截圖 2020-06-05 下午4.23.28

  3. 如果要使用 Entity 來達到使用者可以直接問 xxx的天氣如何,可以在 intents 關鍵字清單中加入下面的內容

    1
    - {city = taina} 天氣如何?
    • city 代表的是這個位置的內容會被存到的變數名稱
    • = taina 的意思是輸入的內容大概會長得像怎樣
  4. 接著再訊問使用者城市名稱的的 user input 這個節點,把 value 填上 =@city ,這樣當使用者第一句話已經有包含城市名稱的時候,bot 就會跳過問城市名稱的階段直接 call api

    截圖 2020-06-05 下午4.53.18

  5. 這邊是實際演示的成果

    截圖 2020-06-05 下午4.56.38

Lu file

  • Dodcument here

  • Lu 檔案的寫法

  • 註解

    1
    > This is a comment and will be ignored
  • Intent

    • 表示使用者想要執行的動作,Intent 的目的是為了找出使用者輸入的內容中想要達成的目標,例如訂機票、付錢、找文章等等

    • Intent 的寫法

    • 使用 # <intent-name> 來宣告 intent 的名稱

    • 在下方可以使用 -,+,* 等符號來列出一個表達這個 intent 的清單

      1
      2
      3
      4
      5
      # Greeting
      - Hi
      - Hello
      - Good morning
      - Good evening
    • 多具不同的 intnet 是用# <intent-name> 來進行分割,空白列在 parsing 的時候會被忽略掉

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
          # Greeting
      - Hi
      - Hello
      - Good morning
      - Good evening

      # Help
      - help
      - I need help
      - please help
      ```

      * Entity

      * 使用 `@ <entity-type> <entity-name> [[hasRole[s]] <comma-separated-list-of-roles>] [hasFeature[s] <comma-separated-list-of-features>]` 來宣告 Entity

      * 使用 `@ <entity-name> = <definition>` 來定義 Entity

      * 宣告與定義可被寫在同一行

      @ [[hasRoles] ] =

      1
      2
      3
      4

      * entity-type,entity-name,definition 是必填的,roles 是選填的

      * 實際定義的範例如下

      @ ml “this is a simple entity” role1, role2
      @ ml ‘this is a simple entity’ hasRoles role1, role2

      1
      2
      3
      4

      * Machine-Learned Entity

      * Machine-Learned Entity 會從對話中學習,我們需要將 Machine-Learned Entity 放置在一句話中可能會出現的位置,例如今天我想要利用 ML-Entity 來詢問使用者的訊息,可以將 ML-Entity 定義成下方這樣
          # getUserName
          - my name is {username=vishwac}
      
          > Without an explicit entity definition, 'userName' defaults to 'ml' entity type.
      ```
      • 藉由上方這樣的定義,我們不需明確定義出 my name is xxx 才能設定條件