concept query in category chatbot

This is an excerpt from Manning's book Building Chatbots with Microsoft Bot Framework and Node.js.
A customer support chatbot – Instead of talking to or texting with a real person, users can be directed to a chatbot that can handle the common questions and as a fallback be routed to a real person if the chatbot is unable to handle a query. This can let businesses cut down on resources for customer support and also make it more efficient. Currently users are frequently frustrated due to the long wait time before you have a person who can answer the query. With automation, most of the queries can be instantly handled and human intervention only needed for new or complicated queries and because most of the human support personnel will be free a lot more, the wait times for these complex query answering will also go down.
In the last chapter, we learnt about intent recognition and different methods we can use to recognize intents. However, there was a big problem with the approach. To understand this problem, let’s take the example of queries inside “Get Workout Info”. As a reminder, the sample queries I introduced were: “how to do a pushup?”, “how do I do a pushup?”, “what is the right way to do a pushup?”, “How can I do pushups correctly?”, “what is the correct way to do a pushup?”.
Though the wording differs, each of these is an example of the user asking for information about the process of doing a pushup. But in the real world, the user might ask also about other sit-ups, deadlifts, chin-ups, and many other exercises--and our bot should be able to handle them all. To do this, we could try to add samples for each of the different exercises, like we added samples for different phrases for the question about pushups. But the problem with this approach is that LUIS will recognize all of the sample queries as an intent of type “Get Workout Info”. While this correctly describes the general intent of the user query (how to perform an exercise), it does not tell us anything about the particular exercise the user wants to know about; it has no way of differentiating between queries for pushups and those for sit-ups. One way we could solve this problem would be to change “Get Workout Info” to “Get pushup Info” and similarly create intent categories for the different types of workouts like “Get sit-up Info”, “Get deadlift Info”, etc. We could then add samples for each of these workouts into their categories, like we added samples for queries about pushups in the last chapter. However, this would be a very inefficient solution. And this is where entities help us.
Entities help us to get more information out of a given query. For a query like “How to do a pushup?” we will not only be able to get the intent (which is “Get Workout Info”), but also recognize that the exercise the user is talking about is “pushup”.
In this chapter, you will learn about Entities and how to use them to more efficiently create NLP for our chatbot. Entities let you define parameters inside intents and these parameters can take on different values. For example, in our case we can define a parameter called “workout type” which is included in all intents of type “Get Workout Info”. The NLP system will then be able to recognize the parameter “workout type” from any query which is of the type “Get Workout Info”. So the NLP system will recognize the “workout type” as “pushup” in the query “how to do a pushup?”. I will show you how to define entities and use them inside your chatbot using LUIS (the NLP service by Microsoft we learnt about in the previous chapter). And we will take a look at a few limitations for using entities and how we can address these limitations.
// Handle the Exercise intent bot.dialog(“Get Workout Info”,function(session,args){ var intent = args.intent; var entity = builder.EntityRecognizer.findEntity(intent.entities, “exercise”); #1 if (entity){ var exercise = entity.entity; if (exercise == “pushup” || exercise == “push up”){ #2 session.send("Put your hands about shoulder width apart. Put your shoulder down and back like you were trying to hold a tennis ball between your shoulder blades."); } else if (exercise == “pullup” || exercise == “pull up”){ session.send("Grip the bar shoulder-width apart with straight arms. Pull yourself up by pulling your elbows to the floor. Keep pulling until your chin passes the bar. Lower yourself all the way down until your arms are straight. Then pull yourself up again."); } } }).triggerAction({ matches:”Get Workout Info” }); #1 extracting the value of the exercise entity mentioned in the user query #2 checking the exercise type mentioned in the query
This time instead of trying only the exact phrases we used in the sample set you can try testing with different variations of the queries like instead of “how to do a pushup?”, we might ask “how do you think I should do a pushup?”.
Figure 4.17 Testing intent and entity recognition
![]()
As you can see above our bot is much smarter than before and can easily handle variations of the queries.