DEV Community

Cover image for Quick guide to create a custom ChatterBot corpus
Coding Fatale
Coding Fatale

Posted on Edited 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
✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด

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
✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด

The YAML file should look like this:

categories:
- Hello
conversations: 
- - hello
  - world
✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด

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')

✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด

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')
✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด ✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด

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

Top comments (5)

✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด
 
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

✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด
 
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..

✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด
 
40w2000 profile image
40w2000 •

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

✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด
 
codefatale profile image
Coding Fatale •

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

✨ อัปเดตล่าสุด: codefatale/quick guide to create a custom chatterbot corpus ca - สรุปดราม่าล่าสุด
 
40w2000 profile image
40w2000 •

Thanks. I'll do that.