Build your own chatbot
using Python
Anirudh Rao
Great Learning
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Session Takeaways
Build your own chatbot using Python
● Introduction to chatbots
● Types of chatbots
● Top applications of chatbots
● Architecture of chatbots
● How does a chatbot work?
● Practical demonstration in Python
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Did you know?
Python is the world’s most popular programming language!
● Popular streaming services make use of Python extensively.
● The name Python is derived from a TV show.
● Very popular for Natural Language Processing (NLP)
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Introduction to Chatbots
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Introduction to Chatbots
What are chatbots?
● Chatbots are simulations which can understand human language, process it
and interact back with humans while performing specific tasks.
● The first chatbot was created by Joseph Wiesenbaum in 1966, named Eliza.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Introduction to Chatbots
History of chatbots
“ Can machines think like humans? ”
- Alan Turing
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Introduction to Chatbots
History of chatbots
Eliza – 1966
Parry – 1972
A.L.I.C.E – 1995
Smarter Child – 2001
SIRI – 2010
Google Now – 2012
Alexa - 2015
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Types of Chatbots
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Types of Chatbots
Important types:
Text-based chatbots Voice-based chatbots
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Types of Chatbots
Chatbots are designed using these approaches:
Rule-based Chatbot: Bot answers questions based on some rules on which
it is trained on. The rules defined can be very simple to very complex.
Self-learning Chatbot: Bot that learns how to communicate using the result
of a machine learning model to learn and assess current situation.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Top applications
of chatbots
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Top applications of chatbots
Hundreds of applications today
Helpdesk assistant Email distributor Home assistant
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Top applications of chatbots
Hundreds of applications today
Operations assistant Phone assistant Entertainment assistant
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Architecture
of chatbots
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Architecture of chatbots
A typical chatbot architecture should consist of:
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Very important steps:
1. Import corpus
2. Preprocess the data
3. Text case handling
4. Tokenization
5. Stemming
6. Bag of Words (BOW)
7. One hot encoding
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Corpus:
● Corpus is the training data needed for the chatbot to learn.
● Without a corpus, it is impossible for a chatbot to learn and reply
something useful back to the user.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Data preprocessing - text case handling:
● Convert all the data coming as an input to either upper or lower case.
● This will avoid misrepresentation and misinterpretation of words if
spelt under lower or upper cases.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Tokenization:
Tokenization is the structured process of converting
a sentence into individual collection of words.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Stemming:
Stemming is a process of finding similarities
between words with the same root words.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
Generating Bag Of Words (BOW):
Process of converting words into numbers by generating
vector embeddings from the tokens generated.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
How does a chatbot work?
One hot encoding:
One hot encoding is a process by which categorical variables
are converted into a form that ML algorithms use.
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Practical demonstration
using Python
Proprietary content. © Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.