DEV Community

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

Posted 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.

conversations: 
# Your input
- - hello
# Bot response
-   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

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

Discussion (2)

Collapse
jamespiatczanyn profile image
James Piatczanyn • Edited on

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..