2

I made a simple chatbot using chatterbot library and python. The way I trained it is, I made it read a few text files containing chat examples, and it learns how to reply to messages based on those training examples. The problem I am facing is - Even if I erase the contents of the training text files, and run the application, the chatbot still behaves in the same manner as before, i.e. it's memory doesn't get refreshed. I tried starting a new file and copy pasted the same code and changed the name of the program, but it still doesn't help. How do I solve this problem? Here is the code for reference:

from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

import os

bot = ChatBot('trialBot')

bot.set_trainer(ListTrainer)

#directory containing training text files
mainDir = 'C:\\Users\\xyz\\Desktop\\trainfiles\\'

for _file in os .listdir(mainDir):
    chats = open(mainDir + _file, 'r').readlines()
    bot.train(chats)


while True:
    request = raw_input('You: ')
    response = bot.get_response(request)

    print('Bot: ' + str(response))
Syntax-Tax
  • 21
  • 1

1 Answers1

2

It sounds like you might want to use an in-memory database so that the content is only persisted as long as the chat bot is running.

bot = ChatBot(
    'trialBot',
    database_uri=None
)

Setting database_uri to None will cause the chat bot to use a Sqlite database that is stored in-memory so store the knowledge that it is trained with. As a result, you will have a fresh database to work with each time you run your program.

Gunther
  • 2,474
  • 4
  • 31
  • 45