Skip to content

Commit

Permalink
Add training class for Ubuntu corpus
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Nov 9, 2016
1 parent 3286e4c commit ee96ce0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ docs/_build/
*.iml

examples/settings.py
examples/ubuntu_dialogs*
26 changes: 26 additions & 0 deletions chatterbot/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,29 @@ def train(self):
statements = self.get_statements()
for statement in statements:
self.storage.update(statement, force=True)


class UbuntuCorpusTrainer(Trainer):

def extract(self, file_path):
import tarfile

self.logger.info('Starting file extraction')

extracted_directory_path = ''

def track_progress(members):
for member in members:
# this will be the current file being extracted
yield member
print('Extracting {}'.format(member))

with tarfile.open(file_path) as tar:
tar.extractall(members=track_progress(tar))

self.logger.info('File extraction complete')

return extracted_directory_path

def train(self):
data_directory = self.extract('C:/Users/Gunther/GitHub/ChatterBot/examples/ubuntu_dialogs.tgz')
23 changes: 23 additions & 0 deletions examples/ubuntu_corpus_training_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from chatterbot import ChatBot
import logging


'''
This is an example showing how to train a chat bot using the
Ubuntu Corpus of conversation dialog.
'''

# Enable info level logging
logging.basicConfig(level=logging.INFO)

chatbot = ChatBot(
'Example Bot',
trainer='chatterbot.trainers.UbuntuCorpusTrainer'
)

# Start by training our bot with the Ubuntu corpus data
chatbot.train()

# Now let's get a response to a greeting
response = chatbot.get_response('How are you doing today?')
print(response)

0 comments on commit ee96ce0

Please sign in to comment.