Docsity

Chat bot using python project report, Lab Reports of Computer Science

Partial preview of the text

Download Chat bot using python project report and more Lab Reports Computer Science in PDF only on Docsity!

CONTENT:

  • What is Chatbot?
  • Why do we need Chatbot?
  • Types of ChatBot.
  • All about python project – ChatBot
  • How to make chatbot in python?

What exactly is a ChatBot?

A chatbot is an artificial intelligence (AI) software that can simulate a conversation (or a chat) with a user in natural language through messaging applications, websites, mobile apps or through the telephone. Why are chatbots important? A chatbot is often described as one of the most advanced and promising expressions of interaction between humans and machines. However, from a technological point of view, a chatbot only represents the natural evolution of a Question Answering system leveraging Natural Language Processing (NLP). Formulating responses to questions in natural language is one of the most typical Examples of Natural Language Processing applied in various enterprises’ end-use applications. There are two different tasks at the core of a chatbot:

  1. User request analysis
  2. Returning the response How a Chatbot Works: As you can see in this graphic, a chatbot returns a response based on input from a user. This process may look simple; in practice, things are quite complex. 1) User request analysis : this is the first task that a chatbot performs. It analyzes the user’s request to identify the user intent and to extract relevant entities

Why do we need chatbot?

  1. Automated Customer Support For Similar Queries
  2. Save Human Resources for Qualitative Tasks
  3. Improves Business Branding With Minimum Effort
  4. Chatbots Development Cost is Cheap
  5. More Success Chance as Early Adopter
  6. Accelerate Operations
  7. Better User Interaction
  8. Chatbot- Easy-to-use
  9. Chatbot Development Requires Less Time
  10. Cost-effective and Time-efficient

Types of ChatBot :

There are two basic types of chatbot models based on how they are built; Retrieval based and Generative based models.

1. Retrieval based Chatbots

A retrieval-based chatbot uses predefined input patterns and responses. It then uses some type of heuristic approach to select the appropriate response. It is widely used in the industry to make goal-oriented chatbots where we can customize the tone and flow of the chatbot to drive our customers with the best experience.

2. Generative based Chatbots

Generative models are not based on some predefined responses.They are based on seq 2 seq neural networks. It is the same idea as machine translation. In machine translation, we translate the source code from one language to another language but here, we are going to transform input into an output. It needs a large amount of data and it is based on Deep Neural networks.

How to Make Chatbot in Python? Now we are going to build the chatbot using Python but first, let us see the file structure and the type of files we will be creating:

  • Intents.json – The data file which has predefined patterns and responses.
  • train_chatbot.py – In this Python file, we wrote a script to build the model and train our chatbot.
  • Words.pkl – This is a pickle file in which we store the words Python object that contains a list of our vocabulary.
  • Classes.pkl – The classes pickle file contains the list of categories.
  • Chatbot_model.h5 – This is the trained model that contains information about the model and has weights of the neurons.
  • Chatgui.py – This is the Python script in which we implemented GUI for our chatbot. Users can easily interact with the bot. Here are the 5 steps to create a chatbot in Python from scratch:
  1. Import and load the data file
  2. Preprocess data
  3. Create training and testing data
  4. Build the model
  5. Predict the response

1. Import and load the data file First, make a file name as train_chatbot.py. We import the necessary packages for our chatbot and initialize the variables we will use in our Python project. The data file is in JSON format so we used the json package to parse the JSON file into Python. import nltk from nltk.stem import WordNetLemmatizer lemmatizer = WordNetLemmatizer() import json import pickle import numpy as np from keras.models import Sequential from keras.layers import Dense, Activation, Dropout from keras.optimizers import SGD import random words=[] classes = [] documents = [] ignore_words = ['?', '!'] data_file = open('intents.json').read() intents = json.loads(data_file)

lemmatize, lower each word and remove

duplicates words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words] words = sorted(list(set(words)))

sort classes

classes = sorted(list(set(classes)))

documents = combination between

patterns and intents print (len(documents), "documents")

classes = intents

print (len(classes), "classes", classes)

words = all words, vocabulary

print (len(words), "unique lemmatized words", words) pickle.dump(words,open('words.pkl','wb')) pickle.dump(classes,open('classes.pkl','w b'))