首页 > 解决方案 > rasa nlu 后备是返回意图而不是问题

问题描述

我正在使用 rasa(第 2 版),并通过此配置集成了FallbackClassifier.

但这会返回意图名称,而不是任何带有是和否按钮的问题。如果我按是,那么它会向用户提问

Did you mean intent_name

谈话是这样进行的

在此处输入图像描述

它应该显示问题,而不是显示 intent_name。我错过了什么吗?

在控制台上

ERROR    rasa_sdk.endpoint  - No registered action found for 
name 'action_default_fallback'.

标签: pythonrasarasa-x

解决方案


在后备策略中,rasa 显示最可能意图的选项。

默认情况下,Rasa 显示回退的原始意图名称,因为我们没有提供任何映射配置。因此,如果它找到了意图make_reserverations,它将显示

Did you mean make_reserverations? 

并提供两个按钮是和否。

要显示自定义或用户友好的短语,需要实施该操作action_default_ask_affirmation

您必须在actions.py中创建一个类

class ActionDefaultAskAffirmation(Action):
    """Asks for an affirmation of the intent if NLU threshold is not met."""

    def name(self):
        return "action_default_ask_affirmation"

    def __init__(self):
        self.intent_mappings = {}
        # read the mapping of 'intent and valid question' from a csv and store it in a dictionary
        with open(
            INTENT_DESCRIPTION_MAPPING_PATH, newline="", encoding="utf-8"
        ) as file:
            csv_reader = csv.reader(file)
            for row in csv_reader:
                self.intent_mappings[row[0]] = row[1]

    def run(self, dispatcher, tracker, domain):
        # from the list of intents get the second higher predicted intent
        # first will be nlu_fallback  
        predicted_intent_info = tracker.latest_message["intent_ranking"][1]
        # get the most likely intent name
        intent_name = predicted_intent_info["name"]
        # get the prompt for the intent
        intent_prompt = self.intent_mappings[intent_name]

        # Create the affirmation message and add two buttons to it.
        # Use '/<intent_name>' as payload to directly trigger '<intent_name>'
        # when the button is clicked.
        message = "Did you mean '{}'?".format(intent_prompt)

        buttons = [
            {"title": "Yes", "payload": "/{}".format(intent_name)},
            {"title": "No", "payload": "/out_of_scope"},
        ]

        dispatcher.utter_message(message, buttons=buttons)

        return []

然后需要像这样映射csv文件

//intent_name,User_Friendly_Phrase
bot_challenge,I am bot

然后在domain.yml下创建一个条目actions


推荐阅读