Skip to content

Instantly share code, notes, and snippets.

@acidzebra
Created July 27, 2019 12:59
Show Gist options
  • Save acidzebra/26ccbc01f6eadb335dfc2e9bf628fe1c to your computer and use it in GitHub Desktop.
Save acidzebra/26ccbc01f6eadb335dfc2e9bf628fe1c to your computer and use it in GitHub Desktop.
chatterbot_listtrainer.py
import chatterbot
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer
from chatterbot import filters
from chatterbot import comparisons
from chatterbot import response_selection
import asyncio
import anki_vector
from anki_vector.util import degrees
import time
import nltk
import ssl
import io
import logging
import re
myFile=io.open("TEXT_FILE_FOR_TRAINING","r",encoding="utf-8")
lines=myFile.read()
print("file read, processing")
x = re.split('\.|\?|\!', lines)
x = list(filter(None, x))
print ("splitting and filtering complete")
for i in range(0,len(x)):
x[i]=x[i].strip()
x[i]=x[i].replace("\n","")
print ("strip and replace complete")
chatbot1 = ChatBot(
'Blinky',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
database_uri='sqlite:///chatbotinkydb3.sqlite3'
)
print ("training bot on corpus")
# create trainers and train the bots
trainer1 = ChatterBotCorpusTrainer(chatbot1)
trainer1.train("chatterbot.corpus.english")
print ("training bot on list data")
trainer1 = ListTrainer(chatbot1)
trainer1.train(x[:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment