ANKUSH
ANKUSH
PROJECT
CHATBOT
ANKUSH.N
X ‘I’
4
ACKNOWLEDGEMENT
grateful to my Computer Science teacher Mrs. K. Manjula and to the Computer Science
department for the constant guidance and support to complete the project.
INDEX
S.NO TOPIC PAGE NO.
Overview
1 5
2 Project Description 7
3 Programs 8
4 Outputs 18
5 Bibliography 21
Project Overview
The Natural Language Toolkit (NLTK) is a platform used for building Python programs that work with
human language data for applying in statistical Natural Language Processing (NLP). Natural Language
Processing, is the sub-field of AI that is focused on enabling computers to understand and process
human languages.
It contains text processing libraries for tokenization, parsing, classification, stemming, tagging and
semantic reasoning. It also includes graphical demonstrations and sample data sets and a book which
explains the principles behind the underlying language processing tasks that NLTK supports.
Applications of nltk
Chatbots
One of the most common applications of Natural Language Processing is a chatbot. There are a lot of
chatbots available for different applications.
Text Normalisation
To clean up the textual data in such a way that it comes down to a level where its complexity is lower
than the actual data.
Sentence Segmentation
Under sentence segmentation, the whole corpus is divided into sentences. Each sentence is taken as a
different data so now the whole corpus gets reduced to sentences.
Tokenization
After segmenting, each sentence is then further divided into tokens. Token is any word or number or
special character occurring in a sentence.
Stemming
The words are reduced to their root words. In other words, stemming is the process in which the affixes
of words are removed and the words are converted to their base form.
Lemmatization
Stemming and lemmatization both are alternative processes to each other as the role of both the
processes is same – removal of affixes. In lemmatization, the word we get after affix removal (also
known as lemma) is a meaningful one. Hence it takes a longer time to execute than stemming.
Bag of Words
Tokens are converted into numbers.
Installation
pip install nltk
Implementation
import nltk
nltk.download()
NLTK comes with many corpora, trained models, etc. To install the data, we have to first install
NLTK, then use NLTK’s data downloader when running the program for the first time.)
PROJECT DESCRIPTION
Driven by AI, automated rules, natural-language processing (NLP), and machine learning (ML),
chatbots process data to deliver responses to requests of all kinds.
Task-oriented (declarative) chatbots are single-purpose programs that focus on performing one
function. Using rules, NLP, and very little ML, they generate automated but conversational
responses to user inquiries. Interactions with these chatbots are highly specific and structured
and are most applicable to support and service functions—think robust, interactive FAQs. Task-
oriented chatbots can handle common questions, such as queries about hours of business or
simple transactions that don’t involve a variety of variables. Though they do use NLP so end
users can experience them in a conversational way, their capabilities are fairly basic. These are
currently the most commonly used chatbots.
Data-driven and predictive (conversational) chatbots are often referred to as virtual assistants or
digital assistants, and they are much more sophisticated, interactive, and personalized than task-
oriented chatbots. These chatbots are contextually aware and leverage natural-language
understanding (NLU), NLP, and ML to learn as they go. They apply predictive intelligence and
analytics to enable personalization based on user profiles and past user behavior. Digital
assistants can learn a user’s preferences over time, provide recommendations, and even anticipate
needs. In addition to monitoring data and intent, they can initiate conversations. Apple’s Siri and
Amazon’s Alexa are examples of consumer-oriented, data-driven, predictive chatbots
PROGRAMS
import nltk
#nltk.download()
topics=["science","psychology","economics","computers","art","games","movies"]
ansy=["yes","ya","ok","little","maybe","yeah"]
ansn=["no","nope","n","not","quit","nothing","bye"]
g1=[]
q=0
a=0
fq=0
c=1
print("\t\t\t KNOWYBOT\n")
print("science\npsychology\neconomics\nart\ngames\nmovies\n")
print("Currently the THREE topics Science, psycology and economics is available on chat\n")
if a in ansn:
user=input("\nKnowyBot : What topic would you like to talk about ?\nGuest : ")
else:
user=input("\nKnowyBot : Today is a great day. what topic would you like to talk about ?\n(quit to
leave)\nGuest : ")
g1=nltk.word_tokenize(user)
for a in g1:
if a in topics or user==a:
if a=="science":
user=input("\nwould you like to know how life began ??? \nguest : ")
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
user=input("\nKnowyBot : Did you know that our stomach acid is strong enough to
dissolve stainless steel?..... Thats all for now in science..any other topic?\nGuest : ")
g1=nltk.word_tokenize(user)
for a in g1:
if a in topics:
continue
elif a in ansn:
q=1
break
else:
q=1
break
elif a in ansn:
q=2
break
else:
q=1
break
elif a in ansn:
q=2
continue
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
continue
elif a in ansn:
q=1
break
else:
q=1
break
elif a=="psychology":
user=input("\nKnowyBot : Do you know that Psychology is the scientific study of mind and
behavior. Psychology includes the study of conscious and unconscious phenomena, including feelings
and thoughts.would you like to know more?\nguest : ")
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
c=1
continue
elif a in ansn:
q=1
break
else:
q=1
break
elif a in ansn:
q=2
break
else:
q=1
break
elif a in ansn:
q=2
continue
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
continue
elif a in ansn:
q=1
break
elif a=="economics":
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
user=input("\nKnowyBot :Did you know that Switzerland and Singapore are not
living off banking and tourism alone? .... Thats all for now in economics... \n Do you want to continue
with any other topic?\nGuest : ")
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
c=1
continue
elif a in ansn:
q=1
break
else:
q=1
break
elif a in ansn:
q=2
break
else:
q=1
break
elif a in ansn:
q=2
continue
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
continue
elif a in ansn:
q=1
break
elif a in ansn:
fq=1
break
elif a in ansn:
fq=1
break
else:
if q==1:
break
elif q==2:
continue
else:
user=input("Sorry! I did not understand.. can you type a specific topic?\nGuest: ")
g1=nltk.word_tokenize(user)
for a in g1:
if a in topics:
user=a
continue
else:
g1=nltk.word_tokenize(user)
for a in g1:
if a in ansy:
fq=1
break
elif a in ansn:
continue
if fq==1:
print("Bye")
break
OUTPUT
science
psychology
economics
art
games
movies
Currently the THREE topics Science, psychology and economics is available on chat
KnowyBot : Today is a great day. What topic would you like to talk about ?
(quit to leave)
Guest : science
guest : ya
KnowyBot :RNA was the first molecule on earth to be self-replicated and begin the process of
evolution that led to more advanced forms of life,including humans .....would you like to continue?
Guest : ya
KnowyBot : Did you know that our stomach acid is strong enough to dissolve stainless steel?..... That's
all for now in science..any other topic?
Guest : psychology
Guest: psychology
KnowyBot : Today is a great day. What topic would you like to talk about ?
(quit to leave)
Guest : psychology
KnowyBot : Do you know that Psychology is the scientific study of mind and behavior. Psychology
includes the study of conscious and unconscious phenomena, including feelings and thoughts.would
you like to know more?
guest : ya
KnowyBot : Brilliant!Did you know that the human attention span is shorter than a goldfish. Would you
like to continue?
Guest : ya
KnowyBot :The human brain can store an estimated 2,500,000 gigabytes.Memories are stored for both
short-term and long-term use at the same time .... That's all for now in psychology ...
Guest : no
bye
>>>
BIBLIOGRAPHY
https://en.m.wikipedia.org/wiki/Chatbot
https://www.analyticsvidhya.com/blog/2021/12/creating-chatbot-building-using-python/
https://www.edureka.co/blog/how-to-make-a-chatbot-in-python/
https://www.upgrad.com/blog/how-to-make-chatbot-in-python/
https://www.huffingtonpost.co.uk/hajoon-chang/economics-facts_b_5511565.html
https://www.geeksforgeeks.org/how-to-download-install-nltk-on-windows/
https://leverageedu.com/blog/psychology-facts/