Another post starts with you beautiful people!
It has been a long time of posting a new post. But my friends in this period I was not sitting where I got a chance to work with chatbot and classification related machine learning problem.
So in this post I am going to share all about chatbot- from where I have learned? What I have learned? And how can you build your first bot?
Quite interesting right!
Chatbot is a program that can conduct an intelligent conversation based on user's input. Since chatbot is a new thing to me also, I first searched- is there any Python library available to start with this?
And like always Python has helped me this time also. There is a Python library available with name as ChatterBot which is nothing but a machine learning conversational dialog engine. And yes that is all I want to start my learning because I always prefer inbuilt Python library to start my learning journey and once I learn this then only I move ahead for another sources.
For understanding process flow of a chat bot please see this link process flow of chatterbot
I have installed the chatterbot library from the official PyPi as pip install chatterbot
Let's start our journey by importing this library in our jupyter notebook first-
Next, we need to create a new instance of the ChatBot class as below-
Here you can give any name to your bot as for example I have given name 'Moto' to my chat bot.
Let's starts with greetings to check if our chatbot understands the basics greetings from the user input or not. For this we don't need to write a code from scratch. ChatterBot includes tools that help simplify the process of training a chat bot instance.We just need to import required built-in trainer class like below-
ListTrainer Allows a chat bot to be trained using a list of strings where the list represents a conversation. So let's define our conversation list which will establish each item in the list as a possible response to it’s predecessor in the list as below-
Now to use 'ListTrainer' training class we must pass it to the set_trainer() method before calling train() as below-
Once you run the above lines you will see a progress bar showing training progress of the bot. Make sure if you make any changes to the conversation list then you need to rerun these lines otherwise your changes will not reflect.
Let's check how our bot responses on some of our greeting inputs-
Now what about if you don't want to use a conversation list; instead you want to use a corpus data. No any hack for this; ChatterBot comes with a corpus data and utility module that makes it easy to quickly train our bot to communicate. To do so, simply specify the corpus data modules you want to use as below-
Let's create a new chat bot for this example, set the trainer as Corpus trainer instead of List trainer and train our bot for English corpus as below-
See here the long training list of the corpus English language having by the corpus trainer class. It contains most of the basics conversations we see in computers, emotions, gossips, greetings, humor etc. Since we have trained the all corpus of English; it is training our bot for all. If you want to train some specific just add that one in the train() like below-
Let's check our new bot responses on some of inputs:-
Quite amazing right :) No any coding and your bot is able to give proper response.
Now our bot is ready to handle greetings, conversations, humor, gossip etc. Let's move forward and make our bot ready to handle real world conversations. What about Twitter data or Whatsapp data or Facebook data? Sounds interesting and complex too? No worry ChatterBot is already there to make our way smooth.
Let's see how can we train our bot with data from the Twitter API. Remember whenever you are going to work with any third party api you will need api credentials to interact with those apis. And in this example also we need access key, token, consumer key etc from the Twitter API.
Our first step will be to get api key,token,access key and token and for getting this you need to create an account in twitter first then you need to create an app using the same account in twitter developer account
I have also created a test twitter account and an app for this tutorial and now I have the api key, api token, access key and access token. Now see how we can use twitter data to train our bot as below-
Let's understand new inputs we are giving here:
- input_adapter: to allow a chat bot to have a versatile method of receiving or retrieving input from a given source. In our example the output terminal adapter allows a user to type into their terminal to communicate with the chat bot.
- output_adapter: a generic class that is delivering a response to an API endpoint.
- logic_adapter: determine the logic for how ChatterBot selects a response to a given input statement.In our example adapter returns a specified default response if a response can not be determined with a high amount of confidence.
Behind the seen chatterbot library uses Naive Bayes Classifier algorithm to determine if an input statement meets a particular set of criteria that warrant a response to be generated from that logic adapter.
Let's move ahead and see how can I use my bot in web? For deploying your bot to any web app Python provides us two web frameworks- Django and Flask. In this post I am going to share you integration of your bot with Django.
If you are new to Django as I was, please refer this great link build-your-first-python-and-django-application . Believe me a Data Scientist with Django skill add-on will definitely attract the recruiters. So just have a look and learn the basics of Django framework before deploying your chat bot to this web framework.
Once you learn about the Django basics, create a Django project and import that in your favourite IDE. I have created and imported a sample application in my Django 2.0.6 + MySql 5.7 and it looks like as below-
If you don't want to create the app by your own and just want a working example of this then don't worry. Just copy the example project from this link working example and import in pycharm ide.The structure will look like same as above screen shot.
Now once you setup the project open the settings,py file and search for the INSTALLED_APP. Here you need to add your app name like below-
Next, you need to add your chatbot related settings (trainer, adapter etc) in the same file as below-
Next, define the root url and wsgi parameters of your app as below-
After this you need to define your database related information like below-
In this example we are using sqlite3 db, you can change it according to your database.
Once you done all above settings, it's time to build and deploy your Django app with your bot. For this open your Anaconda Prompt and go to the path where your django app project is. In my setup It is like below-
Next, run following command to install required libraries-
After this you need to run following two commands one by one-
Now it's time to train our bot with simple greetings as below-
Next start your server by running this command-
Once server is tarted, hit the url http://127.0.0.1:8000/ and you will see following screen-
It means you have successfully setup, build and deploy Django app with your chat bot :)
That's it my friends! In this post you have learnt What is a chatbot? How can you create your first chatbot with inbuilt Python library? How can you integrate your bot with a web framework?
As a data scientist if you have a knowledge of such integrations then you are going to make your own way in this IT world. There are lots of pending items waiting for you to do some hands on.
So import the project example, try to extend the built in functionalities and make your bot stronger day by day.
In my next post I will share you how can you use Google's DialogFlow to built a bot.
With that said my friends- Go chase your dreams, have an awesome day, make every second count and see you later in my next post.
Pinwords is a really basic tool, but it’s great if you want to quickly make an image from a quote and add it to your Pinterest account. Pinstamatic actually lets you
ReplyDeletecreate a whole bunch of items to add to your Pinterest boards including website snapshots, pins of Twitter profiles and Spotify tracks that you can pin.
We have to thank and share such a nice blog post and interesting information. It is helpful for develop my knowledge, people always searching for this type of posts.
ReplyDeleteChatbot Developers in Dubai
Facebook Chatbot in Dubai
AI Chatbot in Dubai
Artificial intelligence Company in Dubai
That is the very first time I frequented your website page and thus far? I surprised with the analysis you made to create this particular submit incredible. Fantastic job!
ReplyDeleteChatbot Company in Dubai
Chatbot Companies in Dubai
Chatbot Development
AI Chatbot Development
Chatbot Companies in UAE
Chatbot Company in Chennai
Chatbot Company in Mumbai
Chatbot Company in Delhi
Chatbot Development Companies
Great post. Thanks for sharing.
ReplyDeleteBest Chat Bot Development Services
Thanks! to Chatlayer for sharing this great information with us.
ReplyDeletehttps://www.sinch.com/en-in/products/customer-engagement/chatlayer/
Really Great post sharing.useful to this articles.
ReplyDeleteUser Interaction: Chatbots are designed to engage with users in a conversational manner. Python provides a robust platform for creating interactive conversational experiences. it's a
useful to user interaction.
Data Science Expert
ReplyDeleteWelcome to Analytic Square, where we tailor courses to meet industry demands. Our focus? Short, targeted programs to boost your skills. From data analysis to digital marketing, we've got you covered. Let's elevate your expertise together!
Thanks for sharing the valuable information.
ReplyDeleteHome Nursing Services in Hyderabad
nursing services at your door step
Home Physiotherapy Services
Greps AI excels in delivering Greps AI Innovative AI Solutions, focusing on digital marketing, UI/UX design, and chatbot development. Our expertise in leveraging advanced AI technologies ensures businesses achieve enhanced customer engagement and operational efficiency. With a commitment to innovation and quality, Greps AI is dedicated to driving transformative outcomes through tailored AI solutions tailored to meet diverse business needs.
ReplyDeleteExcellent post which I'm sharing.beneficial to this article.
ReplyDeleteAustralian AI Solutions Company