Tuesday, 27 March 2018

Bot Framework Tutorial 5: How to Train a Question and Answer(QnA) Bot

This tutorial follows from the Tutorial 4 where we create a Question and Answer Bot. In this tutorial, we would focus on improving the functionality  of our the question and answer bot so that it can give more intelligent answers to questions.


Today we would focus on Create a chat robot that would answer any question about Computer Programming and we would do this together


  1. Examine the Base Questions
  2. Add Your own questions
  3. Create a QnaServer in qnamaker.ai
  4. Test the Service
  5. Train Your Service
  6. Quiz for You
  7. Publish and Test  The Service
  8. Create a New Question and Answer Bot in Azure
  9. Final Notes and Next Steps


1. Examine the Base Questions List


For this tutorial, we would start with a basic list of computer programming questions. You can view these questions from here.

Figure 1: Base Questions List


Figure 1 shows the base qustions list that would serve as our starting point


2. Add Your own questions


You can add more questions to this list. Just leave the question in the comment box under the list. You could also leave the question in the comment box under this tutorial.

If you have the answer to the question you could provide it along with the question, if not, then we would provide the answer and add it to the list in a short time.

Figure 2: Add Your Question here


If would like to have access to the Programming Questions and Answers page, then mention that in the comment box, as well as your email. After verifying that the request is authentic, then we would provide you with a link to edit the questions and answers list and add your own questions.


3. Create a QnaServer in qnamaker.ai


Step 1: Visit qnaMaker.ai
Step 2: Click on Create New Service
Step 3: Enter the name of the Service (eg. Programming-Questions-Service)

Now you need to enter the url of the knowledgebase. The knowledgebase is simply the list of question and answers we already have.


Figure 3: Create new Qna Service


Step 4: Enter the url of our programming questions and answers page: http://kindsonthegenius.blogspot.hu/2018/03/computer-programming-questions-and.html
Copy and paste the url in the box

Step 5: Scroll down the page and click on the create button
After some seconds, the knowledgebase is created as shown in Figure 4.

Notice that the  system recognizes which text is a questions and which is the answer to the question. Also, any image is the file or text that is not question and answers are ignored.
Isn't this amazing!


4. Test Your Service


To test our service:
Step 1: Click on the Test menu by the left
The testing page is displayed as shown in Figure 4

Figure 4: Testing Page

Step 2: Enter some of the questions we have in the list and observe the response.
You would observe that it gives the correct response.
Let's now move to the training section so we see how we can improve performance


5. Train Your Service


However, you entered the questions exactly as it is because you already have the list of question. But a user trying to ask questions about computer programming may ask questions in a different way or with different wordings.

For example, the three questions should produce the same answer(at least for a simple bot):

  • Can you tell me about JVM?
  • What is Java Virtual Machine?
  • What does JVM stand for?


Step 1: Try to enter this three questions and what do you observe? Give answer in the comment box below.

Step 2: Now Enter What is Java Virtual Machine.
You will observe that it give us the wrong answer đŸ˜ƒ

Training would help us fix this.

Step 3: Now enter What is JVM, so that is gives the right answer.
We want it to give us the same answer when we enter What is Java Virtual Machine

Step 4: By the right hand side, in the text box under 'provide multiple alternative phrasing to the question to broaden the knowledge base', enter What is Java Virtual Machine
Step 5: Click Add (the + sign)
Notice that the question is added as a second question for this particular answer as shown in Figure 5

Figure 5: Training the Qna Service


Step 6: Click on Save and Retrain
Step 7: Now, Enter the question again, What is Java Virtual Machine

What do you observe?
Notice now that it gives the right answer

6. Quiz for you


Train the Service the give the same answer for the following quesionÉ

What are some Languages in Programming
Mention some programming languages
Give examples of programming languages

Also take some time to train the service to handle other variations of the other questions in the list. Remember to click on Save and Retrain when you are done with the training.



7. Publish and Test  The Service


After you are done with the training:
Step 1: Click on Publish. A review page is displayed
Step 2: Click on Publish again to publish the service

Figure 6: Publish Success page

Now, you can see Success page.
In this page you will find the KnowledgebaseId and the Subcription Key.
Step 3: Copy and save this output, because you will need it in the nex tutorial.

8. Create a New Question and Answer Bot in Azure


You will need to do this by yourself.
See How to Create a Question and Answer Bot
Give the bot a name like ProgrammingBot or ProgrammingAssistant or ProgrammingTutor

9. Final Notes and Next Steps


Now we have a working qna Service and we have a question and answer bot. This is interesting because in the next tutorial we would examine how allow users to use this bot for free.

You know, the public could make use of your bot and it would even apear that they are chatting with someone
In the next tutorial, we would examing Channels and also  add Skype channel to this bot so that it can connect with and chat with real users

For now I would like to thank you for the time spent learning. Do leave a question or observation if you have any.