0% found this document useful (0 votes)
31 views20 pages

ANKUSH

The document discusses a chatbot project implemented using NLTK. It describes how chatbots work and the different types. It then provides the code to implement a basic question answering chatbot covering topics like science, psychology and economics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views20 pages

ANKUSH

The document discusses a chatbot project implemented using NLTK. It describes how chatbots work and the different types. It then provides the code to implement a basic question answering chatbot covering topics like science, psychology and economics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

ARTI

FICIAL INTELLIGENCE [417]

PROJECT

CHATBOT

ANKUSH.N

X ‘I’

4
ACKNOWLEDGEMENT

I would like to express my sincere thanks to Meena Aunty, Principal Mrs. S.


Amudhalakshmi for their encouragement and support to work on this Project. I am

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

Natural Language Toolkit

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.

Some basic concepts


The language of computers is Numerical, so it has to be converted into numbers via the following
steps:

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.

Removing Stopwords, Special Characters and Numbers


The tokens which are not necessary are removed from the token list.
Converting text to a common case
This ensures that the case-sensitivity of the machine does not consider same words as different just
because of different cases.

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

How do chatbots work?

Driven by AI, automated rules, natural-language processing (NLP), and machine learning (ML),
chatbots process data to deliver responses to requests of all kinds.

There are two main types of chatbots.

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()

from nltk.tokenize import sent_tokenize,word_tokenize

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")

while "quit" not in g1:

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:

print("\nKnowyBot : excellent ! lets talk about", 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:

user=input("\nKnowyBot :RNA was the first molecule on earth to be self-replicate and


begin the process of evolution that led to more anvance form of life,including human .....would you
like to continue? \nGuest : ")

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:

print("KnowyBot : You seem undecided ")

q=1

break

elif a in ansn:

print("\nKnowyBot: OK! Lets go back to the main topics ")

q=2

break

else:

print("KnowyBot : You seem undecided ")

q=1

break
elif a in ansn:

q=2

continue

user=input("\nKnowyBot: OH OK Would you prefer some other topic?\nGuest : ")

g1=nltk.word_tokenize(user)

for a in g1:

if a in ansy:

continue

elif a in ansn:

q=1

break

else:

print("KnowyBot : You seem undecided")

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:

user=input("\nKnowyBot : Brilliant!did you know that the human attention span is


shorter than a goldfish. Would you like to continue? \nGuest : ")

g1=nltk.word_tokenize(user)
for a in g1:

if a in ansy:

user=input("\nKnowyBot :The humain brain can store an estimated 2,500,000


gigabytes.Memories are stored for both short-term and long-term use at the same time .... Thats all for
now in psycology ... \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:

print("KnowyBot : You seem undecided ")

q=1

break

elif a in ansn:

print("\nKnowyBot: OK! Lets go back to the main topics ")

q=2

break

else:

print("KnowyBot : You seem undecided ")

q=1
break

elif a in ansn:

q=2

continue

user=input("\nKnowyBot: OH OK Would you prefer some other topic?\nGuest : ")

g1=nltk.word_tokenize(user)

for a in g1:

if a in ansy:

continue

elif a in ansn:

q=1

break

elif a=="economics":

user=input("\nKnowyBot : Economics was originally called 'political economy.would you like


to know more? \nguest : ")

g1=nltk.word_tokenize(user)

for a in g1:

if a in ansy:

user=input("\nKnowyBot : Brilliant!The Nobel Prize in Economics is not a real Nobel


Prize.Would you like to continue? \nGuest : ")

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:

print("KnowyBot : You seem undecided ")

q=1

break

elif a in ansn:

print("\nKnowyBot: OK! Lets go back to the main topics ")

q=2

break

else:

print("KnowyBot : You seem undecided ")

q=1

break
elif a in ansn:

q=2

continue

user=input("\nKnowyBot: OH OK Would you prefer some other topic?\nGuest : ")

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:

print("\nKnowyBot: Ok come back Later")

fq=1

break

elif a in ansn:

print("\nKnowyBot: Ok come back Later")

fq=1

break

else:

if q==1:

print("\nKnowyBot: Ok come back Later")


print("bye")

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:

user=input("\nKnowyBot: Do you want to quit?\nGuest: ")

g1=nltk.word_tokenize(user)

for a in g1:

if a in ansy:

print("\nKnowyBot: Ok come back Later")

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

KnowyBot : excellent ! lets talk about science

Would you like to know how life began ???

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

Sorry! I did not understand.. Can you type a specific topic?

Guest: psychology

KnowyBot : Today is a great day. What topic would you like to talk about ?
(quit to leave)

Guest : psychology

KnowyBot : excellent ! let's talk about 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 ...

Do you want to continue with any other topic?

Guest : no

KnowyBot: Ok come back Later

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/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy