Python Tutorials

Building Chatbots with Python Using Natural Language Processing and Machine Learning

Written by Rapture Godson

Building chatbots with Python is not just about completing an online tutorial or following a few steps—it’s a skill in itself.

And luckily, Sumit Raj, the author of the book Building Chatbots with Python has been able to break down the whole skill development process, even for the least reader.

Who is this book for?

  • Students and programming newbies looking to acquire a new skill.
  • Pro Python web developers looking to expand their knowledge or career in chatbots development.
  • Natural programming enthusiasts looking to learn how to build a chatbot from scratch.

So if you’re looking to learn how to start building chatbots with Python today, you will love this guide.

Let’s get started…

About the Author


Learn more about Sumit Raj

Sumit Kumar Raj is the topmost viewed writer on the Python web framework on Quora with interests in building chatbots, natural language processing, machine learning, and data science.

Sumit Raj published Building Chatbots with Python to serve as a great resource for learning the concepts related to chatbots and learning how to build them.

About the Contents 

The book is comprised of five (5) basic chapters.

  1. The beloved chatbots
  2. Natural language processing for chatbots
  3. Building chatbots the easy way
  4. Building chatbots the hard way
  5. Deploying your chatbot

Chapter #1: The Beloved Chatbots

Chapter one of the book starts by Sumit Raj showing the various applications of bots (internet bots) in our everyday life. Taking examples from Siri, IBM Watson, and Google Allo, Sumit Raj was able to point out how these bots help users become more productive at what they do.

He also went on to point out the increasing trend in chatbots development, and how API has made it really easy today to build chatbots with Python.

Chapter one of the book proceeds to describe the need for chatbots and its future… Also showing different industries that are being impacted by it today, and industries that will benefit from it in the future.


This chapter doesn’t get really interesting until page #18 where Raj starts discussing about QnA bots.

What makes this so interesting’s that: these bots are programmed to understand various user questions whose answers are already available on a FAQ page of a website.


FAQ Chatbot Example

Finally, the chapter ends with Sumit Raj describing the various basic steps involved in building a chatbot. He introduces terms like decision trees, chatbots frameworks and sheds some light on various components and terminologies used in building chatbots with Python.

Chapter #2: Natural Language Processing for Chatbots

Let’s cut to the chase…

Chapter #2 is where the fun starts!

You will get to see real-life examples and demonstrations of how Natural Language Processing  (NLP) is used for chatbots development.

Sumit Raj starts things off by carefully breaking down Spacy – which is an open-source software library for advanced NLP, written in Python and Cython. 

Next, you get to see, first-hand, the fundamental methods of NLP for building chatbots with Python. You’d get introduced to things like POS tagging, stemming and lemmatization, named-entity recognition, dependency parsing, and many more…


Starting dependency parsing server on localhost

You will be executing lots and lots of codes in this chapter, so please, don’t be in a haste. Take your time!

Make sure you’ve totally understood a certain line of code before proceeding to the next.

Chapter #3: Building Chatbots the Easy Way

Now, what is coding without a few diagrams?

This chapter will be appreciated more by non-programmers…


Well, it simply requires little or NO programming skills whatsoever!

This chapter introduces you to Dialogflow…

The best part:

You will get to build your very first food ordering chatbot!

This seems to be the longest chapter in this amazing book, as it is filled with a lot of practical exercises for you.

After building your first Dialogflow chatbot, you will also learn how to integrate it on your Facebook messenger and test it to see it in action.

Chapter #4: Building Chatbots the Hard Way

This shouldn’t scare you…

Building chatbots the hard way is not too difficult to learn!

And for those developers with a strong background in Python and how to setup packages, you won’t have any issues with this chapter.

This chapter not only teaches you how to build chatbots from scratch with Python but also shows you how core machine learning (ML) works with NLP (Natural Language Processing) with the help of Rasa NLU (Natural Language Understanding).


Diagram representing the working of Rasa NLU and Rasa Core

You will get to understand what Rasa NLU is all about and why you should start using it…

This chapter would also teach you how to build a horoscope bot that:

  • Understands greetings and replies with a greeting.
  • Understands if a user is asking for a horoscope.
  • Is able to ask the horoscope sign of a user if the user doesn’t provide one.
  • Subscribes/unsubscribes a user to get a daily horoscope.
  • Learns from existing responses to formulate a new response.
  • Handles spelling mistakes by users.

You will agree with me that: creating JSON files is quite difficult by hand, but programmatically very easy and scalable… And Rasa NLU has multiple ways of defining intents and their entities on a given data.

The chapter now proceeds to discuss the most difficult, but highly scalable method to prepare data for the chatbot.

The fun doesn’t stop there!

You will also get your hands dirty with dialog management using Rasa where you’d be training different models for Rasa Core dialog management.

I know at some point, you have witnessed a chatbot fail in certain conditions on an online platform.

Yes, a chatbot may fail to manage the contexts of a conversation miserably… But with the help of the Rasa Core’s ML-based dialog framework, you will learn how to fix these issues easily.

The chapter ends with different ways that you can use to train your chatbot before going ahead to deploy it in chapter 5.

Chapter #5: Deploying Your Chatbot

Here you’d get to see how to deploy your chatbot on different platforms like Facebook and Slack.


Creating an application in Slack

In this chapter, you’d be working a lot with Heroku – a platform that enables developers to build, run, and operate applications entirely in the cloud.

After deploying your chatbot, you will get to see how to verify your chatbot API. You will be working with the POSTMAN tool which is a very nice GUI-based tool to do API

Finally, this chapter ends with you creating your own custom chatbot UI.


This book is the most comprehensive guide I’ve ever seen on building chatbots. I came across the book in my current research for the best techniques for building chatbots and I strongly recommend it for anyone looking to improve his career in programming.


About the author

Rapture Godson

Leave a Comment