Chatterbot: Set a default response if no matching input is found

Created on 5 Nov 2016  路  11Comments  路  Source: gunthercox/ChatterBot

hi gunther,

I wanted to know if there is a way to set a default response like (i don't understand what you mean)
if no matching input is found

-Dattatreya

Most helpful comment

@alekaizer That is an excellent example. There isn't a better way to provide a default response, I usually recommend something similar to that as a solution.

All 11 comments

i am trying to set a threshold value in the closest match adapter for levenshtein distance
is this correct ?

hi @datta90 You use the process method of your logic adapter to get the confidence of the response then set the threshold on the confidence.

input = 'does linux rock'
bot = ChatBot('tux')
statement = bot.input.process_input(input)
confidence, response = bot.logic.process(statement)
if confidence > THRESHOLD:
   response = bot.output.process_response(response)
else
   response = 'I don't understand what you mean'

Maybe @gunthercox has a better way of doing it :)

@alekaizer That is an excellent example. There isn't a better way to provide a default response, I usually recommend something similar to that as a solution.

i am getting this error when i type the above code in python terminal

In [9]:  statement = bot.logic.input.process_input(input1)
----------------------------------------------------------------------
AttributeError                            Traceback (most recent call
<ipython-input-9-794f22aa52a2> in <module>()
----> 1 statement = bot.logic.input.process_input(input1)

AttributeError: 'MultiLogicAdapter' object has no attribute 'input'

@datta90 Are you sure you are typing it into the terminal _exactly_ as it was written above?
The error message is correct, there is no .input attribute after .logic. I think maybe you meant to type just bot.input.process_input.

thank you gunther
I am getting error UnicodeDecodeError: 'utf8' codec can't decode byte 0x93 in position 83: invalid start byte when i am adding my own training data in the English folder,
my file name is ending with .corpus.json and i have written this file properly
even when i am remove this file i am still getting this error

is it because of json adapter storage my strings are bit long in the file

A UnicodeDecodeError is a Python error that is triggered when a file is opened for reading without the encoding being properly specified. I'll look into this to make sure that ChatterBot's corpus reader is specifying it correctly.

@datta90 I've made a correction to the German corpus that should fix the issue you reported: https://github.com/gunthercox/ChatterBot/pull/394

No problem gunther actually mistake was from my side I used regex to remove the ASCII characters present in my JSON file

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vkosuri picture vkosuri  路  4Comments

yuvalBor picture yuvalBor  路  3Comments

decode007 picture decode007  路  4Comments

engrphil picture engrphil  路  3Comments

coolrb picture coolrb  路  3Comments