rasa nlu后退是返回意图而不是问题

2024-05-28 11:16:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用rasa(第2版),并与this configuration集成了FallbackClassifier

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

Did you mean intent_name

对话就是这样进行的

enter image description here

它应该显示问题,而不是显示意图和名称。我错过什么了吗

和控制台上

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

Tags: 用户name名称youactionmeanthis按钮
2条回答

在回退策略中,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

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

实际上TwoStageFallback似乎是成功的。我认为问题在于,虽然您成功地确认了意图mood_great,但您的助手不知道下一步要运行哪个操作,因此会触发action_core_fallback(在RulePolicy配置中配置)(请参阅文档here中的更多内容)

您是否已将action_default_fallback添加到域文件中?如果您这样做了:在这种情况下,您需要定义一个适当的custom action。如果不想覆盖默认实现,可以从域文件中删除action_default_fallback

相关问题 更多 >