【问题标题】:How to get the predicted intent with confidence using agent rasa sdk chatbot如何使用代理 rasa sdk 聊天机器人自信地获得预测意图
【发布时间】:2021-08-02 07:52:58
【问题描述】:

我正在使用这个手动加载经过训练的 rasa 模型

agent = Agent.load(
                model,
                action_endpoint=EndpointConfig(ACTION_ENDPOINT)
            )

我正在预测这样的结果

botResponse = await agent.handle_text(query)

但这只是将响应作为文本返回,但我也需要信心和意图名称

我尝试了handle_message,但仍然没有信心。

【问题讨论】:

    标签: python chatbot rasa rasa-sdk


    【解决方案1】:

    您可以从Agenttracker_store 实例中检索此信息。为此,首先确保您在调用agent.handle_text(query, sender_id="some sender id") 时传递了发件人ID。然后检索跟踪器:

    current_tracker = agent.get_or_create_tracker(sender_id="some sender id")
    

    一旦你有了跟踪器,你就可以检索最后发送的消息的 NLU 解析数据:

    user_event = tracker.get_last_event_for(UserUttered)
    if user_event:
        nlu_parse_data = user_event.parse_data
    

    nlu_parse_data 应该如下所示:

    "text": "Hi MoodBot.",
            "parse_data": {
              "intent": {
                "id": 3068390702409455462,
                "name": "greet",
                "confidence": 0.9968197345733643
              },
              "entities": [],
              "text": "Hi MoodBot.",
              "message_id": "47efa155fc234abea554242883f0a74e",
              "metadata": {},
              "intent_ranking": [
                {
                  "id": 3068390702409455462,
                  "name": "greet",
                  "confidence": 0.9968197345733643
                },
                {
                  "id": -7997748339392136471,
                  "name": "bot_challenge",
                  "confidence": 0.0019184695556759834
                },
                {
                  "id": -3856210704443307570,
                  "name": "mood_unhappy",
                  "confidence": 0.0010514792520552874
                },
    

    【讨论】:

      【解决方案2】:

      我使用了两种不同的rasa api来实现同样的效果

      获取查询parse_message_using_nlu_interpreter的意图和置信度并获取响应handle_text

      queryResponseList = await agent.handle_text(query)
      intentInfo = await agent.parse_message_using_nlu_interpreter(query)
      intent = Intent(**{
                  "name": intentInfo["intent"]["name"],
                  "confidence": intentInfo["intent"]["confidence"]
              })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多