ChatterBot icon indicating copy to clipboard operation
ChatterBot copied to clipboard

Answers Updating

Open Aljumaili85 opened this issue 7 years ago • 6 comments

Hi there, previously I faced a problem of updating the ChatterBot answers when its could not find the right one for a given question, my chatterbot was trained using data from the ChatterBot dialog corpus .

Then I decide to create a chatterbot database from scratch by creating empty database and inserting the question and the the answer one by one using the example "learning_new_response.py".

the application works like this: type something to begin ... me: hi chatterbot: Is "hi" a coherent response to "hi"? me: no chatterbot: please input the correct one me: Hello Dear! chatterbot: Responses added to bot! .............................. and so on until I enter, let say 5 questions and answers. Then if I choose a pre-definde question it will choose a wrong answer. for example if I write "hi" the chatterbot will respond : Is "I am good thank you." a coherent response to "hi"? I wondering what is going wrong here! ?

by the way, if I open the created database I can find all the questions with the right answers but I don't know why it chooses a different answer even when I use the BestMatch as logic adapter.

bellow is my code that has been used:

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
bot = ChatBot(
    "Terminal",
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    trainer = "chatterbot.trainers.ChatterBotCorpusTrainer",
        logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
            "response_selection_method": "chatterbot.response_selection.get_most_frequent_response"
        }
    ]
)

def get_feedback():
    text = input()
    if 'yes' in text.lower():
        return False
    elif 'no' in text.lower():
        return True
    else:
        print('Please type either "Yes" or "No"')
        return get_feedback()
print("Type something to begin...")

while True:
    try:
        request=input()
        input_statement = bot.input.process_input(request)
        temp1,response = bot.generate_response(
            input_statement,1
        )
        bot.output.process_response(response)
        print('\n Is "{}" a coherent response to "{}"? \n'.format(response, input_statement))
        if get_feedback():
            print("please input the correct one")
            request1=input()
            response1 = bot.input.process_input(request1)
            bot.learn_response(response1, input_statement)
            print("Responses added to bot!")
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

Aljumaili85 avatar Jan 08 '19 11:01 Aljumaili85

Hi @Aljumaili85, you mentioned that all of the correct answers exist in the database when you view it. Are there incorrect answers in the database as well? It is possible that your chat bot is selecting a close match that has the incorrect response associated with it still.

This may be an improvement that could be made to ChatterBot. May I ask, in cases like this how would you like the chat bot to select the correct response?

gunthercox avatar Jan 12 '19 00:01 gunthercox

No, actually I have one and only one answer for each question, but it seems that the BestMatch is not selecting the right matched question , but at the same time BestMatch works good with the database of dialog corpus

Aljumaili85 avatar Jan 14 '19 09:01 Aljumaili85

Interesting, I'll mark this as a possible bug then. I'm not aware of any issues currently effecting how the BestMatch adapter selects responses, but I'd happy to work on a solution if the problem can be identified.

gunthercox avatar Jan 15 '19 11:01 gunthercox

Hi @gunthercox @Aljumaili85

I have tried this code but got an error

**

input_statement = bot.input.process_input(request) AttributeError: 'ChatBot' object has no attribute 'input'.

**

Can you please help me how to get rid of it. Many thanks

Dulce06 avatar Feb 12 '19 10:02 Dulce06

It a problem of incompatibility of the given code and the installed ChatterBot version. try to install the latest ChatterBot and try again. meanwhile i will try to see whats wrong

Aljumaili85 avatar Feb 12 '19 11:02 Aljumaili85

Hi @Aljumaili85

Thanks for the prompt response.

Upgraded the chatterbot version. I have the following errors now:

DEFAULT_SESSION_ID = bot.default_session.id AttributeError: 'ChatBot' object has no attribute 'default_session'

Cannot find reference 'input_function' in 'utils.py' less... (Ctrl+F1) Inspection info: This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.

Dulce06 avatar Feb 12 '19 11:02 Dulce06