簡體   English   中英

如何使QnA制造商和Luis BOT集成在一起才能正常工作?

[英]How to get the integration of QnA maker and the Luis BOT to work accurately?

我面臨的問題是我正在遵循此文檔來集成LUIS和QnA制造商

https://docs.microsoft.com/zh-cn/azure/cognitive-services/qnamaker/tutorials/integrate-qnamaker-luis

而且我已經修改了FAQbot的代碼。 我有兩個意圖,一個是具有QnA制造商的FAQ意圖,另一個是意圖。 當我從FAQ意圖中在聊天機器人中提出問題時,它會給出准確的答復,而當我問一個完全不同的問題時,它也會進入另一個意圖。 但是,當我問另一個不在知識庫中但有幾個與現有問題類似的單詞的新問題時,它給了我一個答案,可以根據FAQ的意圖來預測它。 而不是其他意圖。 如何提高模型的准確性?

public class Metadata
{
    public string name { get; set; }
    public string value { get; set; }
}

public class Answer
{
    public IList<string> questions { get; set; }
    public string answer { get; set; }
    public double score { get; set; }
    public int id { get; set; }
    public string source { get; set; }
    public IList<object> keywords { get; set; }
    public IList<Metadata> metadata { get; set; }
}

public class QnAAnswer
{
    public IList<Answer> answers { get; set; }
}

[Serializable]
public class QnAMakerService
{
    private string qnaServiceHostName;
    private string knowledgeBaseId;
    private string endpointKey;

    public QnAMakerService(string hostName, string kbId, string endpointkey)
    {
        qnaServiceHostName = hostName;
        knowledgeBaseId = kbId;
        endpointKey = endpointkey;

    }
    async Task<string> Post(string uri, string body)
    {
        using (var client = new HttpClient())
        using (var request = new HttpRequestMessage())
        {
            request.Method = HttpMethod.Post;
            request.RequestUri = new Uri(uri);
            request.Content = new StringContent(body, Encoding.UTF8, "application/json");
            request.Headers.Add("Authorization", "EndpointKey " + endpointKey);

            var response = await client.SendAsync(request);
            return  await response.Content.ReadAsStringAsync();
        }
    }
    public async Task<string> GetAnswer(string question)
    {
        string uri = qnaServiceHostName + "/qnamaker/knowledgebases/" + knowledgeBaseId + "/generateAnswer";
        string questionJSON = "{\"question\": \"" + question.Replace("\"","'") +  "\"}";

        var response = await Post(uri, questionJSON);

        var answers = JsonConvert.DeserializeObject<QnAAnswer>(response);
        if (answers.answers.Count > 0)
        {
            return answers.answers[0].answer;
        }
        else
        {
            return "No good match found.";
        }
    }
}

[Serializable]
public class BasicLuisDialog : LuisDialog<object>
{
    // LUIS Settings
    static string LUIS_appId = "29e08438-43ae-40ab-8a77-7bb6474edd13";
    static string LUIS_apiKey = "95137566e76443019e26a653f99d7a0c";
    static string LUIS_hostRegion = "westus.api.cognitive.microsoft.com";

    // QnA Maker global settings
    // assumes all KBs are created with same Azure service
    static string qnamaker_endpointKey = "40dfaeb5-5679-4f8f-863f-a5f587101a88";
    static string qnamaker_endpointDomain = "azurebot123";

    // QnA Maker TA_FAQbot Knowledge base
    static string TA_FAQbot_kbID = "13fed287-64d7-43aa-9a39-2c6bc86ea511";


    // Instantiate the knowledge bases
    public QnAMakerService azurebot123QnAService = new QnAMakerService("https://" + qnamaker_endpointDomain + ".azurewebsites.net", TA_FAQbot_kbID, qnamaker_endpointKey);


    public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute(
        LUIS_appId,
        LUIS_apiKey,
        domain: LUIS_hostRegion)))
    {
    }

    [LuisIntent("None")]
    public async Task NoneIntent(IDialogContext context, LuisResult result)
    {
        HttpClient client = new HttpClient();
        await this.ShowLuisResult(context, result);
    }


    [LuisIntent("RandomFAQ")]
    public async Task RandomFAQIntent(IDialogContext context, LuisResult result)
    {
        HttpClient client = new HttpClient();
        await this.ShowLuisResult(context, result);
    }

    // TA_FAQbot Intent
    [LuisIntent("TA_FAQbot")]
    public async Task TA_FAQbotIntent(IDialogContext context, LuisResult result)
    {
        // Ask the FAQ knowledge base
        var qnaMakerAnswer = await azurebot123QnAService.GetAnswer(result.Query);
        await context.PostAsync($"{qnaMakerAnswer}");
        context.Wait(MessageReceived);
    }

    =
    private async Task ShowLuisResult(IDialogContext context, LuisResult result)
    {
        await context.PostAsync($"You have reached {result.Intents[0].Intent}. Sorry, I do not have the answer to this question. I will get back to you with an answer soon.");
        context.Wait(MessageReceived);

    }

          [LuisIntent("Cancel")]
          public async Task CancelIntent(IDialogContext context, LuisResult result)
          {
              await this.ShowLuisResult(context, result);
          }

          [LuisIntent("Help")]
          public async Task HelpIntent(IDialogContext context, LuisResult result)
       {
              await this.ShowLuisResult(context, result);
          }
}

當您計划構建LUIS模型時,請選擇良好的命名約定。 否則,當您從代碼中引用特定意圖時,這對您來說將很困難。

不要將太長的單詞用作意圖名稱。 只需使用簡短的描述性措詞。 使用駝峰式大小寫或點分隔的短語是一個好習慣

必須記住關於LUIS:

  1. 定義明確的意圖

確保每個意圖的詞匯表都是針對該意圖的,並且不與其他意圖重疊

  1. 確實找到意圖的最佳去處

使用來自LUIS的預測數據來確定您的意圖是否重疊。 重疊的意圖會使LUIS感到困惑。 結果是得分最高的意圖與另一個意圖過於接近。 因為LUIS不會每次都使用完全相同的數據路徑進行訓練,所以重疊的意圖有可能在訓練中排在第一或第二

  1. 平衡所有意圖的話語

為了使LUIS預測准確,每個意圖中的示例話語數量(無意圖除外)必須相對相等。

如果您的意圖有100個示例性話語,而意圖有20個示例性話語,則100個言語將具有更高的預測率

以下是對LUIS的一些注意事項:

在此處輸入圖片說明

注意:有關更多詳細信息,您可以參考此文檔

更新:

在此處輸入圖片說明

如果您還有任何疑問,請隨時發表評論。 謝謝,祝您編程愉快!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM