How to add external training in chatterbot
I created a very simple bot to learn how to use chatterbot. This library already comes with a training, but I wanted to put an extra training with the import of a corpus in Portuguese that I found on github.
from chatterbot import ChatBot
bot = Futaba(
"Terminal",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
logic_adapters=[
"chatterbot.logic.MathematicalEvaluation",
"chatterbot.logic.TimeLogicAdapter",
"chatterbot.logic.BestMatch"
],
input_adapter="chatterbot.input.TerminalAdapter",
output_adapter="chatterbot.output.TerminalAdapter",
database_uri="../database.db"
)
print("Type something to begin...")
while True:
try:
bot_input = bot.get_response(None)
except (KeyboardInterrupt, EOFError, SystemExit):
break
That's all I have.
How can I import this corpus into my chatbot?
1 answers
The answer took a long time to come and probably you should have already succeeded, but just to get registered:
from chatterbot.trainers import ChatterBotCorpusTrainer
bot = ChatBot('bot')
trainer = ChatterBotCorpusTrainer(bot)
trainer.train('arquivoDeTreino.yml')
The file .yml is the file where the conversation will be used for bot training. If you want an example file, use these: https://github.com/gunthercox/chatterbot-corpus/tree/master/chatterbot_corpus/data/portuguese
It is also possible to train the bot with a txt file itself, where each line is a sentence coming from the user or the bot, to this instead of ChatterBotCorpusTrainer, you use ListTrainer. Anything you can look at the ChatterBot documentation that has everything there explained. https://chatterbot.readthedocs.io/en/stable/training.html