ChatterBot: Chatterbot not working properly

Hi,

I’m trying to create a chatterbot using flask. I got it but unfortunately I face few issues.

  1. I have 10 YML files, If I ask a question, the chatterbot is getting the answer from some other file and not where it should fetch, basically not answering properly
  2. Secondly when I run the chatterbot for the second time, the first time question that I asked which chatterbot could not reply for the first time is stored and it is asking me back when I ask a known question.

I used the following code:

from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from chatterbot.response_selection import get_first_response
from chatterbot.comparisons import levenshtein_distance
import os

app = Flask(__name__)

english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter",
                        preprocessors=['chatterbot.preprocessors.clean_whitespace'],
				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': 'I am sorry, but I do not understand.'
        } 
    ],
    trainer='chatterbot.trainers.ListTrainer'
)

english_bot.set_trainer(ListTrainer)

for files in os.listdir('../mytraining/'):
		data = open('../mytraining/' + files, 'r').readlines()
		english_bot.train(data)

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/get")
def get_bot_response():
    userText = request.args.get('msg')
    return str(english_bot.get_response(userText))


if __name__ == "__main__":
    app.run()
Please help me as early as possible 
![not_working](https://user-images.githubusercontent.com/39655998/40579319-774fa1fa-6142-11e8-8bd3-d066c7a4f830.JPG)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

@FathimaFirdhouse glad to hear your problem was resolved.

@FathimaFirdhouse The file format of the data (json / yaml) has no effect on the accuracy.

If you are getting different responses between use of single and multiple files I’d suggest making sure that the conversations in each file follow the correct notation for responses.

Thank you so much for your help. It is working now with read_only=True instead of adding it in initialization I added it after training statement that is after bot.train(data) now it’s working fine. Thank you very much.