DEV Community

Cover image for Quick guide to create a custom ChatterBot corpus
Ash Freels
Ash Freels

Posted on • Updated on

Quick guide to create a custom ChatterBot corpus

The ChatterBot python library is a great introduction to machine learning. It is very easy to create and train your own custom data by creating a YAML file. Luckily, ChatterBot has a custom corpus file and folder where you can add the content you want for the chat bot.

Naming a category

You want to start off naming the corpus category. It can be any topic you want.

categories:
- Hello
Enter fullscreen mode Exit fullscreen mode

Writing dialog

Added dialog is important if you want the chat bot to reply with a specific answer. Your input is denoted by - - while the response for the bot is starts with - . After when you are done save the file in the custom folder. You can also add multiple YAML files to the custom folder.

conversations: 
# Your input
- - hello
# Bot response
-   world
Enter fullscreen mode Exit fullscreen mode

The YAML file should look like this:

categories:
- Hello
conversations: 
- - hello
  - world
Enter fullscreen mode Exit fullscreen mode

Training the custom file

You can now train the bot with the custom corpus that you created.

trainer = ChatterBotCorpusTrainer(bot)
trainer.train('chatterbot.corpus.custom')

Enter fullscreen mode Exit fullscreen mode

The bot can be trained with multiple files within a folder. For example, we have a folder with various YAML files.

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

That's it for the quick introduction. For more information visit ChatterBot for documentation.

Top comments (5)

Collapse
 
jamespiatczanyn profile image
James Piatczanyn • Edited

Hi, how do you access the custom corpus file and folder? I've had no luck trying to locate it on my own

Collapse
 
httpanand profile image
Anand

AppData/local/Programs/Python/Python39/Lib/site-packages/chatterbot_corpus/data/custom/myown.yml

This should help :) and sry for the late reply i saw this post just now..

Collapse
 
40w2000 profile image
40w2000

Hi. Can you add multiple categories into a single YAML file or do you need separate files?

Collapse
 
codefatale profile image
Ash Freels

Hello - I created a separate folder with various YAML files .

Collapse
 
40w2000 profile image
40w2000

Thanks. I'll do that.