0% found this document useful (0 votes)
25 views3 pages

Basic Chatbot

This project presents the development of a text-based chatbot using Python's NLTK and spaCy libraries, capable of interacting with users by identifying intents and providing relevant responses. The chatbot is designed for basic conversation, greeting users, and answering simple queries, showcasing the application of natural language processing techniques. The implementation serves as a foundation for further enhancements using machine learning and deep learning for more advanced conversational AI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Basic Chatbot

This project presents the development of a text-based chatbot using Python's NLTK and spaCy libraries, capable of interacting with users by identifying intents and providing relevant responses. The chatbot is designed for basic conversation, greeting users, and answering simple queries, showcasing the application of natural language processing techniques. The implementation serves as a foundation for further enhancements using machine learning and deep learning for more advanced conversational AI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Text-Based Chatbot using NLTK

and spaCy

Submitted by

Amit Bikram Mishra


B.Tech, Computer Science and Engineering

Department of Computer Science and Engineering


Ideal Institute of Engineering
May 2025
Amit Bikram Mishra Text-Based Chatbot

Abstract
This project focuses on building a simple text-based chatbot using Natural Language
Processing (NLP) libraries like NLTK and spaCy in Python. The chatbot interacts with
users by identifying intents based on user input and responding with relevant answers.
This demonstrates how basic NLP and rule-based logic can be combined to simulate
conversational AI effectively.

Introduction
Chatbots have become a popular tool for user interaction in various fields such as cus-
tomer support, education, and healthcare. This project presents a text-based chatbot
developed using Python’s NLTK and spaCy libraries. The bot is capable of greeting
users, answering simple queries, and handling basic conversation using natural language
processing techniques.

Tools & Technologies


The following tools and libraries were used in this project:
• Python: Main programming language.
• NLTK (Natural Language Toolkit): Used for tokenization and basic NLP
preprocessing.
• spaCy: Used for intent detection and named entity recognition.
• VS Code: IDE used to write and run the code.

Code
Chatbot Python Code
1 import nltk
2 import spacy
3 from nltk . tokenize import word_tokenize
4 import random
5
6 nlp = spacy . load ( " en_core_web_sm " )
7
8 responses = {
9 " greeting " : [ " Hi there ! " , " Hello ! " , " Hey ! " , " Hi ! How can I help you
?"],
10 " how_are_you " : [ " I ’m doing great , thanks for asking ! " , " I ’m just a
bot , but I ’m doing fine ! " ] ,
11 " weather " : [ " The weather is always perfect in the cloud ! " , " Sunny
with a chance of code . " ] ,
12 " name " : [ " You can call me ChatBot ! " , " I ’m your friendly chatbot . " ] ,
13 " goodbye " : [ " Goodbye ! " , " See you later ! " , " Bye ! Have a great day ! "
],

Page 1
Amit Bikram Mishra Text-Based Chatbot

14 " default " : [ " I ’m not sure I understand . Can you rephrase ? " , "
Interesting ! Tell me more . " ]
15 }
16
17 def get_intent ( user_input ) :
18 doc = nlp ( user_input . lower () )
19 if any ( token . lemma_ in [ ’ hi ’ , ’ hello ’ , ’ hey ’] for token in doc ) :
20 return " greeting "
21 elif " how " in user_input and " you " in user_input :
22 return " how_are_you "
23 elif " weather " in user_input :
24 return " weather "
25 elif " your name " in user_input or " who are you " in user_input :
26 return " name "
27 elif any ( token . lemma_ in [ ’ bye ’ , ’ goodbye ’ , ’ see you ’] for token in
doc ) :
28 return " goodbye "
29 else :
30 return " default "
31
32 def chat () :
33 print ( " ChatBot : Hello ! Type ’ bye ’ to exit . " )
34 while True :
35 user_input = input ( " You : " )
36 if user_input . lower () in [ ’ bye ’ , ’ exit ’ , ’ quit ’ ]:
37 print ( " ChatBot : " , random . choice ( responses [ " goodbye "
]) )
38 break
39 intent = get_intent ( user_input )
40 reply = random . choice ( responses [ intent ])
41 print ( " ChatBot : " , reply )
42
43 if __name__ == " __main__ " :
44 chat ()

Conclusion
This project showcases how basic natural language processing techniques using NLTK
and spaCy can be applied to build a simple conversational chatbot. While the chatbot
is rule-based, it lays a strong foundation for further development using machine learn-
ing and deep learning for advanced conversational AI. This practical implementation
demonstrates the usefulness of Python NLP libraries in creating engaging and responsive
applications.

Page 2

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