Reputation: 361
I have made a simple Chatbot which can answer static queries. It is working ok so far But the problem is when a query is asked which is not in training data, it is just picking any random statement. I want Chatbot to answer some default statement like "I am not trained for this","I don't know"..etc. my code is as below:
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'))
in my training data,I have set answers for 'default_response' as 'I don't know','I need to think on it' etc..
But, this is not working as botReply is already being parsed before going to if statement.
Can someone help on how to get default_response rather giving Random answers ?
Upvotes: 1
Views: 2189
Reputation: 4489
There is an example of what you are doing in the docs for ChatterBot. I would assume the version you are using will operate the same. You can also read here where it discusses how it selects with multiple logic adapters.
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'))
You need to only use one logic_adapter
which will automatically return the default value if under the threshold set. You can use multiple adapters but since you are doing the same type of logic for both it doesn't make sense to have two.
In your question you are getting a response without a threshold first and then potentially a second response or a default value without confidence, so the one with confidence is going to win.
Upvotes: 3