Chatterbot Google Colab Train English Corpus


nlp

Here’s how to solve the file not found for training chatterbot on Google collab:

# Install
!pip install chatterbot
!pip install chatterbot-corpus

# move english to content viz our workign directory
import os
os.system('mv /usr/local/lib/python3.7/dist-packages/chatterbot_corpus/data/english /content/english')

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


import os
bot = ChatBot(
    'Terminal',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    logic_adapters=[
        'chatterbot.logic.BestMatch'
    ],
    database_uri='sqlite:///database.sqlite3'
)
trainer = ChatterBotCorpusTrainer(bot)
path = '/content/english'
for file in os.listdir(path):
    file_path = '/content/english/'+ file
    trainer.train(file_path)

    print('Type something to begin...')

# The following loop will execute each time the user enters input
while True:
    try:
        user_input = input()

        bot_response = bot.get_response(user_input)

        print(bot_response)

    # Press ctrl-c or ctrl-d on the keyboard to exit
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

Written by

Abdur-Rahmaan Janhangeer

Chef

Python author of 7+ years having worked for Python companies around the world

Suggested Posts

Bag of Words (BoW) in NLP: A Deep Dive into Text Vectorization

If you are trying to build a spam filter, a sentiment analyzer, or any machine learning model that p...

Read article

TF-IDF Explained: Boosting Signal in Text Vectorization

In our Bag of Words guide, we saw how to turn text into numbers by counting word frequencies. But th...

Read article

Word2Vec: Capturing Meaning in Vector Space

Bag of Words and TF-IDF are great, but they suffer from a fatal flaw: they have no concept of meanin...

Read article
Free Flask Course