為您的 QnA Maker 知識庫建立自訂的同義字清單Create customized lists of synonyms for your QnA Maker knowledge base

適用于: SDK v4APPLIES TO: SDK v4

Bot Framework CLI 可讓您將 QnA Maker 知識庫的管理自動化。The Bot Framework CLI lets you automate the management of QnA Maker knowledge bases. 它可讓您從命令列或腳本建立、更新和刪除 QnA Maker 知識庫 (KB) 。It lets you create, update, and delete a QnA Maker knowledge base (KB) from the command line or a script. 它也可讓您建立適用于 KB 的同義字清單。It also enables you to create a list of synonyms that applies to your KB. 本文說明如何使用 CLI 變更 命令來建立 QnA Maker KB 的同義字。This article explains how to create synonyms for your QnA Maker KB using the CLI alterations command.

必要條件Prerequisites

QnA Maker 變更的簡介An introduction to alterations in QnA Maker

[變更] 命令可讓您將自訂的同義字清單匯入 QnA Maker KB。The alterations command lets you import customized lists of synonyms into your QnA Maker KB. 變更是具有相同意義的單字清單。Alterations are a list of words that have the same meaning. 例如,"禮物" 這個字的同義字可能是 "現在時" 這個字。For example, a synonym for the word "gift" could be the word "present".

變更也適用于縮寫。Alterations can be very useful for abbreviations as well. 例如,"GDPR" 是廣泛使用的詞彙,但有些人可能會將它稱為「平均」,也就是荷蘭文的縮寫。For example "GDPR" is a widely used term, but some people might call it "AVG", which is the Dutch abbreviation. 公司通常會有各自獨特的縮寫清單,這些縮寫參考其產品提供的不同功能或元件。Companies often have their own unique list of abbreviations referring to different features or components that their products offer.

雖然 QnA Maker 已經有幾種語言的常見預先定型同義字的內部清單,但是許多公司仍可受益于擁有額外的同義字。While QnA Maker already has their own internal list of common pre-trained synonyms in several languages, many companies can still benefit from having additional synonyms.

改變也有助於改善您的知識庫品質,同時減少問答組的數目以及定型所需的時間。Alterations can also help improve the quality of your KB while reducing the number of question/answer pairs as well as the time needed to train it.

提示

您無法使用 QnA Maker 入口網站來建立自訂的同義字清單,不過它可以使用 Bot Framework CLI 來提供。It's not possible to create customized lists of synonyms using the QnA Maker portal, however it is available using the Bot Framework CLI.

安裝 Bot Framework SDK CLIInstall the Bot Framework SDK CLI

如果您已安裝 Bot Framework CLI,您可以直接跳到 使用 QNAMAKER CLI 命令,以建立 QnA Maker 知識庫的同義字清單If you have already installed the Bot Framework CLI you can skip ahead to Use the qnamaker CLI commands to create a list of synonyms for your QnA Maker knowledge base.

Bot Framework CLI 需要 Node.jsBot Framework CLI requires Node.js.

  1. 請確定您已安裝最新版的 npm:Make sure you have the latest version of npm installed:

    npm i -g npm
    
  2. 使用 Node.js,從命令列安裝最新版本的 Bot Framework CLI。Using Node.js, install the latest version of Bot Framework CLI from the command line.

    npm i -g @microsoft/botframework-cli
    

如需詳細資訊,請參閱 BOT FRAMEWORK CLI 工具For more information, see Bot Framework CLI tool.

使用 qnamaker CLI 命令來建立 QnA Maker 知識庫的同義字清單Use the qnamaker CLI commands to create a list of synonyms for your QnA Maker knowledge base

當您 建立 QnA Maker 模型時,會建立兩個 JSON 檔案:名為 converted.jsQnAMaker 模型,以及名為 alterations_converted.js變更 檔。When you create your QnA Maker model two JSON files are created: the QnAMaker model, which is named converted.json, and the alterations file, which is named alterations_converted.json. 雖然 QnAMaker 模型包含您專案中所有 qna 檔案的資料,全都結合成可形成單一檔案,但變更檔案只會包含空的變更清單,如下所示:While the QnAMaker model contains the data from all the .qna files in your project, all combined to form a single file, the alterations file contains only an empty alterations list, as shown below:

{
  "wordAlterations": []
}

您不需要使用 CLI 命令建立您的 QnA Maker 模型或 KB,即可使用 [變更] 命令來建立同義字清單,但是這樣做會建立文字更改檔案。You don't have to create your QnA Maker model or KB using CLI commands in order to use the alterations commands to create your list of synonyms, but doing so does create the word alterations file.

變更檔案是包含 wordAlterations 陣列的 JSON 檔案,其中包含一組 改變,也 就是同義字的清單,例如:The alterations file is a JSON file that contains an array of wordAlterations which consists of an array of alterations, which is a list of synonyms, for example:

{
  "wordAlterations": [
    {
      "alterations": [
        "qnamaker",
        "qna maker"
      ]
    },
    {
      "alterations": [
        "botframework",
        "bot framework"
      ]
    },
    {
      "alterations": [
        "bot framework command line interface",
        "bot framework cli",
        "bf cli"
      ]
    }
  ]
}

一旦建立了變更檔案,您可以將其傳遞至 qnamaker:alterations:replace 命令做為 input 屬性,以取代建立 QnA Maker KB 時預設建立的空白變更清單。Once the alterations file is created, you can pass it to the qnamaker:alterations:replace command as the input property to replace the empty alterations list created by default when creating the QnA Maker KB. 每當您需要更新現有的清單時,就會使用相同的命令。You'll use the same command anytime you need to update the existing list.

bf qnamaker:alterations:replace -i <input-file-name>

如果您沒有 init檔案,您將需要包含訂用帳戶金鑰:If you don't have an init file, you will need to include the subscription key:

bf qnamaker:alterations:replace -i <input-file-name> --subscriptionKey <Subscription-Key>

重要

您無法在 Azure 中以累加方式新增或移除變更清單中的專案。You cannot incrementally add or remove items from the list of alterations in Azure. 當您執行「變更取代」命令時,會刪除 azure 中的變更清單,並將其取代為傳入的檔案。When you run the alterations replace command, the alterations list in azure is deleted and replaced with the file passed in.

如需使用此命令的詳細資訊,請參閱 bf qnamaker:alterations:replace BF CLI QNA MAKER 讀我檔案中的。For additional information on using this command, see bf qnamaker:alterations:replace in the BF CLI QnA Maker README.

下載 QnA Maker 知識庫中的變更清單Download the list of alterations in your QnA Maker knowledge base

如果您需要查看 QnA Maker KB 中的同義字,可以使用 qnamaker:alterations:list 命令。If you need to see what synonyms are in your QnA Maker KB, you can use the qnamaker:alterations:list command.

bf qnamaker:alterations:list

如果您沒有 init檔案,您將需要包含訂用帳戶金鑰:If you don't have an init file, you will need to include the subscription key:

 `bf qnamaker:alterations:list --subscriptionKey <Subscription-Key>`

如需使用此命令的詳細資訊,請參閱 bf qnamaker:alterations:list BF CLI QNA MAKER 讀我檔案中的。For additional information on using this command, see bf qnamaker:alterations:list in the BF CLI QnA Maker README.

更新 QnA Maker 知識庫中的變更清單Update the list of alterations in your QnA Maker knowledge base

雖然沒有任何命令可直接更新 QnA Maker 中的現有變更清單,但您可以 使用變異 清單 命令 下載變更清單、進行必要的修改,然後使用新的清單取代您在 Azure 中的變更清單。While there is no command to directly update an existing alterations list in QnA Maker, you can use the alterations list command to download the alterations list, make needed modifications, and then using that new list replace your alterations list in Azure.

  1. 使用命令取得目前的變更清單 bf qnamaker:alterations:listGet the current list of alterations using the command bf qnamaker:alterations:list

    提示

    您可以使用管線命令(例如 DOS 命令)將結果直接傳送到檔案 >You can send the results directly to a file using a piping command such as the DOS > command. 下列範例會在目前目錄中建立名為 alterations_converted.js 的檔案:The following example will create a file named alterations_converted.json in the current directory:

    bf qnamaker:alterations:list >alterations_converted.json

  2. 對 JSON 檔案進行任何所需的更新,然後儲存這些變更。Make any desired updates to the JSON file then save those changes.

  3. 使用下列命令來取代 QnA Maker KB 中的變更清單: bf qnamaker:alterations:replace -i <input-file-name>Replace the alterations list that is in your QnA Maker KB using the command: bf qnamaker:alterations:replace -i <input-file-name>. 如果您在目前的目錄中將變更清單 JSON 檔案儲存為 alterations_converted.json ,此命令將會是: bf qnamaker:alterations:replace -i alterations_converted.jsonIf you saved the alterations list JSON file as alterations_converted.json in the current directory, the command will be: bf qnamaker:alterations:replace -i alterations_converted.json