gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.11k stars 4.45k forks source link

learn_response from feedback is not working #2098

Open feryah opened 3 years ago

feryah commented 3 years ago

Hi, I am trying to build a chat bot in French that learns new questions and answers thanks to the feedback given by the user. But when I ask the bot the same question it just learnt, it doesn't work, it still give a random answer like for the question: "What is the capital city of Germany?" I give it the answer "Berlin" to learn and it prints me "answers added" but when I ask this question again it still not have the answer. Any help please?

Here is my code:


from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.response_selection import get_random_response, get_most_frequent_response, get_first_response
from chatterbot.comparisons import LevenshteinDistance, JaccardSimilarity
from chatterbot.conversation import Statement

my_bot = ChatBot(name='Mon_premier_Chatbot', 
                 #storage_adapter='chatterbot.storage.SQLStorageAdapter',
                 statement_comparison_function=LevenshteinDistance,
                 response_selection_method=get_random_response,
                 logic_adapters=[

        {   

            'import_path':'chatterbot.logic.BestMatch',
            'maximum_similarity_threshold':0.9
        }

    ]

    )

trainer = ChatterBotCorpusTrainer(my_bot)

for f in os.listdir('./french'):
  trainer.train('./french/'+f)

bot = ChatBot("test", storage_adapter='chatterbot.storage.SQLStorageAdapter')

def get_feedback():

    text = input()

    if 'oui' in text.lower():
        return True
    elif 'non' in text.lower():
        return False
    elif 'exit' in text.lower():
      return False
    else:
        print('Veuillez taper "Oui" ou "Non"')
        return get_feedback()

name = input("Entre ton prénom : ")
print("Bienvenue au service Bot ! Dis-moi comment je peux t'aider")

while True:
    try:
        input_statement = Statement(text=input(name+' : '))
        response = bot.generate_response(input_statement)

        print(f'\n Bot : Est-ce {response.text} une réponse cohérente à {input_statement.text} ? \n')

        if get_feedback() is False:
            print('Bot : Veuillez taper la réponse correcte')
            correct_response = Statement(text=input())
            if correct_response == 'exit':
              print('Bot : Bye')
              break
            bot.learn_response(correct_response, input_statement)
            print('Bot : Réponses ajoutées au bot !')

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

Output:

Entre ton prénom : Ferial
Bienvenue au service Bot ! Dis-moi comment je peux t'aider
Ferial : Comment vas-tu ?

 Bot : Est-ce Je vais bien merci, et toi ? une réponse cohérente à Comment vas-tu ? ? 

Oui
Ferial : Quelle est la capitale de l'Allemagne ?

 Bot : Est-ce Liberté, Egalité Fraternité une réponse cohérente à Quelle est la capitale de l'Allemagne ? ? 

Non
Bot : Veuillez taper la réponse correcte
Berlin
Bot : Réponses ajoutées au bot !
Ferial : Quelle est la capitale de l'Allemagne ?

 Bot : Est-ce Liberté, Egalité Fraternité une réponse cohérente à Quelle est la capitale de l'Allemagne ? ? 

Non
Bot : Veuillez taper la réponse correcte
Berlin
Bot : Réponses ajoutées au bot !
Ferial : 
AnAnalogGuy commented 3 years ago

Have you checked the "database/dialog files" if the answer has really been added?

NISH-Original commented 3 years ago

Have you checked the "database/dialog files" if the answer has really been added?

Can you please tell me where can I find that?

Mohammad699 commented 2 years ago

Have you checked the "database/dialog files" if the answer has really been added?

I have the same issue and the answers were added to the database file.

Mohammad699 commented 2 years ago

Have you checked the "database/dialog files" if the answer has really been added?

Can you please tell me where can I find that?

search for sqlite3 file in you projects root directory