DEV Community

Cover image for Facebook Unofficial API + Chatterbot Bot Part 4: Bot see Bot do
Takunda Madechangu
Takunda Madechangu

Posted on

Facebook Unofficial API + Chatterbot Bot Part 4: Bot see Bot do

Unless you teach your bot new tricks its going to remain dum.

Hello everyone. In this tutorial we are going to teach our bot some new tricks

Training your chatbot

As i browsed the web i only found two way to train your chatbot:

  • Using Listrainer class
  • Using chatterbot corpus

Using ListTrainer class

Import libraries
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
Enter fullscreen mode Exit fullscreen mode
Create bot and start training
chatbot = ChatBot('Training Example')

trainer = ListTrainer(chatbot)

trainer.train([
    "Hi there!",
    "Hello",
])

trainer.train([
    "Greetings!",
    "Hello",
])
Enter fullscreen mode Exit fullscreen mode

Its that simple

Using Chatterbot Corpus

According to the documentation:

Chatterbot corpus is a corpus of dialog data that is included in the chatterbot module.

Corpus data is user contributed, but it is also not difficult to create one if you are familiar with the language. This is because each corpus is just a sample of various input statements and their responses for the bot to train itself with.

Installing chatterbot-corpus module

pip install chatterbot-corpus

In most cases chatterbot-corpus is not installed by default so you have to install it.

Using the corpus

Forgive me i am thinking of the corpus callosum right now. I must be mad right?

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

'''
This is an example showing how to create an export file from
an existing chat bot that can then be used to train other bots.
'''

chatbot = ChatBot('Export Example Bot')

# First, lets train our bot with some data
trainer = ChatterBotCorpusTrainer(chatbot)

trainer.train('chatterbot.corpus.english')
Enter fullscreen mode Exit fullscreen mode

All this stuff can be done from a separate file as long as you specify the correct bot name.

THE THIRD WAY

After some experimentation i discovered that the corpus is not that smart, you can get easily detected by someone who knows how you chat. We could use ListTrainer right?

Heart hell no

You cant anticipate every conversation, it would take you days if not months or years to include every possible use case. So what should do we do? Curse fbchat and chatterbot authors?........Nope

What if we make chatbot take notes silently as we chart. We do the chitty chat chat and chatbot simply learns from the boss. One day when we are confident enough.......We unleash the beast

Until next time. See you next tutorial

Bye bye

Top comments (0)