Chatterbot: Random responses to same question

Created on 17 Aug 2016  ·  13Comments  ·  Source: gunthercox/ChatterBot

Hello, I'm trying to create a basic chat bot with voice recognition and tts, I'm trying to teach it Russian, and stumbled upon a problem.

I'm trying to teach it through simple lists, which I stored as json file, here is an example:

[ "Расскажи о себе.", "Я ИИ, написанный на питоне." ], [ "Расскажи о себе.", "Мне нравится оранжевый..." ], [ "Расскажи о себе.", "А Вы знали, что у ИИ нет пола?" ], [ "Расскажи о себе.", "Я здесь, что бы помогать." ], [ "Расскажи о себе.", "Exterminate." ], [ "Расскажи о себе.", "Я люблю фиолетовый..." ],

I tried it like this, and also tried putting them all into one list, like this:

[ "Расскажи о себе.", "Я ИИ, написанный на питоне.", "Расскажи о себе.", "Мне нравится оранжевый...", "Расскажи о себе.", "А Вы знали, что у ИИ нет пола?", "Расскажи о себе.", "Я здесь, что бы помогать.", "Расскажи о себе.", "Exterminate.", "Расскажи о себе.", "Я люблю фиолетовый..." ],

In both cases, when asked "Расскажи о себе" (translates as "Tell me about yourself"), Chatterbot picks one of the answers, and keeps using this one particular answer, and then always uses it when asked "Tell me about yourself", until I restart the process... Do I need to somehow reset AI after each conversation?

Extended documentation would really help.
Thanks.

Also thinking about spending some time and making russian language corpus, if thats interesting.

Most helpful comment

I think I have it figured out now..

from chatterbot.response_selection import get_random_response
chatterbot = ChatBot("Charlie",
    response_selection_method=get_random_response,

Those were the only changes I had to make to finally get some varied responses for each given question.

All 13 comments

Hi, I will have to look into this issue a bit more. In the mean time, could you tell me what version of Python you are using?
I'm aware that Python 2.7 can sometimes have issues handling unicode text.

Nope, I specifically updated to 3.5 to work with chatterbot and stuff. There are no issues with unicode, I'm using codecs.open() to read unicode file, and it reads perfectly, and bot uses and recognizes all the phrases, it's just that it does not randomly choose one of the learned answers. It acts the same with english lists, I just did not have english example at hand at the moment.

And yeah, otherwise a great chatbot, I love that it can be extended with modules, basically it can grow into fully functional assistant, from what I understand, from what I understand. Thinking about integrating it with Home Assistant in the future.

I have the same issue in Spanish using python 2.7, i didn't test it with 3.x. In rare occasions it picks another answer.

Hi @Nixellion @asperduti, the latest release of ChatterBot now includes much more verbose logging that can be enabled to help debug issues like these. You can enable the logging by setting Python's logging level to info:

import logging

logging.basicConfig(level=logging.INFO)

ChatBot(
    # ...
)

This should allow you to actually see what is happening inside ChatterBot and it will also tell you exactly why a particular response was returned.

If anything strange shows up in the logs, please open an issue about it or post the log output in a comment somewhere.

Logging documentation: http://chatterbot.readthedocs.io/en/latest/chatterbot.html#logger

Hi, thanks. Here''s what I've got:

INFO:chatterbot.chatterbot:"расскажи о себе" is a known statement INFO:chatterbot.adapters.adapter:<class 'chatterbot.adapters.logic.no_knowledge_adapter.NoKnowledgeAdapter'> selected "расскажи о себе" as a response with a confidence of 0 INFO:chatterbot.adapters.adapter:<class 'chatterbot.adapters.logic.time_adapter.TimeLogicAdapter'> selected "The current time is 12:39 AM" as a response with a confidence of 0 INFO:chatterbot.adapters.adapter:Using "расскажи о себе" as a close match to "Расскажи о себе." INFO:chatterbot.adapters.adapter:Breaking tie between 6 optimal responses. INFO:chatterbot.adapters.logic.mixins:Selecting first response from list of 6 options. INFO:chatterbot.adapters.adapter:Tie broken. Using "Exterminate." INFO:chatterbot.adapters.adapter:<class 'chatterbot.adapters.logic.closest_match.ClosestMatchAdapter'> selected "Exterminate." as a response with a confidence of 0.97 INFO:chatterbot.chatterbot:Selecting "Exterminate." as response with a confidence of 0.97```

So it says that it's selecting the first responce, while it should probably select random?
I guess I should set it to random_response, from what I see in that code... Is that anywhere in documentation? Did not find it

Change the bit in base_match.py to:

        self.tie_breaking_method = kwargs.get(
            "tie_breaking_method",
            "random_response"
        )

now it selects random responses. But I guess it's not the correct way to set it, right?

You can actually specify this when you construct your chat bot:

chatbot = ChatBot(
    # ...
   tie_breaking_method="random_response"
)

The documentation on these methods was _very_ recently added: http://chatterbot.readthedocs.io/en/latest/adapters/tie_breaking_method_mixins.html

Note, that there are currently plans to improve the selection process. Specifically, https://github.com/gunthercox/ChatterBot/issues/276 will add functionality so that the the response is selected based on the context of the current conversation. This will help make these responses much more relevant.

Thanks, yeah, did not see that before in the docs.

And sounds great, some contextual responses should be great.
Also some documentation on how to add some functional adapters, things that actually do stuff like play music, google something or check your mail. Right now I did a few, and they do stuff within adapter itself, after checking if they can process the input, but I'm not sure if thats the correct approach either.

@gunthercox this link you posted is dead: http://chatterbot.readthedocs.io/en/latest/adapters/tie_breaking_method_mixins.html
Is that how you would currently get a random response? In my corpus I have some of the same questions posted multiple times, yet each question gets the same default answer for it each time.

# -*- coding: utf-8 -*-
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

# Create a new chat bot named Charlie

chatterbot = ChatBot("Charlie",
    #database='CommentDatabase.json',
    tie_breaking_method="random_response",
    storage_adapter='chatterbot.storage.MongoDatabaseAdapter',
    logic_adapters=[    
        {
            'import_path': 'chatterbot.logic.BestMatch'
        },
        {
            'import_path': 'chatterbot.logic.LowConfidenceAdapter',
            'threshold': 0.70,
            'default_response': 'OhNo'
        }
        ],
        database='list_trainer'
    )
chatterbot.set_trainer(ChatterBotCorpusTrainer)


chatterbot.train(
    "/path/to/favorites.corpus.json"
)

# Get a response to the input text 'How are you?'
response = chatterbot.get_response("what is your favorite movie")

print(response)

I think I have it figured out now..

from chatterbot.response_selection import get_random_response
chatterbot = ChatBot("Charlie",
    response_selection_method=get_random_response,

Those were the only changes I had to make to finally get some varied responses for each given question.

@neatville Setting the response_selection_method is correct.

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

atulanandnitt picture atulanandnitt  ·  3Comments

coolrb picture coolrb  ·  3Comments

decode007 picture decode007  ·  3Comments

gunthercox picture gunthercox  ·  3Comments

AmusingThrone picture AmusingThrone  ·  3Comments