Professional Documents
Culture Documents
KoT Minor Report
KoT Minor Report
KoT Minor Report
on
Submitted to
KIIT Deemed to be University
BACHELOR’S DEGREE IN
COMPUTER SCIENCE & ENGINEERING
BY
Submitted to
KIIT Deemed to be University
BACHELOR’S DEGREE IN
COMPUTER SCIENCE & ENGINEERING
BY
CERTIFICATE
This is to certify that the project entitled
“KOT - THE KIIT CHAT BOT”
submitted by
is a record of bonafide work carried out by them, in the partial fulfillment of the
requirement for the award of Degree of Bachelor of Engineering (Computer Science &
Engineering OR Information Technology) at KIIT Deemed to be University,
Bhubaneswar. This work is done during the year 2022-2023, under our guidance.
Himansu Das
Project Guide
Acknowledgments
ANKIT KUMAR
CHITTA DAKSHESH
MEGHNA SINGH
PUNYAPU SAITEJA
ABSTRACT
Introducing KOT, a chatbot built using Python, PyTorch, NLP, and frontend. This
project aims to provide an interactive platform for students to inquire about various
services and facilities provided by KIIT University. The chatbot utilizes natural
language processing techniques and machine learning algorithms to understand user
queries and provide appropriate responses. With a user-friendly interface and 24/7
availability, KOT offers a convenient and efficient way for students to access
information and enhance their overall university experience.
Contents
1 Introduction 1
2 Theory 2
2.1 Chat Bot 2
2.2 Python Programming Language 2
2.3 Pytorch 2
2.4 Artificial Intelligence 3
2.5 Machine Learning 3
2.6 Natural language processing 3
3 Requirement Specifications 4
3.1 Functional Requirements 4
3.2 Non Functional Requirements 4
3.3 Technical Requirements 4
4 Implementation 5
4.1 Setting up the environment 6
4.2 Training Data 7
4.3 Basic NLP 8
4.4 Implement the NLP Utils 11
4.5 Neural Network 13
4.6 Training Pipeline 15
4.7 Implement The Chat 15
4.8 Website 16
4.9 Usage 17
5 Conclusion 18
5.1 Conclusion 18
5.2 Future Scope 18
References 19
List of Images
Chapter 1
Introduction
Kalinga Institute of Industrial Technology with over 25,000 students, and it is difficult
for the university staff to cater to every query promptly. To address this challenge, our
team has developed KOT a cutting-edge ChatBot which can give accurate answers to the
queries of students of the Kalinga Institute of Industrial Technology.
The primary aim of our ChatBot is to provide a seamless and interactive experience to
Kalinga Institute of Industrial Technology students through our Chatbot. Our ChatBot
is designed to go beyond simple Q&A and integrate with the university's knowledge base
to provide relevant solutions to student queries. With the ability to provide real-time
assistance to students, our chatbot is an efficient and convenient solution that can help
ease the burden on university staff, help desk and streamline administrative processes.
This report details the development and implementation of the ChatBot project for the
Kalinga Institute of Industrial Technology. The report is structured as follows: Chapter
2 discusses the basic concepts and literature review, Chapter 3 describes the problem
statement and requirement specifications, Chapter 4 outlines the implementation details,
Chapter 5 talks about the standard adopted for the project, and Chapter 6 concludes the
report and discusses future scope.
In conclusion, our ChatBot will greatly enhance the student experience at the Kalinga
Institute of Industrial Technology and revolutionize how students get the information
they need.
Fig 1.1 shows how many queries come to college officials daily.
Others
15
Reception
15
Help Desk
50
Phone Call
10
Teachers
15
Fig 1.1
02
Chapter 2
Theory
2.1 CHATBOT
A chatbot is a computer program designed to simulate conversation with human users,
especially over the internet. Chatbots can be used for various purposes, such as
customer service, information retrieval, and entertainment. They are built using natural
language processing (NLP) techniques that allow them to understand and interpret
human language.
2.3 PyTorch
PyTorch is an open-source machine-learning library based on the Torch library. It
provides an easy-to-use platform for building and training neural networks, making it a
popular choice for deep learning tasks. In our ChatBot project, PyTorch is used to
develop and train the neural network model used for intent classification and response
generation.
03
2.6 NLP
Natural Language Processing (NLP) is a subfield of computer science and artificial
intelligence that focuses on enabling computers to understand, interpret, and generate
human language. It involves developing algorithms and models that can analyze and
derive meaning from natural language data, such as text and speech. NLP has many
practical applications, including language translation, sentiment analysis, chatbots,
speech recognition, and information extraction, among others. It's a rapidly evolving
field that has seen significant advancements in recent years due to the availability of
large amounts of data and advances in machine learning and deep learning techniques.
AI
ML NLP
Fig 2.2
04
Chapter 3
Requirement Specifications
The purpose of this project is to develop a chatbot for KIIT University that can assist
users in answering their questions related to the university. The chatbot should be able
to recognize user intents and respond with appropriate answers.
By meeting these requirement specifications, the chatbot can provide a helpful and
user-friendly experience for KIIT University students, staff, and faculty, and assist
them in getting the information they need quickly and efficiently.
05
Chapter 4
Implementation
Implementation is the process of converting the design and specifications of a project
into a working and functional product. In this section of the project documentation, we
will discuss the implementation of the chatbot project.
The chatbot implementation consists of two main components: training and chat. The
training component involves feeding the chatbot with data and building a machine-
learning model based on that data. The chat component involves providing a user
interface for the chatbot and processing user input to provide appropriate responses.
The training component is implemented using Python and PyTorch. The training code
is contained in the train.py file, which reads in a JSON file containing patterns and
responses, preprocesses the data, and trains a neural network model using PyTorch.
The trained model is saved to data.pth file, which is then used by the chat component.
The chat component is implemented using HTML, CSS, and JavaScript. The chat
interface is created using HTML and styled using CSS, while the chat logic is
implemented in JavaScript. The chat logic involves processing user input, sending the
input to the chatbot, and displaying the chatbot's response to the user.
Conda intents.json
ENVIRONMENT CREATE TRAINING DATA BASIC NLP
BOW
FFNN nltk module
TRAINING PIPELINE NEURAL NETWORK NLP UTILS
Fig 4.1
06
Install Conda:
Conda is a popular package manager that makes it easy to manage packages and
dependencies. You can download and install Conda from the official website:
https://docs.conda.io/en/latest/miniconda.html
Install NLTK:
NLTK is a popular natural language processing library that we will use to tokenize our
data. You can install NLTK using the following command:
pip install nltk
Tags are labels that we assign to each intent, and they are used to train the chatbot to
recognize different types of user queries. Tags should be unique and descriptive, and
they are used to map user queries to the appropriate response.
Patterns are the actual text of a user's message or query that the chatbot uses to
recognize the intent of the message. These patterns are associated with each tag in the
training data, and they are used to train the chatbot to recognize user queries.
Responses are pre-determined text that the chatbot outputs in response to a specific
user query. Overall, the combination of intents, tags, patterns, and responses form the
foundation of a chatbot's training data and enable the chatbot to understand and
respond to user queries in a natural and human-like manner.
{
"intents": [
{
"tag": "greeting",
"patterns": [
"Hi",
"Hey",
"How are you",
"Is anyone there?",
"Hello",
"Good day"
],
"responses": [
"Hey :-)",
"Hello, thanks for visiting",
"Hi there, what can I do for you?",
"Hi there, how can I help?"
]
},
...
]
}
08
Fig 4.2
Before calculating the bag of words (bow) for each sentence, two important NLP
techniques, Tokenization and Stemming are applied.
Tokenization :
Tokenization is the process of breaking down a piece of text into smaller units called
tokens, which are typically words or phrases. This is an essential step in natural
language processing as it enables the machine to analyze and understand the meaning
of text data. Tokenization can be performed using various techniques, including
whitespace-based tokenization, regular expression-based tokenization, and rule-based
tokenization. The choice of technique depends on the specific needs of the task at hand,
but the end goal is always to transform the raw text into a structured format that can
be easily processed by a machine learning algorithm.
Example of Tokenization :
"what would you do with 1000000$?"
[ “what”, “would”, “you”, “do”, “with”, “1000000”, “$”, “?”]
09
Stemming :
Stemming is the process of reducing a word to its base or root form, known as the
stem. This is useful in natural language processing because it allows for variations of a
word to be grouped together and analyzed as a single entity. In Python, the NLTK
library provides several stemmers such as the Porter stemmer, the Lancaster stemmer,
and the Snowball stemmer. These stemmers use different algorithms to perform the
stemming process, with the Snowball stemmer being the most widely used due to its
multilingual support and customizable stemming rules. Stemming is a crucial step in
text preprocessing for many NLP applications such as information retrieval, sentiment
analysis, and topic modeling.
Example of Stemming :
[“organize”, “organizes”, “organizing”]
[ “organ”, “organ”, “organ”]
Bag Of Words :
The bag of words (BOW) representation is a way to convert textual data into a
numerical format that machine learning algorithms can process. It involves creating a
vector for each sentence in the dataset, with each dimension of the vector representing a
specific word in the vocabulary. The value in each dimension is either 1 or 0, indicating
whether or not the corresponding word appears in the sentence.
For example, if our vocabulary consists of the words "hello", "world", "how", and
"are", and we have the sentence "Hello, how are you?", its BOW representation would
be [1, 0, 1, 1], since "hello" and "how" both appear in the sentence, while "world" and
"are" do not.
To create the BOW representation, we first tokenize the sentence to obtain a list of
words, then create an empty vector with the same length as the vocabulary. We then
iterate through each word in the sentence, and if it appears in the vocabulary, we set
the corresponding dimension of the vector to 1. Finally, we have a numerical
representation of the sentence that can be fed into a machine-learning algorithm.
It's worth noting that the BOW representation doesn't capture any information about
the order or context of the words in the sentence. Therefore, it's often used in
combination with other techniques, such as word embeddings, to create a more
nuanced representation of the textual data.
10
I love this movie! It's sweet, but I 1
with satirical humor. The dialogue love 2
is great and the adventure scenes this 3
movie 4
are fun... It manages to be
It's 2
whimsical and romantic while sweet 3
laughing at the conventions of the but 1
fairy tale genre. I would with 0
recommend it to just about satirical 4
anyone. I've seen it several times, always 3
and I'm always happy to see it happy 2
see 4
again whenever I have a friend
..... ....
who hasn't seen it yet!
Fig 4.3
"Where is KIIT?"
Tokenization
Input For
X[0,0,1,0,1,1,0,0] Neural Network
Fig 4.4
Once tokenization and stemming are applied to the training data, we proceed to create
an array of all the unique words in the dataset. This array serves as a reference for
creating the bag of words representation of each sentence. The bag of words has the
same size as the array of all words, with each position indicating the presence (1) or
absence (0) of a word in the incoming sentence.
To label the training data, we sort the intents alphabetically and assign a unique index
to each intent. This index serves as the class label for each intent, which the neural
network will use to classify new input data.
11
Fig 4.5
NLTK provides a variety of useful methods that we can utilize for our chatbot
implementation.
The code defines a set of utility functions in a module called nltk_utils.py to preprocess
the text data for our chatbot. It uses the nltk library which is a leading platform for
building Python programs to work with human language data.
def tokenize(sentence):
return nltk.word_tokenize(sentence)
12
The second function stem(word) takes a word and returns its root form by using the
PorterStemmer algorithm from the nltk library. It uses a crude heuristic that chops off
the ends of words to find their root form. For example, the words "organize",
"organizes", and "organizing" will all be stemmed to "organ".
def stem(word):
return stemmer.stem(word.lower())
The bag of words has the same size as the array of all words, and each position
contains a 1 if the word is present in the incoming sentence or 0 otherwise. The function
first stems each word in the tokenized sentence, and then initializes the bag with 0 for
each word. It then loops over each word in the array of all words, and if a word is
present in the tokenized sentence, it sets the corresponding position in the bag array to
1.
All these functions together are used to preprocess the input data before feeding it into
the machine learning model. The tokenize() function is used to split a sentence into
individual words, the stem() function is used to convert each word to its root form, and
the bag_of_words() function is used to generate a bag of words representation of the
input sentence.
13
Fig 4.6
14
In other words, the function returns 0 for any negative input and the input itself for any
non-negative input. The ReLU function is popular in neural networks because it is
simple to compute and provides good results in practice. It is also known for
addressing the vanishing gradient problem that occurs in networks with deep
architectures.
The implementation is straightforward with a Feed Forward Neural net with 2 hidden
layers
The constructor initializes the linear layers, and the ReLU activation function, and
assigns them as attributes to the module. The forward method defines the forward pass
of the neural network, where the input tensor is sequentially passed through the linear
layers and the ReLU activation function.
The output we gain from the neural network model will be a tensor of shape
(batch_size, num_classes), where batch_size is the number of input examples fed to
the model at once, and num_classes is the number of output classes (in our case, 2:
positive or negative sentiment). The tensor contains the predicted scores for each
example in each class. We can use a softmax function to convert these scores into
probabilities, or we can use the class with the highest score as the predicted class.
self.layers = nn.Sequential(
nn.Linear(input_size, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, num_classes)
)
This creates a sequence of layers that are applied in order to the input tensor x.
15
Overall, the training pipeline converts the patterns into a bag of words, assigns a label
to each pattern, creates a custom dataset and data loader, trains the neural network
model using the dataset, and saves the trained model to a file for later use in the
chatbot.
The code first prompts the user for input and waits for them to type something. If the
user enters "quit", the chat loop exits. Otherwise, the input is tokenized using the same
tokenizer function we used during training. The bag of words representation of the
tokenized input is then computed using the same function as before. The bag of words
vector is then passed to the model to obtain a prediction.
If the predicted class has a probability greater than 0.75, the chatbot selects a response
from the corresponding intent at random and outputs it to the user. If the predicted
class has a probability less than or equal to 0.75, the chatbot outputs a generic "I do
not understand" message.
Overall, this implementation allows our chatbot to converse with users in a natural
language interface using the trained model. The chatbot can handle a variety of inputs
and outputs, allowing for a more engaging user experience.
16
4.8 Website
In order to run our chatbot on a website, we need to develop a user interface using
HTML, CSS, and JavaScript. The UI/UX design for the website is documented in a
Figma file located at click_here.
The color palette we used consists of KIIT University's logo colors, including a light
green background (#CFFFD7), dark green accents (#008826), and lighter green
highlights (#0FA338).
For text, we used Verdana as the primary font for its readability, while Gill Sans MT
was used for headings and other text to add a touch of elegance to the design.
We aimed to make the interface easy to navigate for users, with clear and intuitive
buttons and menus. The chatbot itself is prominently displayed in the center of the
screen, with a welcoming message inviting users to interact. The chat window is
designed to resemble a conversation bubble, with user messages on the left and chatbot
responses on the right.
Overall, our goal in designing the UI/UX for the chatbot website was to create a
professional and visually appealing design that is easy and intuitive to use for users,
while also representing KIIT University's brand and values.
We can use HTML to structure our web page, CSS to style it, and JavaScript to handle
user input and display responses from our chatbot.
We begin by creating an HTML file that contains the structure of our web page. This
includes the header, body, and footer elements, as well as any other elements that we
want to display, such as text inputs and buttons. We also link our CSS and JavaScript
files to our HTML file using the link and script tags, respectively. In our CSS file, we
define the styles for our web page, such as font size, color, and layout.
In our JavaScript file, we handle user input and send it to our chatbot model for
prediction. We use the fetch function to send a request to our Flask server that runs the
chatbot model. Once we receive the response from the server, we display it on the web
page using the DOM (Document Object Model) API.
Once we are satisfied with our chatbot interface.
We hosted our chatbot website on Versel, a platform that provides an easy way to
deploy web applications. We connected our GitHub repository to the Versel app and
set up automatic deployments on any changes to the main branch of our repository.
This made it easy to deploy and share our website with others, allowing us to reach a
wider audience and improve the user experience of our chatbot.
4.9 Usage
To use the chatbot from the website, simply visit the website URL and start typing
your message in the chat window. The chatbot will respond with appropriate answers
based on the trained intents in our case we solve queries of KIIT students
Without a website the usage instructions for the chatbot are straightforward. First, you
need to run the training script train.py using the command python train.py. This will
create data.pth file that contains the trained model parameters and other necessary
data.
Once the training is complete, you can start chatting with the chatbot by running the
script chat.py using the command python chat.py. This will load the trained model
from the data.pth file and start a chat session with the user.
If you want to customize the chatbot for your own needs, you can modify the
intents.json file with new patterns and responses, and then re-run the training script to
update the model.
Fig 4.7
Chapter 5
Conclusion
5.1 Conclusion
References
[2] Michael Bowles, "Machine Learning in Python: Essential Techniques for Predictive
Analysis", 20 Nov 2015.