Chatbots already have many good implementations, such as Turing Bot and Microsoft Ice, which are very intelligent and sound like humans. However, this is not a one-size-fits-all thing. In certain scenarios, the answers to the questions are bounded or tailored to specific business scenarios, so there is still a need for robots that can be customized and developed on demand.

The chatterBot project is an open source project designed to implement chatterBot in Python. Here are some details on how to implement chatterBot and how to customize it:

ChatterBot divides a robot into input Adapter, Logic Adapter, storage Adapter, Output Adapter, and Trainer module.

Input Adapter: This module is designed to get and process user input, which means automatically getting input from external sources, such as gitter room, Twitter, etc. These are input plug-ins that come with the project. Processing user input converts the retrieved input into a Statement object that can be processed further. The Statement object is an abstraction of user input. It contains input text, additional information, and provides methods for serialization and comparison. The Input Adapter is designed to be plug-in, so in practice we can implement our own input Adapter, such as typing an ID for each user, so that the input contains the user’s information, and then we can implement different logic for different users in subsequent processing.

logic Adapter: This is still a plug-in design. When the main process is started, all the logic processing plug-ins defined by the user will be added to the Logic context, and then handed to the MultiLogicAdapter for processing. MultiLogicAdapter calls each LogicAdapter in turn. When logic Adapter is called, can_process is executed to determine whether the input can match the logic processing plug-in. For example, “What’s the weather like today?” obviously needs to hit the weather plugin, but the can_process method of the time plugin should return False. After hitting the target, the logic Adapter calculates the corresponding response (also packaged as a Statement object) and confidence. The MultiLogicAdapter takes the most reliable response and proceeds to the next step. The project has come with many logic Adapters, including close match, Close meaning, time logic, mathematical logic, and even emotional logic, which you can explore by yourself. In practice, we still need to customize some logic processing plug-ins. If we want our logic processing plug-in to always have a higher priority than the native plug-in, we can increase the confidence. The native logic processing plug-in can return a maximum of 1 confidence. Any confidence greater than 1 is the highest priority.

storage Adapter: When we introduced logic Adapter, we did not mention that most of the logic processing is based on the training set, which needs to be matched with the training set during processing. Therefore, this project also makes the persistence of the training set plug-in, including file type (JSON format), mongodb. We can also do our own persistence layer, such as support redis, support mysql.

Output Adapter: This module is basically the same as the input Adapter, except that it handles output. It is also plug-in design, so we can also customize development, for example, with Tencent and other voice synthesis service providers interface integration, our robot can “speak”.

Trainer: This module provides training methods for the robot. There are two built-in methods. One is to train the robot by typing the list, such as “Hello”, “hello”, which is the former’s answer, and the other is to train the robot by importing the Corpus format file. We can write our own training modules if neither of these approaches is possible, but in general, the final training set should be converted into the two types described above.

Conclusion: ChatterBot is not a perfect chatbot project (if you want to get a chatty bot as soon as you install it, you can drop it). Overall, the features are limited, but the project is not easy because the structure is very clear and highly plug-in. So it’s very suitable to do custom development on this basis, so go ahead.