World is evolving faster, we can see AI everywhere. One of the greatest examples is launch of Alexa & Google home. They are creating buzz around the people.
Let’s get into world of AI, we are going to develop our own bot. There are many types of bot, popular once are “Retrieval-Based Bots” and “Generative based Bots”.
Retrieval Based Chatbot: Retrieval models have a pre-defined responses, which is unlike generative
models that can generate responses they’ve never seen before. Rule-Based bot is one of the example. The rules on which it works can vary from simple to very complex. In rule-based, intent and entity of the question is found and, on that basis, user gets the answer.
Generative Based Chatbot: This is a type of bot which requires lots of training data as it is mainly developed with deep learning models. We can develop a generative based chatbot using simple RNN(LSTM) model.
Generally, most of the problems can be solved using a rule-based approach.
Today, we are going to develop a Rule-based bot. We are going to use Microsoft Azure Services to build this bot. Microsoft Cognitive services provide lots of API’s like Vision API, Knowledge API (QnA Maker), Language API (LUIS), Speech API & Search API (Azure Search).
Vision API: Image-processing algorithms to smartly identify, caption and moderate your pictures.
Knowledge API: Map complex information and data to solve tasks such as intelligent recommendations and semantic search.
LUIS: Allow your apps to process natural language with pre-built scripts, evaluate sentiment and learn how to recognize what users want.
Speech API: Convert spoken audio into text, use voice for verification or add speech recognition to your app.
Search API: Add Bing Search APIs to your apps and harness the ability to comb billions of web pages, images, videos and news with a single API call.
We are going to use below components for our chatbot:
- Bot Framework: The Microsoft Bot Framework helps us to build, connect, deploy, and manage intelligent bots to naturally interact with your users on a website, app, Cortana, Microsoft Teams, Skype, Slack, Facebook Messenger, and more. Get started quickly with a complete bot building environment, all while only paying for what you use. We are going to write our code in dot net.
- QnA Maker: QnA Maker is an easy-to-use web-based service to train AI to respond to user’s questions in a more natural, conversational way. We can build, train and publish a simple question and answer bot based on FAQ URLs, structured documents, product manuals or editorial content in minutes.
- Microsoft Azure Services: Microsoft Azure is a cloud computing service created by Microsoft for building, testing, deploying, and managing applications and services through a global network of Microsoft-managed data centers.Note: Azure account starting is free, plus you get a ₹13,300 credit to spend in the first 30 days. You will not be charged — even if you start using services — until you choose to upgrade.PLAN FOR BOT DEVELOPMENT:
We are going to follow below step for the chatbot creation:1. Go to https://www.qnamaker.ai/ and sign in:
Creating our Knowledge Base using QnA Maker & Microsoft Azure account creation:
Now click on “Create a knowledge base “:This part consists of 5 parts are as follows :
Step 1: Create a QnA service in Microsoft Azure. When you will click on “Create a QnA Service”, it will take you to Microsoft Azure page and you have to create a new Knowledge based service
Now provide all the details to create QnA Service:
Once service is created you can Connect your QnA service to your KB from step 2 in QnA maker page:
QnA maker Step 2 for knowledge base creation
Now provide name of your Knowledge Base in step 3:
Providing Knowledge base name
Now provide the Knowledge base in step 4. It can Extract question-and-answer pairs from an online FAQ, product manuals, or other files. Supported formats are .tsv, .pdf, .doc, .docx, .xlsx, containing questions and answers in sequence. You can also add the Question & Answer manually. I have created my own Question and Answer and created a Mall assistant bot , We can use this URL for demo https://docs.microsoft.com/en-us/azure/bot-service/bot-service-resources-bot-framework-faq?view=azure-bot-service-3.0 .
Now click on “Create your KB” to create your knowledge base at step 5
Here my knowledge based is created:
Now you can test your knowledge base by clicking on TEST button:
You can do lots of thing in knowledge base, like adding more questions, modifying your questions & adding similar kind of question for an answer etc. It makes the bot more efficient. You can refer to QnA maker documentation to learn more about it.
Now click on publish tab and publish your knowledge base and you get below details:
2. Creating Web bot service in Microsoft Azure:
We are done with QnA maker setup now. Let’s go to Microsoft Azure account and click on create
resource -> AI + Machine Learning -> Web App :
Now you can access your Web App bot by clicking on Web App Bot i.e Assistant bot here :
3. Setup of Visual studio:
Go to the location https://visualstudio.microsoft.com/vs/older-downloads/ and download Visual Studio 2015
4. Setup Bot Framework:
Go to your App web bot -> click on build -> click on Download zip file
Once it is downloaded, unzip it and open Microsoft.Bot.Sample.QnABot
Click on Microsoft.Bot.Sample.QnABot
Here is the visual studio:
Message Controller: A Message Controller helps the user and bot to get connected. When the user responds first the message goes to message controller then it will help to connect with dialogs.
Dialog: A dialog specify the action to be taken by bot on receiving a message from the user.
Now go to dialog-> BasicQnAMakerDialog.cs
Microsoft have done some changes in the services and syntax of the code. You can copy the below codes and paste it to the BasicQnAMakerDialog.cs :
5. Integration of Bot Framework with Azure services and QnA Maker:
Now go to Web.config and add MicrosoftAppId, MicrosoftAppPassword , AzureWebJobsStorage, QnAEndpointHostName , QnAAuthKey & QnAKnowledgebaseId :
MicrosoftAppId, MicrosoftAppPassword & AzureWebJobsStorage can be found at Web App Bot -> Application Setting as shown below:
MicrosoftAppId, MicrosoftAppPassword & AzureWebJobsStorage
QnAEndpointHostName , QnAAuthKey , QnAKnowledgebaseId can be found in end of step 1 :
Now provide QnAEndpointHostName , QnAAuthKey , QnAKnowledgebaseId at Web App Services -> Application Setting
QnAEndpointHostName , QnAAuthKey , QnAKnowledgebaseId
Now go to the Visual studio and click on rebuild
Once rebuild is done go to Microsoft Azure -> App Service
Click on the Get publish profile, your password will get downloaded:
Now go to visual studio and click on publish as shown below:
Publishing the project
It will ask for password, open Get publish profile and get the password as shown below:
Provide publish profile Password
Getting password for publishing project
Once the bot get published successfully, go to Microsoft Azure -> Web App Bot -> Channel , shown below:
Click on skype and login add it to your skype id:
6. Chat with the Bot :
Happy Learning !!