Build a simple Chatbot

 Build a simple Chatbot

This article was published as a part of the Data Science

A chatbot is an AI-based software that comes under the application of NLP which deals with users to handle their specific queries without Human interference.

 Brief Intro on Chatbot

A chatbot is a smart application that reduces human work and helps an organization to solve basic queries of the customer. Today most of the companies, business from different sector makes use of chatbot in a different way to reply their customer as fast as possible. chatbots also help in increasing traffic of site which is top reason of business to use chatbots.

Chatbot asks for basic information of customers like name, email address, and the query. If a query is simple like product fault, booking mistake, need some information then without any human connection it can solve it automatically and If some problem is high then It passes the details to the human head and helps customer to connect with organization manager easily. And most of the customers like to deal and talk with a chatbot.

Why we need Chatbots?

  • Cost and Time Effective ~ Humans cannot be active on-site 24/7 but chatbots can and the replying power of chatbots is much fast than humans.
  • Cheap Development cost ~ with the advancement in technology many tools are developed that help easy development and integration of chatbots with little investment.
  • Human Resource ~ Today Chatbots can also talk with text o speech technology so it gives the feel as a human is talking on another side.
  • Business Branding ~ Businesses are changing with technology and chatbot is one out of them. Chatbot also helps in advertising, branding of organization product and services and give daily updates to users.

Types of Chatbots

There are mainly 2 types of chatbots.

1) Rule-based Chatbots – As the Name suggests, there are certain rules on which chatbot operates. Like a Machine learning model, we train the chatbots on user intents and relevant responses, and based on these intents chatbot identifies the new user’s intent and response to him.

2) Self-learning chatbots – Self-learning bots are highly efficient because they are capable to grab and identify the user’s intent on their own. they are build using advanced tools and techniques of Machine Learning, Deep Learning, and NLP. Self-learning bots are further divided into 2 subcategories.

Retrieval-based chatbots:- Retrieval-based it is somewhat the same as Rule-based where predefined input patterns and responses are embedded.

Generative-Based chatbots:- It is based on the same phenomenon as Machine Translation build using sequence 2 sequences neural network.

Most of the organization uses self-learning chatbot along with embedding some rules like Hybrid version of both methods which makes chatbot powerful to handle each situation during a conversation with a customer.

Build one for you using Python

Now we have an immense understanding of the theory of chatbots and their advancement in the future. Let’s make our hands dirty by building one simple rule-based chatbot using python for ourselves.

We will design a simple GUI using the Python Tkinter module using which we will create a text box and button to submit user intent and on the action, we will build a function where we will match the user intent and respond to him on his intent. If you do not have the Tkinter module install, then first install it using the pip command.

pip install tkinter

Code

from tkinter import *
root = Tk()
root.title("Chatbot")
def send():
    send = "You -> "+e.get()
    txt.insert(END, "n"+send)
    user = e.get().lower()
    if(user == "hello"):
        txt.insert(END, "n" + "Bot -> Hi")
    elif(user == "hi" or user == "hii" or user == "hiiii"):
        txt.insert(END, "n" + "Bot -> Hello")
    elif(e.get() == "how are you"):
        txt.insert(END, "n" + "Bot -> fine! and you")
    elif(user == "fine" or user == "i am good" or user == "i am doing good"):
        txt.insert(END, "n" + "Bot -> Great! how can I help you.")
    else:
        txt.insert(END, "n" + "Bot -> Sorry! I dind't got you")
    e.delete(0, END)
txt = Text(root)
txt.grid(row=0, column=0, columnspan=2)
e = Entry(root, width=100)
e.grid(row=1, column=0)
send = Button(root, text="Send", command=send).grid(row=1, column=1)
root.mainloop()

No comments

Powered by Blogger.