rasa nlu fallback 返回的是意图而不是问题
rasa nlu fallback is returning intent instead of question
我正在使用 rasa(第 2 版)并且 我已经集成了 FallbackClassifier
。
但是这个 returns 意图名称而不是任何带有是和否按钮的问题。如果我按是,那么它会向用户
提问
Did you mean intent_name
对话是这样进行的
而不是显示 intent_name 它应该显示问题。我错过了什么吗?
在控制台上
ERROR rasa_sdk.endpoint - No registered action found for
name 'action_default_fallback'.
在回退策略中,rasa 显示了最有可能的意图选项。
默认情况下,Rasa 显示回退的原始意图名称,因为我们没有提供任何映射配置。因此,如果它找到意图 make_reserverations
,它将显示
Did you mean make_reserverations?
并提供两个按钮是和否。
要显示自定义或用户友好的短语,需要执行操作 action_default_ask_affirmation
您必须在 actions.py
中创建一个 class
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
。
我正在使用 rasa(第 2 版)并且 FallbackClassifier
。
但是这个 returns 意图名称而不是任何带有是和否按钮的问题。如果我按是,那么它会向用户
提问Did you mean intent_name
对话是这样进行的
而不是显示 intent_name 它应该显示问题。我错过了什么吗?
在控制台上
ERROR rasa_sdk.endpoint - No registered action found for
name 'action_default_fallback'.
在回退策略中,rasa 显示了最有可能的意图选项。
默认情况下,Rasa 显示回退的原始意图名称,因为我们没有提供任何映射配置。因此,如果它找到意图 make_reserverations
,它将显示
Did you mean make_reserverations?
并提供两个按钮是和否。
要显示自定义或用户友好的短语,需要执行操作 action_default_ask_affirmation
您必须在 actions.py
中创建一个 classclass 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
TwoStageFallback
实际上看起来成功了。我认为问题在于,当您成功确认意图 mood_great
时,您的助手不知道接下来要 运行 执行哪个操作,因此会触发 action_core_fallback
(在 RulePolicy
中配置配置)(请参阅文档 here)。
您是否将 action_default_fallback
添加到您的域文件?如果你这样做了:在这种情况下你需要定义一个合适的 custom action 。如果您不想覆盖默认实现,您可以从域文件中删除 action_default_fallback
。