How to build ‘Hello World!’ bot with DeepPavlov in 4 steps

Vasily Konovalov
Dec 11, 2018 · 4 min read

DeepPavlov is a conversational artificial intelligence framework that contains all the components required for building chatbots. DeepPavlov is developed on top of the open source machine learning frameworks TensorFlow and Keras. It is free and easy to use. This is the first in a series of articles on the DeepPavlov framework for natural language processing (NLP). It shows how to build a pattern-matching chatbot with our framework.

Introduction

A chatbot is a conversational AI system that is able to communicate with a human in a natural language. It can be integrated into websites, messaging platforms, and devices. Your company might delegate routine tasks to a chatbot, which will be able to process multiple user requests simultaneously. Unlike humans, chatbots are always available to assist you and provide huge labor cost savings. In addition, people are often fond of exploring chatbot abilities and trying something new.

Historically, chatbots can be divided into two large groups: rule-based and data-driven. Rule-based chatbots rely on predefined commands and templates. Each of these commands should be written by a chatbot developer using regular expressions and textual data analysis. Instead, data-driven chatbots rely on machine learning models pre-trained on dialogue data.

When you want to create your first chatbot the hardest problem is how to start. What are the main parts of the bot? How to build them and make them work together? You will find answers to these questions in this article.

To keep things simple, let us start with the most basic elements of a dialogue. First, the chatbot needs to understand utterances in a natural language. The Natural Language Understanding (NLU) module translates a user query from natural language into a labeled semantic representation. For example, the utterance “Please set an alarm for 8 a.m.” will be translated into a machine-understandable form like set_alarm(8 am). Then the bot has to decide what is expected of it. The Dialogue Manager keeps track of the dialogue state and decides what should be answered to the user. At the last stage, the Natural Language Generator (NLG) translates a semantic representation back into human language. For example, rent_price(Atlanta)=3000 USD translates to “The average rent price in Atlanta is around $3,000. The picture below shows a typical dialogue system architecture.

Picture 1. Dialogue system architecture

Now you know enough theory to implement an introductory level chatbot with the open-source DeepPavlov framework. The code of the article can be found in the Colab notebook.

DeepPavlov: 1st run

Possibly the most delightful part of discovering a new programming framework is the “Hello, world!” example. Our HelloBot will be able to recognize a greetings message and reply with “Hello world!” In addition, upon receiving a goodbye message, it will respond with one of the predefined goodbye messages. Otherwise, it will reply with the message “I don’t understand, sorry.

Before delving into the code, it would be useful to explain in general terms how DeepPavlov works. All Skill-related classes are usually associated with dialogue tasks and solve a single NLP task. The Agent comprises several Skills and can switch between them. It can be a dialogue system that contains a range of goal-oriented and chatbot skills and chooses which one to use for generating the answer depending on user input. The Skill Manager performs a selection of the Skill to generate a response as on the scheme below.

Picture 2. Agent architecture

Step 1

You can install DeepPavlov locally with pip install deeppavlov or you can play with HelloBot code in Colaboratory via the link.

Step 2

Import all essential packages.

Step 3

Then create Skills with corresponding patterns and predefined responses.

Step 4

The Agent executes Skills and then takes the highest-confidence responses from them.

Basically, a HelloBot is a classical rule-based chatbot: it searches for known keywords and returns one of the several possible responses. Now let’s move to a chatbot that will be able to imitate natural human communication to some extent. ELIZA was the first bot developed to demonstrate the superficiality of communication between humans and machines. It was created by Joseph Weizenbaum in 1966 at the MIT AI Lab. It is the first known chatbot capable of taking the Turing test. ELIZA mimicked human communication through pattern matching and substitutions without the need to understand the meaning behind utterances. It generated natural dialogues with the help of prewritten scripts. These scripts were able to handle dialogue inputs to respond accordingly. Now let’s move directly to implementation. For every dialogue scenario, we create a Skill.

Do not hesitate to add more Skills in the same manner. Now you know how to create simple rule-based chatbots by using the DeepPavlov framework. In the next article, we will describe techniques that will help you develop more advanced chatbots.

The DeepPavlov documentation and code repository are accessible at deeppavlov.ai.


I would like to thank Mikhail Burtsev, Luiza Sayfullina, Olga Kairova, and the entire team of the iPavlov lab for the insightful comments.

DeepPavlov

An open-source library for deep learning end-to-end dialog systems and chatbots / DeepPavlov.ai

Vasily Konovalov

Written by

Machine Learning and Natural Language Processing expert at iPavlov lab.

DeepPavlov

An open-source library for deep learning end-to-end dialog systems and chatbots / DeepPavlov.ai