Full Report PDF
Full Report PDF
Full Report PDF
BELAGAVI-590014, KARNATAKA.
A PROJECT REPORT
On
2019-2020
SAPTHAGIRI COLLEGE OF ENGINEERING
14/5, Chikkasandra, Hesaraghatta Main Road, Bengaluru – 560057.
Certificate
Certified that the Project Work entitled “A PERSONALIZED MEDICAL ASSISTANT
CHATBOT” carried out by SATVIK RANJAN (1SG15CS094), TATHAGAT ANKIT (1SG15CS114),
VIVEK KUMAR (1SG15CS125), bonafide students of Sapthagiri College of Engineering, in partial
fulfillment for the award of Bachelor of Engineering in Computer Science and Engineering of
Visvesvaraya Technological University, Belagavi during the academic year 2019-2020. It is certified that
all corrections/suggestions indicated for Internal Assessment have been incorporated in the report deposited
in the department library. The project report has been approved as it satisfies the academic requirements in
respect of Project Work (15CSP85) prescribed for the said degree.
EXTERNAL EXAMINATION:
1.___________________________ _________________________
2.___________________________ _________________________
ACKNOWLEDGEMENT
Any achievement does not depend solely on the individual efforts but on the guidance,
encouragement and co-operation of intellectuals, elders and friends. A number of personalities, in their
own capacities have helped us in carrying out this project work. We would like to take this opportunity
to thank them all.
Also we would like to express our immense gratitude to Dr. K L SHIVABASAPPA Principal,
Sapthagiri College of Engineering Bangalore, for their help and inspiration during the tenure of the
course.
We also extend our sincere thanks to Dr. Kamalakshi Naganna, Professor and Head (IC),
Department of Computer Science and Engineering, Sapthagiri College of Engineering, for their constant
support.
We would like to express our heartful gratitude to Sneha G, Asst. Professor, Department of
Computer Science and Engineering, Sapthagiri College of Engineering, for their timely advice on the
project and regular assistance throughout the work.
We also extend our sincere thanks to all the Faculty members and Supporting staff
Department of Computer Science and Engineering, Sapthagiri College of Engineering, for their constant
support and encouragement.
Finally, we thank our parents and friends for their moral support.
1SG15CS094 SATVIK RANJAN
1SG15CS114 TATHAGAT ANKIT
1SG15CS125 VIVEK KUMAR
I
ABSTRACT
We are living in the world driven by technology and Chatbot will play a key role in coming
years. With the help of new age emerging technologies like Machine Learning a lot of common diseases
can be predicted just by providing symptoms. But no human can possibly know about all such diseases.
So, the problem is that there isn’t any proper system where anyone can get the details of the diseases just
by entering the symptoms. So, the proposed idea is to create a system that can predict the common
diseases if symptoms are provided. Also, the system can possibly suggest some treatments. Hence it can
be beneficial for people as early detection of the disease can help in better treatment and recovery.
Moreover, this system will help people to keep track of their heath regularly and properly without going
anywhere.
II
SAPTHAGIRI COLLEGE OF ENGINEERING
14/5, Chikkasandra, Hesaraghatta Main Road, Bengaluru-560057.
DECLARATION
1) Satvik Ranjan
2) Tathagat Ankit
3) Vivek Kumar
III
INDEX
Chapter 1: Introduction
1.1 Background
1.2 Overview of the Present Work
1.3 Problem Statement
1.4 Objectives
1.5 Organization of the Project Report
4.1 Architecture
4.2 Major Algorithms
Chapter 5: Implementation
6.1 Testing
6.2 Results
References
I
LIST OF FIGURES
Figure No Page No
(v)
6.5 Chatbot giving symptom suggestion Screenshot 52
(vi)
LIST OF TABLES
S.l. No. Page No.
(vi)
PERSONALIZED MEDICAL ASSISTANT CHATBOT
CHAPTER 1
INTRODUCTION
1.1 Background
Chatbots are programs that mimic human conversation using Machine Learning
algorithms. It is designed to be the ultimate virtual assistant helping one to complete tasks
ranging from answering questions, getting driving directions, to playing one favorite tunes
etc.Chatbots have become more popular in business groups right now as they reduce
customer service cost and handles multiple users at a time. But yet to accomplish many tasks,
there is a need to make chatbots efficientin medical field as well.
The term "Chatterbot" was originally coined by Michael Mauldin creator of the first
Verbot, Julia in 1994 to describe these conversational programsIn 1950, Alan Turing asked
the question “Can machines think?” Turing conceptualized the problem as an “imitation
game” now called the Turing Test, in which an “interrogator” asked questions to human and
machine subjects, with the goal of identifying the human. If the human and machine are
indistinguishable, we say the machine can think. In 1966, Joseph Weinbaum at MIT created
the first chatbot that, arguably, came close to imitating a human: ELIZA. Given an input
sentence, ELIZA would identify keywords and pattern match those keywords against a set of
pre-programmed rules to generate appropriate responses.
Since ELIZA, there has been progress in the development of increasingly intelligent
chatbots. In 1972, Kenneth Colby at Stanford created PARRY, a bot that impersonated a
paranoid schizophrenic.In 1995, Richard Wallace created A.L.I.C.E, a significantly more
complex bot that generated responses by pattern matching inputs against <pattern> (input)
<template> (output) pairs stored in documents in a knowledge base. These documents were
written in Artificial Intelligence Markup Language (AIML), an extension of XML, which is
still in use today. ALICE is a three-time winner of the Loebner prize, a competition held each
year which attempts to run the Turing Test, and awards the most intelligent chatbot.
Modern chatbots include: Amazon’s Echo and Alexa, Apple’s Siri, and Microsoft’s
Cortana. The architectures and retrieval processes of these bots take advantage of advances in
machine learning to provide advanced “information retrieval” processes, in which responses
are generated based on analysis of the results of web searches. Others have adopted
“generative” models to respond; they use statistical machine translation (SMT) techniques to
“translate” input phrases into output responses. Seq2Seq, an SMT algorithm that used
recurrent neural networks (RNNs) to encode and decode inputs into responses is a current
best practice.
Chatbots has become more popular in business groups right now as they reduce
customer service cost and handles multiple users at a time. They are being used in almost
every domain from virtual assistant like Siri on mobile to customer support in tech industry
to e-commerce websites. Chatbots are currently the one of the best trending technologies
available. It is certainly one of the most advanced and time saving technology also. But yet to
accomplish many tasks there is a need to make chatbots efficient in medical field as well. To
address this problem this project provides a platform where human can interact with the
chatbot.
These chatbots are highly trained on datasets using Machine Learning algorithms. It
is like having a child and then teaching him about the world right from the beginning of his
birth. Machine Learning algorithms are mostly on natural rather than being logical. Even
without knowing the proper logic behind an algorithm one can make use of those algorithms
and can be benefited from it. In Machine learning the biggest challenge is the choice of
algorithm to use for our dataset. There are number of models available for machine learning.
There is saying in Machine Learning community that all models are wrong but some are
useful.
A Personalized Medical Assistant Chatbot not only predict the diseases ,it also got
the feature through which can be used for general conversation as a simple chatbot talking
friend which gives responses as per the input queries given to the machine (chatbot).The
chatbot machine is trained in such a way that it works with minimal efforts. In the fast
running world people don't even have enough time to attend to their medical needs in a
proper manner. Some people also hesitate to see a doctor due to the increasing medical cost
even for the simplest of issues like cold, fever, etc. It's also not possible to take a doctor’s
appointment and get immediate assistance because the doctor to people ratio in a particular
area is very small and due to this people experience delays at hospitals/clinics or prefer not to
attend to their medical needs which eventually leads to various health issues.
In addition, people are also afraid or feel shy to share their mentalhealth
issueswithadoctor. While the medical costs and issues are increasing, we are in an era which
has seen a heavy increase in the use of Technology. Every other person is equipped with at
least one and has access to everything at just a click of a button. So, there is a serious need to
combine the medical issues to technological environment which will make everything
accessible to a person in just a click.
The growing busy schedule of an individual and busy work timing people usually
ignore their common health issues and neglect the need of consulting a doctor and more often
people do not have immediate option when they suffer with particular disease. So, this
system can be helpful to the people.
The modern technology has increased the standard of living for the humans. So, the
implementation of this system facilitates the user with medical assistance. This system
provides a well-defined comprehensive interface to interact with the bot. The system
reduces the hectic and time consuming appointment queues and long waiting for simple
medical issuethus optimizes the time. This system provides a simple interface for the
conversation of the user and machine. The design and implementation of this system is to
provide service to those people who have no time due to their day to day work and seek
medical advice for some common symptoms. To achieve this objective manually is very
difficult as it is not possible to take a doctor’s appointment and get immediate assistance
because the doctor to people ratio in a particular area is very small and due to this people
experience delays at hospitals/clinics or prefer not to attend to their medical needs which
eventually leads to various health issues.
The system can provide a solution to the healthcare sector in the form of a chatbot
that can improve the way patients interact with doctors or any healthcare organization.
Patients get a quicker solution to their health-related questions and can thus act promptly
during critical conditions.A chatbot that is created for healthcare and patient care can easily
perform certain functions on a patient’s behalf, thus making interaction smoother on both
the end.
A Personalized Medical Assistant chatbot helps the patients or user to monitor their
health symptoms and work accordingly instead of rushing to doctor for common sign of
illness for prediction. The user provide the system with their respective symptoms what and
all they are experiencing such as change in body temperature, sore throat, cold shivering etc.
In personalized medical assistance chatbot user can give input in two ways either in form of
text or in form of speech. The system receives the input through a interactive interface where
the user enter the symptoms they are facing these symptoms were analyzed by the training
model the brain of the machine and the system responds with the same interface in form of
textual representation.
“To design and develop a voice enabled Chatbot for medical assistance that can
predict the disease on the basis of the symptoms provided by the user and also the chatbot
can be used for general conversation.”
1.4 Objectives
● To combine disease prediction system and general conversation chatbot into one
single unit.
● To make the system simple to use.
● To make the user interface and user experience amazing enough.
● To manage the symptoms given by user and predict the disease a person is suffering
from.
● Help the user to interact with chatbot by text as well as speech/voice.
● To provide most appropriate first aid information for common medical conditions.
● To build a system which can be easily integrated and updated.
● Save time and effort of visiting a doctor for common health illness.
● Chapter One- Introduction: This chapter tells about the background of the project,
problem statement, objectives of the project and as well as proposed system with
theoretical outline.
● Chapter Two- Literature Review: It gives brief description about the existing
techniques, problems identified in the existing system and proposed system with all
its features. It summarizes the prior works, the outcome of the review problem
identified. This chapter also reveals the proposed work.
● Chapter Three- System Requirement: This chapter discusses the requirement of the
system. It reveals the functional and the non- functional requirements. This also
discusses the software and the hardware used.
● Chapter Four- System Design/Methodology: This chapter discusses the overall
system methodology process, which includes the complete architecture and the
algorithm implemented. Besides that, this chapter covers basic terms and theories of
the system design consideration.
● Chapter Five- Implementation: Gives the brief description about how the project is
implemented. The various modules used in the project along with their functionality
are explained in brief.
● Chapter Six- Results and Discussion: This chapter gives the brief description about
how the testing is done on the modules, to see if they are successfully implemented
and work as required. The results consist of various cases depicted as snapshots.
● Chapter Seven- Conclusion and Future Work: This chapter discusses the conclusion
of this project and recommendation on further works and upgrades of the system.
CHAPTER 2
LITERATURE REVIEW
training our model bot affect the quality of its prediction output. Furthermore, they
demonstrate reasoning and generative capabilities or RNN based chat bot.
“Chatbot for University Related FAQs” [2], IEEE transaction (2017) Bhavika R.
Ranoliya, Nidhi Raghuwanshiand Sanjay Singh. Chatbots are programs that mimic human
conversation using Artificial Intelligence (AI). It is designed to be the ultimate virtual
assistant, entertainment purpose, helping one to complete tasks ranging from answering
questions, getting driving directions, turning up the thermostat in smart home, to playing
one’s favorite tunes etc. Chatbot has become more popular in business groups right now as
they can reduce customer service cost and handles multiple users at a time. But yet to
accomplish many tasks there is need to make chatbots as efficient as possible. To address this
problem, this paper provide the design of a chatbot, which provides an efficient and accurate
answer for any query based on the dataset of FAQs using Artificial Intelligence Markup
Language (AIML) and Latent Semantic Analysis (LSA). Template based and general
questions like welcome/ greetings and general questions will be responded using AIML and
other servicebasedquestionsusesLSAtoprovideresponsesatanytime that will serve user
satisfaction. This chatbot can be used by any University to answer FAQs to curious students
in an interactive fashion.
In 2014, the sequence to sequence model being used for translation opened the
possibility of phrasing dialogues as a translation problem translating from an utterance to its
response. The systems built using this principle, while conversing fairly fluently, are not very
convincing because of their lack of personality and inconsistent persona.
The model was trained end-to-end without any hand-crafted rules. The bots talk
reasonably fluently, have distinct personalities, and seem to have learned certain aspects of
their identity. The results of standard automated translation model evaluations yielded very
low scores. However, we designed an evaluation metric with a human judgment element, for
which the chatbots performed well. We are able to show that for a bot’s response, a human is
more than 50% likely to believe that the response actually came from the real character.
● The existing system was based on text as a input in which it explore the avenues of
teaching computers to process natural language text by developing a chatbot it has an
experiential approach from a beginner level of understanding, in trying to appreciate
the processes, techniques, the power and possibilities of natural language processing
using recurrent neural networks (RNN).
● The previous system did not have features such as text to speech or speech to text
conversion.Uses template to match queries/Not possible to write template for every
query.
● The previous system uses template to match queries for each response with respect to
the input. It is not possible to write template for every query.
● This is a major hindrance to the growth of the chatbot industry. The very fact that
chatbots are scripted and handmade sometimes make them feel as IVR with brains.
Even though AI is the brains of the chatbots, the range to which they can solve a
query is still limited
The proposed system is to develop a chatbot which can do normal human conversation
and also detect the disease of the user based on the symptoms provided either in the form of
text or speech. The generated response can also be in written text response or voice. The
proposed system is consisting of three basic modules which are interlinked together with a
user interface.
The architecture has a user interface through which the users communicate to the
chatbot and comes up with the reply to the query given by the user. The chatbot has to decide
whether the given input is for normal human conversation or the user wants prediction of
disease and comes up with the response according to the query given by the user.
CHAPTER 3
SYSTEM REQUIREMENTS
3.4.1 Python
Python was conceived in the late 1980s as a successor to the ABC language. Python
2.0, released 2000, introduced features like list comprehensions and a garbage collection
system capable of collecting reference cycles. Python 3.0, released 2008, was a major
revision of the language that is not completely backward-compatible, and much Python 2
code does not run unmodified on Python 3. Due to concern about the amount of code written
for Python 2, support for Python 2.7 (the last release in the 2.x series) was extended to 2020.
Language developer Guido van Rossum shouldered sole responsibility for the project until
July 2018 but now shares his leadership as a member of a five-person steering council.
Python interpreters are available for many operating systems. A global community of
programmers develops and maintains CPython, an open source reference implementation. A
non-profit organization, the Python Software Foundation, manages Python and CPython.
Machine learning (ML) is the scientific study of algorithms and statistical models that
computer systems use to effectively perform a specific task without using explicit
instructions, relying on patterns and inference instead. It is seen as a subset of artificial
intelligence. Machine learning algorithms build a mathematical model based on sample data,
known as "training data", in order to make predictions or decisions without being explicitly
programmed to perform the task. Machine learning algorithms are used in a wide variety of
applications, such as email filtering, and computer vision, where it is infeasible to develop an
algorithm of specific instructions for performing the task. Machine learning is closely related
to computational statistics, which focuses on making predictions using computers. The study
of mathematical optimization delivers methods, theory and application domains to the field
of machine learning. Data mining is a field of study within machine learning, and focuses on
exploratory data analysis through unsupervised learning. In its application across business
problems, machine learning is also referred to as predictive analytics.
1. Supervised Learning: “The outcome or output for the given input is knownbefore
itself” and the machine must be able to map or assign the given input to the output.
Multiple images of a cat, dog, orange, apple etc here the images are labelled. It is fed
into the machine for training and the machine must identify the same. Just like a
human child is shown a cat and told so, when it sees a completely different cat among
others still identifies it as a cat, the same method is employed here.
Key points:
Key points:
Key points:
3.4.3 HTML
Hypertext Markup Language (HTML) is the standard markup language for creating web
pages and web applications. With Cascading Style Sheets (CSS) and JavaScript, it forms a
triad of cornerstone technologies for the World Wide Web.[4]
Web browsers receive HTML documents from a web server or from local storage and
render the documents into multimedia web pages. HTML describes the structure of a web
page semantically and originally included cues for the appearance of the document.
HTML elements are the building blocks of HTML pages. With HTML constructs,
images and other objects such as interactive forms may be embedded into the rendered page.
HTML provides a means to create structured documents by denoting structural semantics for
text such as headings, paragraphs, lists, links, quotes and other items. HTML elements are
delineated by tags, written using angle brackets. Tags such as <img /> and <input /> directly
introduce content into the page. Other tags such as <p> surround and provide information
about document text and may include other tags as sub-elements. Browsers do not display the
HTML tags, but use them to interpret the content of the page.
HTML can embed programs written in a scripting language such as JavaScript, which
affects the behavior and content of web pages. Inclusion of CSS defines the look and layout
of content. The World Wide Web Consortium (W3C), maintainer of both the HTML and the
CSS standards, has encouraged the use of CSS over explicit presentational HTML since
1997.
This section is dedicated to the JavaScript language itself, and not the parts that are
specific to Web pages or other host environments. For information about APIs specific to
Web pages, please see Web APIs and DOM.
The standard for JavaScript is ECMAScript. As of 2012, all modern browsers fully
support ECMAScript 5.1. Older browsers support at least ECMAScript 3. On June 17, 2015,
ECMA International published the sixth major version of ECMAScript, which is officially
called ECMAScript 2015, and was initially referred to as ECMAScript 6 or ES6. Since then,
ECMAScript standards are on yearly release cycles. This documentation refers to the latest
draft version, which is currently ECMAScript 2020.
Do not confuse JavaScript with the Java programming language. Both "Java" and
"JavaScript" are trademarks or registered trademarks of Oracle in the U.S. and other
countries. However, the two programming languages have very different syntax, semantics,
and uses.
3.4.5 Anaconda
Anaconda distribution comes with more than 1,400 packages as well as the Conda
package and virtual environment manager, called Anaconda Navigator , so it eliminates the
need to learn to install each library independently.
The open source packages can be individually installed from the Anaconda repository
with the conda install command or using the pip install command that is installed with
Anaconda. Pip packages provide many of the features of conda packages and in most cases
they can work together.
Custom packages can be made using the conda build command, and can be shared
with others by uploading them to Anaconda Cloud, PyPI or other repositories.
The default installation of Anaconda2 includes Python 2.7 and Anaconda3 includes
Python 3.7.
3.4.6 Spyder
Initially created and developed by Pierre Raybaut in 2009, since 2012 Spyder has
been maintained and continuously improved by a team of scientific Python developers and
the community.
Spyder is extensible with first- and third-party plugins, includes support for
interactive tools for data inspection and embeds Python-specific code quality assurance and
introspection instruments, such as Pyflakes, Pylint and Rope. It is available cross-platform
through Anaconda, on Windows, on macOS through MacPorts, and on major Linux
distributions such as Arch Linux, Debian, Fedora, Gentoo Linux, openSUSE and Ubuntu.
Spyder uses Qt for its GUI, and is designed to use either of the PyQt or PySide
Python bindings. QtPy, a thin abstraction layer developed by the Spyder project and later
adopted by multiple other packages, provides the flexibility to use either backend.
CHAPTER 4
SYSTEM DESIGN
4.1 Architecture
The below figure shows a general block diagram describing the chatbot interaction
with user activities and operations, along with several layers used in implementing and
supporting the communication and prediction system.
Medical Assistant. Based on the response from the user the chatbot decides if it has to
continue a general conversation or to help the user for self-diagnosis.
C. Response from chatbot
The response is generated based on the decision making in the previous stage. If the
user needs help related to health the chatbot enters into a questionnaire. It starts asking about
different symptoms and then finally predicts a disease. If the user does not need any help
then the chatbot continues with the normal conversation. All the response from the chatbot is
voice based.
● The input to the chatbot is given through a microphone which is further passed to the
speech to text conversion API and the input is processed and the representation of the
input is provided to the system.
● Text is splitted for tagging with parts of speech labels according to their positions and
neighbours in the sentence.
● Individual tagged words are chunked to form phrases using different grammar
● The user chooses the option either he wants to have a normal conversation or medical
assistance based on the input the system makes the decision and comes with the
response.
4.1.1 Workflow
As we can see from the Fig, 4.1.5first the given input from the user if it is in the form
of voice/speech gets converted in form of text and the conversion is done through API further
the converted text are broken down in to individual words fragments and these words
fragments are converted into number as machine only understand the numeric input. After
conversion the training model is build the model is further act as the input for the creation of
chatbot. The chatbot is created using machine learning concept and its is trained with the help
of dataset once the chatbot is build the given input of the user is feed to the machine and the
machine takes the input and use the model for making the response.
High level design contains the functional and non functional requirements of the
software. High level design includes the design considerations.
There are several design consideration issues that need to be addressed or resolved
before getting down designing a complete solution for the system.The main assumptions and
dependencies identified are as follows:
• Sequence-to-Sequence Model
• Naïve Byes
at each timestep. Its objective is to convert a sequence of symbols into a fixed size feature
vector that encodes only the important information in the sequence while losing the
unnecessary information. You can visualize data flow in theencoder along the time axis, as
the flow of local information from one end of the sequence to another.
Each hidden state influences the next hidden state and the final hidden state can be seen as
the summary of the sequence. This state is called the context or thought vector, as it
represents the intention of the sequence. From the context, the decoder generates another
sequence, one symbol(word) at a time. Here, at each time step, the decoder is influenced by
the context and the previously generated symbols.
Naive Bayes classifier is a straightforward and powerful algorithm for the classification task.
Even if we are working on a data set with millions of records with some attributes, it is
suggested to try Naive Bayes approach. Naive Bayes classifier gives great results when we
use it for textual data analysis. Such as Natural Language Processing.
Where,
• P(H) is the probability of hypothesis H being true. This is known as the prior
probability.
• P(E) is the probability of the evidence (regardless of the hypothesis).
• P(E|H) is the probability of the evidence given that hypothesis is true.
• P(H|E) is the probability of the hypothesis given that the evidence is there.
Naive Bayes Classifier
Naive Bayes is a kind of classifier which uses the Bayes Theorem. It predicts membership
probabilities for each class such as the probability that given record or data point belongs to a
particular class. The class with the highest probability is considered as the most likely class.
This is also known as Maximum A Posteriori (MAP).
The MAP for a hypothesis is:
MAP(H) = max( P(H|E) )
=max( (P(E|H)*P(H))/P(E))
= max(P(E|H)*P(H))
P(E) is evidence probability, and it is used to normalize the result. It remains same so,
removing it won’t affect. Naive Bayes classifier assumes that all the features are unrelated to
each other. Presence or absence of a feature does not influence the presence or absence of
any other feature. We can use Wikipedia example for explaining the logic.In real datasets, we
test a hypothesis given multiple evidence(feature). So, calculations become complicated. To
simplify the work, the feature independence approach is used to ‘uncouple’ multiple
evidence and treat each as an independent one.
• Gaussian Naive Bayes: When attribute values are continuous, an assumption is made
that the values associated with each class are distributed according to Gaussian i.e.,
Normal Distribution.If in our data, an attribute say “x” contains continuous data. We
first segment the data by the class and then compute mean µ{y} & Variance
{σ*σ{y}} of each class.
• Multinomial Naive Bayes: Multinomial Naive Bayes is preferred to use on data that
is multinomially distributed. It is one of the standard classic algorithms. Which is
used in text categorization (classification). Each event in text classification represents
the occurrence of a word in a document.
• Bernoulli Naive Bayes: Bernoulli Naive Bayes is used on the data that is distributed
according to multivariate Bernoulli distributions., multiple features can be there, but
each one is assumed to be a binary-valued (Bernoulli, Boolean) variable. So, it
requires features to be binary valued.
4.2.2.2 Advantages and Disadvantage of Naive Bayes classifier
Advantages
• Naive Bayes can be use for Binary and Multiclass classification. It provides different
types of Naive Bayes Algorithms like GaussianNB, MultinomialNB, BernoulliNB.
• Great choice for Text Classification problems. It’s a popular choice for spam email
classification.
Disadvantages
• It considers all the features to be unrelated, so it cannot learn the relationship between
features. E.g., Let’s say Remo is going to a part. While cloth selection for the party,
Remo is looking at his cupboard. Remo likes to wear a white color shirt. In Jeans, he
likes to wear a brown Jeans, But Remo doesn’t like wearing a white shirt with Brown
Jeans. Naive Bayes can learn individual features importance but can’t determine the
relationship among features.
CHAPTER 5
IMPLEMENTATION
5.1.1 Padding
Before training, we work on the dataset to convert the variable length sequences into
fixed length sequences, by padding. We use a few special symbols to fill in the sequence.
2. PAD:Filler
3. GO:Start decoding
Assuming that we would like our sentences (queries and responses) to be of fixed
length, 10, this pair will be converted to:
Q: [PAD,PAD,PAD,PAD,PAD,PAD,”?”,”you”,”are”,”How”]
A: [GO,”I”,”am”,”fine”, ”.”,EOS,PAD,PAD,PAD,PAD]
5.1.2 Bucketing
Introduction of padding did solve the problem of variable length sequences, but
consider the case of large sentences. If the largest sentence in our dataset is of length 100, we
need to encode all our sentences to be of length 100, in order to not lose any words. Now,
what happens to “How are you?” ? There will be 97 PAD symbols in the encoded version of
the sentence. This will overshadow the actual information in the sentence.
Bucketing kind of solves this problem, by putting sentences into buckets of different
sizes. Consider this list of buckets :[ (5,10), (10,15), (20,25), (40,50) ]. If the length of a
query is 4 and the length of its response is 4 (as in our previous example), we put this
sentence in the bucket (5,10). The query will be padded to length 5 and the response will be
padded to length 10. While running the model (training or predicting), we use a different
model for each bucket, compatible with the lengths of query and response. All these models,
share the same parameters and hence function exactly the same way.
The vector difference between Paris and France captures the concept of capital city.
Word Embedding is typically done in the first layer of the network: Embedding layer,
that maps a word (index to word in vocabulary) from vocabulary to a dense vector of given
size. In the seq2seq model, the weights of the embedding layer are jointly trained with the
other parameters of the model.
the data is gathered, spend the time which is required, and discover the data preparation
procedures, algorithm to use, and how to configure it.The final model is the pinnacle of this
process, at the end the model will start actually making predictions.
The problem with applied machine learning is that we are trying to model the
unknown.On a given predictive modeling problem, the ideal model is one that performs the
best when making predictions on new data.We don’t have new data, so we have to pretend
with statistical tricks.The train-test split and k-fold cross validation are called resampling
methods. Resampling methods are statistical procedures for sampling a dataset and
estimating an unknown quantity.In the case of applied machine learning, we are interested in
estimating the skill of a machine learning procedure on unseen data. More specifically, the
skill of the predictions made by a machine learning procedure.Once we have the estimated
skill, we are finished with the resampling method. If you are using a train-test split, that
means you can discard the split datasets and the trained model.If you are using k-fold cross-
validation, that means you can throw away all of the trained models.
5.3.2 Split Dataset:
The dataset is divided into three parts, namely Training dataset, Validation
dataset and Testing Dataset.
5.3.2.1 Training Dataset
Training Dataset: The sample of data used to fit the model.
The actual dataset that we use to train the model (weights and biases in the case of
Neural Network). The model sees and learns from this data.
Validation Dataset: The sample of data used to provide an unbiased evaluation of a model fit
on the training dataset while tuning model hyperparameters. The evaluation becomes more
biased as skill on the validation dataset is incorporated into the model configuration.
The validation set is used to evaluate a given model, but this is for frequent evaluation.
We as machine learning engineers use this data to fine-tune the model hyperparameters.
Hence the model occasionally sees this data, but never does it “Learn” from this. The result of
validation set is taken into consideration to tune our hyperparameters. So the validation set in
a way affects a model, but indirectly.
Test Dataset: The sample of data used to provide an unbiased evaluation of a final model fit
on the training dataset.
The Test dataset provides the gold standard used to evaluate the model. It is only used
once a model is completely trained (using the train and validation sets). The test set is
generally what is used to evaluate competing models. Many a times the validation set is used
as the test set, but it is not good practice. The test set is generally well curated. It contains
carefully sampled data that spans the various classes that the model would face, when used in
the real world.
Model parameters
Hyperparameters
They are decided before fitting the model because they can't be learned from the data
5.3.2.4 Cross-validation
• Perform steps (2) and (3) 10 times, each time holding out a different fold.
The average performance across the 10 hold-out folds is your final performance estimate,
also called your cross-validated score. Because you created 10 mini train/test splits, this score
is usually pretty reliable.
The Web Speech API, introduced at the end of 2012, allows web developers to
provide speech input and text-to-speech output features in a web browser. Typically, these
features aren’t available when using standard speech recognition or screen reader software.
This API takes care of the privacy of the users. Before allowing the website to access the
voice via microphone, the user must explicitly grant permission.
• .pitch - Gets and sets the pitch at which the utterance will be spoken at.
• .rate- Gets and sets the speed at which the utterance will be spoken at.
• .text - Gets and sets the text that will be synthesized when the utterance is spoken.
• .voice - Gets and sets the voice that will be used to speak the utterance.
• .volume - Gets and sets the volume that the utterance will be spoken at.
Once the chatbot understands the user’s message, the next step is to generate a
response. One way is to generate a simple static response. Another way is to get a template
based on intent and put in some variables. The chatbot development company chooses the
method for generating the response depending on the purpose for which chatbots are
employed.For example, a weather forecast chatbot that uses API to get a weather forecast for
the given location can either say, "it will most probably rain today" or "it’s a rainy day" or
"probability of rain is 80%, so put your umbrellas to use today."The style of response varies
from user to user. In that case, the bot can study and analyze previous chats and its associated
metrics to tailor customized responses for the user.
Seq2seq was first introduced for machine translation, by Google. Before that, the
translation worked in a very naïve way. Each word that you used to type was converted to its
target language giving no regard to its grammar and sentence structure. Seq2seq
revolutionized the process of translation by making use of deep learning. It not only takes the
current word/input into account while translating but also its neighborhood.
Seq2seq Working:
Encoder
An encoder reads in "source data", e.g. a sequence of words or an image, and
produces a feature representation in continuous space. For example, a Recurrent Neural
Network encoder may take as input a sequence of words and produce a fixed-length vector
that roughly corresponds to the meaning of the text. An encoder based on a Convolutional
Neural Network may take as input an image and generate a new volume that contains higher-
level features of the image. The idea is that the representation produced by the encoder can
be used by the Decoder to generate new data, e.g. a sentence in another language, or the
description of the image.
Decoder
A decoder is a generative model that is conditioned on the representation created by
the encoder. For example, a Recurrent Neural Network decoder may learn generate the
translation for an encoded sentence in another language.
Model
A model defines how to put together an encoder and decoder, and how to calculate
and minimize the loss functions. It also handles the necessary preprocessing of data read
from an input pipeline. Under the hood, each model is implemented as a model_fn passed to
a tf.contrib.learn Estimator.
Apart from these three, many optimizations have lead to other components of seq2seq:
• Attention: The input to the decoder is a single vector which has to store all the
information about the context. This becomes a problem with large sequences. Hence
the attention mechanism is applied which allows the decoder to look at the input
sequence selectively.
• Beam Search: The highest probability word is selected as the output by the decoder.
But this does not always yield the best results, because of the basic problem of greedy
algorithms. Hence beam search is applied which suggests possible translations at each
step. This is done making a tree of top k-results.
The disease predictor module works on the Naive Bayes Classifier. Naïve Bayes is a
multi-class classifier that is based on the Bayes Theorem.
Naive Bayes is a kind of classifier which uses the Bayes Theorem. It predicts
membership probabilities for each class such as the probability that given record or data point
belongs to a particular class. The class with the highest probability is considered as the most
likely class. This is also known as Maximum A Posteriori (MAP).
Let us consider a small set of 3 classes and 4 variables for the explanation.
• Malaria
• Jaundice
• Common Cold
• Headache
• High Fever
• Vomiting
• Dark urine
The above table shows a frequency table of our data. In our training data:
• Malaria having 7/10(70%) value for headache i.e. out of 10 Malaria patient 7 suffer
from headache. Similarly, high fever has 10/10(100%) value i.e100% Malaria patient
suffer from high fever. Vomiting has 9/10(90%) value i.e90% Malaria patient suffer
from vomiting. Dark urine has 1/10(10%) value i.e10% Malaria patient suffer from
dark urine
• Jaundice having 0/10(0%) value for headache i.e. out of 10 Jaundice patient 0 suffer
from headache. Similarly, high fever has 9/10(100%) value i.e90% Jaundice patient
suffer from high fever. Vomiting has 6/10(60%) value i.e60% Jaundice patient suffer
from vomiting. Dark urine has 9/10(90%) value i.e90% Jaundice patient suffer from
dark urine
• Common Cold having 8/10(80%) value for headache i.e. out of 10 Common Cold
patient 8 suffer from headache. Similarly, high fever has 9/10(90%) value i.e90%
Common Cold patient suffer from high fever. Vomiting has 0/10(0%) value i.e0%
Common Cold patient suffer from vomiting. Dark urine has 0/10(0%) value i.e. 0%
Common Cold patient suffer from dark urine
Now, it’s time to work on predict classes using the Naive Bayes model. We have taken 2
records that have values in their feature set, but the target variable needs to predicted.
We have to predict Disease using the feature values. We have to predict whether the disease
is Malaria, Jaundice, Common Cold
The Evidence here is Headache, Vomiting and Dark urine. The Hypothesis can be a
diseaseamong Malaria, Jaundice, Common Cold.
Using Naive Bayes, we can predict that the class of this record is Malaria.
The Evidence here is High Fever, Dark urine. The Hypothesis can be a disease among
Malaria, Jaundice, Common Cold.
P(Jaundice |High Fever,Dark urine) = P(Jaundice | High Fever) * P(Jaundice |Dark urine) *
P(Jaundice) / P(High Fever,Dark urine)
= 0.9 * 0.90 * 0.33/ P(High Fever,Dark urine)
= 0.26
P(Common Cold |High Fever,Dark urine) = P(Common Cold | High Fever) * P(Common
Cold |Dark urine) * P(Common Cold) / P(High Fever,Dark urine)
= 0.9 * 0.0 * 0.33/ P(High Fever,Dark urine)
= 0.0
The denominator of all the above calculations is same i.e., P (High Fever, Dark urine). The
value of P (Jaundice |High Fever, Dark urine) is greater that P (Malaria |High Fever, Dark
urine) and P (Common Cold |High Fever, Dark urine)
Using Naive Bayes, we can predict that the class of this record is Jaundice.
CHAPTER 6
Low frequency Male voice input Text of the Text of the Pass
through external mic
Speech input Speech input
Low frequency Female voice input Text of the Text of the Pass
through external mic
Speech input Speech input
High frequency Male voice input Text of the Text of the Pass
through inbuilt device mic
Speech input Speech input
High frequency Male voice input Text of the Text of the Pass
through inbuilt mic
Speech input Speech input
Description: Users have the options of interacting with the system either by typing or through
their speech. There are different ways in which one can interact with the system.
6.2 Results
Figure (specify here) shows the Graphical User Interface of the system through which
the users will interact with the system. The GUI has two checked buttons to turn ON/OFF the
Speech to Text and Text to Speech respectively. While giving the input through typing the
user can either directly press enter key or they can click the Say button.
The system has two interaction modes. Here the users interact with the system by
having general conversation.
In the figure shown below the user starts the conversation with a greeting message
and the system replies the user.
Here the users can interact with the system in the second mode of the system, the
disease predictor mode. As soon as the users ask for help for disease prediction the system
changes it’s mode from general conversation to disease predictor mode.
In this mode the system starts asking the user to input symptoms.
Here in this function, once the user gives a symptom, a list of symptoms is shown to
help the user in choosing the symptoms.
In this way the user need not worry about the complete spelling of the symptoms and
the can select the symptoms from that list.
The figure shown below shows a case, when a user enter any symptom and that
symptom is not present in the dataset then no match found is shown.
This happens only the system fails to convert the voice into text correctly.
Here in this module, the user starts giving the symptoms as input. The system asks for
four symptoms from the user. Once the fourth symptom is provided the system responds by
predicting one of the diseases based on the highest probability of the symptoms.
There are three examples shown in the below figures. All the three figures correspond
to three different set of symptoms.
Here the user interacts with the Chatbot only with text input. The output is also
received in the text form.
Here the user interacts with the Chatbot through his voice. The output received is in
the text form.
Here the user interacts with the Chatbot through voice. The output is received in both
text and voice form.
CHAPTER 7
For future enhancements we can use an offline Application Programming Interface (API) for
Speech-to-text conversion and Text-to-Speech conversation. Also, the symptom-diseases
mapping can be done more accurately if a more reliable dataset is made available. Along
with this, with the increasing use of smart wearable more accurate body measurements like
heart rate, Body Mass Index (BMI) etc. can be given as input to the system and the disease
prediction algorithm can be improved for more accurate prediction of diseases.
References
[1]. Milla T Mutiwokuziva, Melody W Chanda, Prudence Kadebu, Addlight Mukwazvure,
Tatenda T Gotora, “A Neural-network based Chat Bot” ICCES(2017)
[2]. Bhavika R. Ranoliya, Nidhi Raghuwanshiand Sanjay Singh, “Chatbot for University
Related FAQs”. IEEE transaction (2017)
[3]. Sameera A. Abdul-Kader, Dr. John Woods, “Survey on Chatbot Design Techniques in
Speech Conversation System”, International Journal of Advanced Computer Science and
Application(2015)
[5]. Balbir Singh Bani, Ajay Pratap Singh, “College Enquiry Chatbot Using A.L.I.C.E”
International Journal of New Technology and Research, 2017
[6]. Huyen Nguyen, David Morales, Tessera Chin “A Neural with Personality”. Stanford
University Report.
[7]. Md. Shahriare Satu, Tajim Md. Niamat Ullah Akhund, Mahammad Abu Yousuf. (2017,
Feb.). Online Shopping Management System with Customer Multi-Language
Supported Query handling AIML Chatbot