聊天机器人:在训练数据中找不到响应时如何获得默认响应
chatbot : how to get default response when no response found in training data
我制作了一个可以回答静态查询的简单聊天机器人。到目前为止它工作正常但问题是当询问不在训练数据中的查询时,它只是选择任何随机语句。
我希望 Chatbot 回答一些默认语句,例如 "I am not trained for this"、"I don't know"..等。
我的代码如下:
bot = ChatBot(
"ChatBot",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.BestMatch',
'threshold': 0.65,
'default_response': 'default_value'
}
],
response_selection_method=get_most_frequent_response,
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database="db.sqlite3"
)
def get_bot_response():
userText = request.args.get('msg')
botReply = str(bot.get_response(userText))
if botReply is "default_value":
botReply = str(bot.get_response('default_response'))
在我的训练数据中,我已将 'default_response' 的答案设置为“我不知道”,'I need to think on it' 等。
但是,这不起作用,因为在转到 if 语句之前已经解析了 botReply。
有人可以帮助 default_response 而不是给出随机答案吗?
docs for ChatterBot. I would assume the version you are using will operate the same. You can also read here 中有一个您在做什么的示例,其中讨论了如何使用多个逻辑适配器进行选择。
bot = ChatBot(
"ChatBot",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch',
'threshold': 0.65,
'default_response': 'default_value'
}
],
response_selection_method=get_most_frequent_response,
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database="db.sqlite3"
)
def get_bot_response():
userText = request.args.get('msg')
botReply = str(bot.get_response(userText))
if botReply is "default_value":
botReply = str(bot.get_response('default_response'))
您只需使用一个 logic_adapter
,如果低于设置的阈值,它将自动 return 默认值。您可以使用多个适配器,但由于您对两者执行相同类型的逻辑,因此使用两个适配器没有意义。
在你的问题中,你首先得到的是没有阈值的响应,然后可能是第二个响应或没有信心的默认值,所以有信心的人会赢。
我制作了一个可以回答静态查询的简单聊天机器人。到目前为止它工作正常但问题是当询问不在训练数据中的查询时,它只是选择任何随机语句。 我希望 Chatbot 回答一些默认语句,例如 "I am not trained for this"、"I don't know"..等。 我的代码如下:
bot = ChatBot(
"ChatBot",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.BestMatch',
'threshold': 0.65,
'default_response': 'default_value'
}
],
response_selection_method=get_most_frequent_response,
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database="db.sqlite3"
)
def get_bot_response():
userText = request.args.get('msg')
botReply = str(bot.get_response(userText))
if botReply is "default_value":
botReply = str(bot.get_response('default_response'))
在我的训练数据中,我已将 'default_response' 的答案设置为“我不知道”,'I need to think on it' 等。
但是,这不起作用,因为在转到 if 语句之前已经解析了 botReply。
有人可以帮助 default_response 而不是给出随机答案吗?
docs for ChatterBot. I would assume the version you are using will operate the same. You can also read here 中有一个您在做什么的示例,其中讨论了如何使用多个逻辑适配器进行选择。
bot = ChatBot(
"ChatBot",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch',
'threshold': 0.65,
'default_response': 'default_value'
}
],
response_selection_method=get_most_frequent_response,
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database="db.sqlite3"
)
def get_bot_response():
userText = request.args.get('msg')
botReply = str(bot.get_response(userText))
if botReply is "default_value":
botReply = str(bot.get_response('default_response'))
您只需使用一个 logic_adapter
,如果低于设置的阈值,它将自动 return 默认值。您可以使用多个适配器,但由于您对两者执行相同类型的逻辑,因此使用两个适配器没有意义。
在你的问题中,你首先得到的是没有阈值的响应,然后可能是第二个响应或没有信心的默认值,所以有信心的人会赢。