Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird results in the chatterbot.chatterbot:Adding responses #1203

Open
jasonleehodges opened this issue Feb 8, 2018 · 7 comments
Open

Weird results in the chatterbot.chatterbot:Adding responses #1203

jasonleehodges opened this issue Feb 8, 2018 · 7 comments
Labels

Comments

@jasonleehodges
Copy link

jasonleehodges commented Feb 8, 2018

The logs are saying something like 'Adding "Hey" as a response to "Hey"' which for the first iteration here makes sense but subsequent iterations it keeps saying that it's adding the response to the phrase "Hey" even thought that was not the last response.

For example, further down the chain you will see that the bot says "See you later" to which I respond with an input of "Bye" and the logs says 'Adding "Bye" as a response to "Hey"'. But "Bye" was not a response to "Hey" it was a response to "See you later." Any idea why it is doing this? Do I need to add a certain logic adapter or something?

>>> chat("Hey")
INFO:chatterbot.adapters:Received input statement: Hey
INFO:chatterbot.adapters:"Hey" is a known statement
INFO:chatterbot.adapters:Using "Hey" as a close match to "Hey"
INFO:chatterbot.adapters:Selecting response from 8 optimal responses.
INFO:chatterbot.response_selection:Selecting a response from list of 8 options.
INFO:chatterbot.adapters:Response selected. Using "I'm good, thanks!"
INFO:chatterbot.adapters:BestMatch selected "I'm good, thanks!" as a response with a confidence of 1.0
INFO:chatterbot.response_selection:Selecting first response from list of 1 options.
INFO:chatterbot.adapters:LowConfidenceAdapter selected "Huh? I don't get it..." as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "Hey" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "Hey" as a response to "Hey"
I'm good, thanks!
>>> chat("Good to hear.")
INFO:chatterbot.adapters:Received input statement: Good to hear.
INFO:chatterbot.adapters:"Good to hear." is not a known statement
INFO:chatterbot.adapters:Using "Good to hear." as a close match to "Goodbye"
INFO:chatterbot.adapters:Selecting response from 1 optimal responses.
INFO:chatterbot.response_selection:Selecting a response from list of 1 options.
INFO:chatterbot.adapters:Response selected. Using "See you later"
INFO:chatterbot.adapters:BestMatch selected "See you later" as a response with a confidence of 0.5
INFO:chatterbot.response_selection:Selecting first response from list of 1 options.
INFO:chatterbot.adapters:LowConfidenceAdapter selected "Huh? I don't get it..." as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "Good to hear." as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "Good to hear." as a response to "Hey"
See you later
>>> chat("Bye")
INFO:chatterbot.adapters:Received input statement: Bye
INFO:chatterbot.adapters:"Bye" is a known statement
INFO:chatterbot.adapters:Using "Bye" as a close match to "Bye"
INFO:chatterbot.adapters:Selecting response from 1 optimal responses.
INFO:chatterbot.response_selection:Selecting a response from list of 1 options.
INFO:chatterbot.adapters:Response selected. Using "Cool"
INFO:chatterbot.adapters:BestMatch selected "Cool" as a response with a confidence of 1.0
INFO:chatterbot.response_selection:Selecting first response from list of 1 options.
INFO:chatterbot.adapters:LowConfidenceAdapter selected "Huh? I don't get it..." as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "Bye" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "Bye" as a response to "Hey"

Here's the configuration:

default = "Huh? I don't get it..."
chatbot = ChatBot('chatboy',trainer="chatterbot.trainers.ListTrainer",
    logic_adapters=[{
        'import_path': 'chatterbot.logic.BestMatch',
        "response_selection_method": "chatterbot.response_selection.get_random_response"
        },
        {
            'import_path': 'chatterbot.logic.LowConfidenceAdapter',
            'threshold': 0.50,
            'default_response': default
        }
        ]
    )

chatbot.train(["Hello","Hey",])
def chat(input):
    response = chatbot.get_response(input)
    print(response)
@vkosuri
Copy link
Collaborator

vkosuri commented Feb 9, 2018

@jasonleehodges Some chatterbot will act weired the amount of training and learning new response are very minor.

Can you try this example https://github.com/gunthercox/ChatterBot/blob/master/examples/learning_new_response.py, and let me know your observations.

@aitzolete
Copy link

aitzolete commented Feb 21, 2018

I had the same issue and, in my opinion, has nothing to do with the amount of training examples. Simply, all the input statements are added as a response to the very first statement.

i tried the following example program:


chatbot = ChatBot(
"txabot",
preprocessors=[
'chatterbot.preprocessors.clean_whitespace'
],
storage_adapter='chatterbot.storage.SQLStorageAdapter',
 logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
	},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',
'threshold': 0.65,
'default_response': 'What do you mean?'
	}
    ],
input_adapter='chatterbot.input.TerminalAdapter',
output_adapter='chatterbot.output.TerminalAdapter',
database='./database.sqlite3')

chatbot.set_trainer(ChatterBotCorpusTrainer)

# Start by training our bot with the Ubuntu corpus data
chatbot.train('chatterbot.corpus.english')

print("Say something...")

# The following loop will execute each time the user enters input
while True:
    try:
        response = chatbot.get_response(None)

    # Press ctrl-c or ctrl-d on the keyboard to exit
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

And when I execute it, all the statements are added to the first one.
I think that, as learning_new_response.py program shows, each statement has to be manually linked with its response.

@jasonleehodges
Copy link
Author

I essentially just turned off the learning and am going to do it manually with user based reinforcement learning because the built in method didn't work for me at all.

@Metalor696
Copy link

@jasonleehodges did you find a solution for this? I'm having the same issue and finding that the very first time get_response is called it finds a statement via 'BestMatch' then all following statements seem to saved as responses to the first RandomResponse.

However, sometimes it will seem to randomly start saving responses against a different statement

INFO:chatterbot.adapters:Received input statement: hey test testmate
INFO:chatterbot.adapters:"hey test testmate" is not a known statement
INFO:chatterbot.adapters:Using "hey test testmate" as a close match to "que veut dire hal"
INFO:chatterbot.adapters:Selecting response from 1 optimal responses.
INFO:chatterbot.response_selection:Selecting first response from list of 1 options.
INFO:chatterbot.adapters:Response selected. Using "logique heuristique algorithmique."
INFO:chatterbot.adapters:BestMatch selected "logique heuristique algorithmique." as a response with a confidence of 0.53
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "hey test testmate" as a response with a confidence of 0



INFO:chatterbot.adapters:Received input statement: what?
INFO:chatterbot.adapters:"what?" is not a known statement
INFO:chatterbot.adapters:Using "what?" as a close match to "What?"
INFO:chatterbot.adapters:No response to "What?" found. Selecting a random response.
INFO:chatterbot.adapters:BestMatch selected "nice hat" as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "what?" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "what?" as a response to "logique heuristique algorithmique."


INFO:chatterbot.adapters:Received input statement: LOL
INFO:chatterbot.adapters:"LOL" is a known statement
INFO:chatterbot.adapters:Using "LOL" as a close match to "LOL"
INFO:chatterbot.adapters:No response to "LOL" found. Selecting a random response.
INFO:chatterbot.adapters:BestMatch selected "hey toby look i got us a dog" as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "LOL" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "LOL" as a response to "logique heuristique algorithmique."



INFO:chatterbot.adapters:Received input statement: which conversation is this?
INFO:chatterbot.adapters:"which conversation is this?" is not a known statement
INFO:chatterbot.adapters:Using "which conversation is this?" as a close match to "which bot is this"
INFO:chatterbot.adapters:No response to "which bot is this" found. Selecting a random response.
INFO:chatterbot.adapters:BestMatch selected "whats the command to generate memes" as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "which conversation is this?" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "which conversation is this?" as a response to "logique heuristique algorithmique."



INFO:chatterbot.adapters:Received input statement: que veut dire hal
INFO:chatterbot.adapters:"que veut dire hal" is a known statement
INFO:chatterbot.adapters:Using "que veut dire hal" as a close match to "que veut dire hal"
INFO:chatterbot.adapters:No response to "que veut dire hal" found. Selecting a random response.
INFO:chatterbot.adapters:BestMatch selected "I'm learning BACKWARDS" as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "que veut dire hal" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "que veut dire hal" as a response to "logique heuristique algorithmique."

The weird thing that confuses me the most is how using a known statement with apparent responses chooses a random response again

INFO:chatterbot.adapters:Received input statement: logique heuristique algorithmique.
INFO:chatterbot.adapters:"logique heuristique algorithmique." is a known statement
INFO:chatterbot.adapters:Using "logique heuristique algorithmique." as a close match to "heuristic algorithmic logic"
INFO:chatterbot.adapters:No response to "heuristic algorithmic logic" found. Selecting a random response.
INFO:chatterbot.adapters:BestMatch selected "Good." as a response with a confidence of 0
INFO:chatterbot.adapters:NoKnowledgeAdapter selected "logique heuristique algorithmique." as a response with a confidence of 0
INFO:chatterbot.chatterbot:Adding "logique heuristique algorithmique." as a response to "hey toby look i got us a dog"

@azarezade
Copy link

azarezade commented Sep 30, 2018

@gunthercox I have the same issue with latest version 1.0.1a, all statements are save in_response_to my first training statement.
Do we miss something here!?

@iamhssingh
Copy link

I believe this question is relevant to be posted here than creating a new issue. Been a long time since I used chatterbot. All statements are being saved in in_response_to but the BestMatch adapter is not looking for responses via in_response_to (earlier it used to).

Here's the issue:

Database:

Statement 1: {"text": "Hi", "search_text": "hi", ...., "in_response_to": None, "search_in_reponse_to": ""}
Statement 2: {"text": "How are you?", "search_text": "WRB:are VBP:you", ...., "in_response_to": "Hi", "search_in_reponse_to": ""}

Output:

Hi
INFO:chatterbot.chatterbot:Beginning search for close text match
INFO:chatterbot.chatterbot:Processing search results
INFO:chatterbot.chatterbot:Similar text found: Hi 1.0
INFO:chatterbot.chatterbot:Using "Hi" as a close match to "Hi" with a confidence of 1.0
INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.
INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.
INFO:chatterbot.chatterbot:BestMatch selected "Hi" as a response with a confidence of 0
INFO:chatterbot.chatterbot:Not processing the statement using SpecificResponseAdapter
INFO:chatterbot.chatterbot:Adding "Hi" as a response to "Hi"
Hi

Apparantely, adding hi in search_in_reponse_to for Statement 2 gets me the desirable result. But why is this not happening by default in learn_response function?

@vkosuri Any inputs?

@danifantom
Copy link

Don't know if You guys found a solution for this. If You did please let me know.
For now I have this workaround:

last_response = ''
while True:
    try:
        user_input = Statement(text=input(), in_response_to=last_response)
        bot_response = bot.get_response(user_input)
        last_response = str(bot_response)
        print(bot_response)
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

Hope this helps someone that could possibly have this issue.
If You guys found a proper solution please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants