python - 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'.
解决方案
在后备策略中,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
推荐阅读
- python - 了解 numpy.where
- javascript - 如何使用特殊的 char 属性规范化 JS 对象
- javascript - if Statement, node js/ JavaScript .. 如何仅在星期天将在提供的代码中声明的规则输出到控制台?
- javascript - Discord.js Bots // 尝试在主文件中添加多个机器人,设置状态,随机化欢迎消息,多个前缀
- c - 如何用 C 编译 SoLoud 库的演示示例?
- python - if not 声明解释
- python - Pycharm:原因:java.io.IOException:无法运行程序“python3.7”:错误= 2,没有这样的文件或目录
- eclipse - Eclipse 运行 SpringBoot:SLF4J:类路径包含多个 SLF4J 绑定
- ios - 使用 startAccessingSecurityScopedResource 仍然得到“无法打开,因为您无权查看它”
- python - 在 Colab 环境中使用 xxd 时,它在 bash 中执行