Chatterbot: Help with learning_feedback_example.py

Created on 21 May 2017  路  7Comments  路  Source: gunthercox/ChatterBot

Can someone explain me why we do not take the correct response from the user if the user enters 'NO'.
We must take what is the correct output according to the User and then feed the ChatBot with the actual output that one expects !

  • please enlighten me! and if there is something wrong then kindly forgive me. :p
  • gabru-md
question

Most helpful comment

Try out this

from chatterbot import ChatBot
import logging
from chatterbot.trainers import ChatterBotCorpusTrainer

# Uncomment the following line to enable verbose logging
# logging.basicConfig(level=logging.INFO)

# Create a new instance of a ChatBot
bot = ChatBot("Terminal",
    storage_adapter="chatterbot.storage.JsonFileStorageAdapter",
    input_adapter="chatterbot.input.TerminalAdapter",
    output_adapter="chatterbot.output.TerminalAdapter"
)
bot.set_trainer(ChatterBotCorpusTrainer)

bot.train(
    "chatterbot.corpus.english"
)

DEFAULT_SESSION_ID = bot.default_session.id

def get_feedback():
    from chatterbot.utils import input_function

    text = input_function()

    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...")

# The following loop will execute each time the user enters input
while True:
    try:
               input_statement = bot.input.process_input_statement()
               statement, response = bot.generate_response(input_statement, DEFAULT_SESSION_ID)
               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")
                    response1 = bot.input.process_input_statement()
                    bot.learn_response(response1, input_statement)

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

All 7 comments

If you want make accurate response make threshold value as 1.0, for example For more information please read this documentation http://chatterbot.readthedocs.io/en/stable/logic/index.html#low-confidence-response-adapter

# -*- coding: utf-8 -*-
from chatterbot import ChatBot

# Create a new instance of a ChatBot
bot = ChatBot(
    'Default Response Example Bot',
    storage_adapter='chatterbot.storage.JsonFileStorageAdapter',
    logic_adapters=[
        {
            'import_path': 'chatterbot.logic.BestMatch'
        },
        {
            'import_path': 'chatterbot.logic.LowConfidenceAdapter',
            'threshold': 1.0,
            'default_response': 'I am sorry, but I do not understand.'
        }
    ],
    trainer='chatterbot.trainers.ListTrainer'
)

# Train the chat bot with a few responses
bot.train([
    'How can I help you?',
    'I want to create a chat bot',
    'Have you read the documentation?',
    'No',
    'This should help get you started: http://chatterbot.rtfd.org/en/latest/quickstart.html'
])

# Get a response for some unexpected input
response = bot.get_response('How do I make an omelette?')
print(response)

I am saying why cannot we add the correct response to the input text. It would then be added to the data-file to train the chatterbot the next time.

Can it not be done ? This will also help the chatbot generate unique responses depending upon what the user wants!

@gabru-md It can be done. Responses can be updated directly in the database (no utility methods have been added for doing this). Do you have any recommendations for what would be useful to provide for correcting "incorrect" responses?

@gunthercox
Directly updating the database would mean to create a user specific training data-set.

What can be done is that as soon as the user enters "No", he/she must be prompted for a reply as to "What can be an apt response for {{QUESTION}} ?"
and then the correct response can be taken as input and stored directly into a database. This can be helpful and will then help generate a unique data-set/corpus for the chatterbot model. The more the users perform the testing the bigger the dataset will be and better will be the responses!

It is quite difficult for me to understand the code and so i am not able to resolve this problem on my own and issue a PR.
Any help would be appreciated :)

Try out this

from chatterbot import ChatBot
import logging
from chatterbot.trainers import ChatterBotCorpusTrainer

# Uncomment the following line to enable verbose logging
# logging.basicConfig(level=logging.INFO)

# Create a new instance of a ChatBot
bot = ChatBot("Terminal",
    storage_adapter="chatterbot.storage.JsonFileStorageAdapter",
    input_adapter="chatterbot.input.TerminalAdapter",
    output_adapter="chatterbot.output.TerminalAdapter"
)
bot.set_trainer(ChatterBotCorpusTrainer)

bot.train(
    "chatterbot.corpus.english"
)

DEFAULT_SESSION_ID = bot.default_session.id

def get_feedback():
    from chatterbot.utils import input_function

    text = input_function()

    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...")

# The following loop will execute each time the user enters input
while True:
    try:
               input_statement = bot.input.process_input_statement()
               statement, response = bot.generate_response(input_statement, DEFAULT_SESSION_ID)
               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")
                    response1 = bot.input.process_input_statement()
                    bot.learn_response(response1, input_statement)

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

Given @sanyam8182's answer I am going to close this off. ChatterBot is a learning-based chat bot and the example above show a good example of how to get additional information from the user to teach the chat bot with.

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

AmusingThrone picture AmusingThrone  路  3Comments

AfrahAsif picture AfrahAsif  路  3Comments

coolrb picture coolrb  路  3Comments

atulanandnitt picture atulanandnitt  路  3Comments