I occasionally see people asking for a way to get top N intents in Dialogflow.
That is, Dialogflow already provides the "best match" intent for a user's utterance, and includes a confidence score along with that match. Is it possible to also know the next 2 best intents and their confidence scores? (Note that this feature is already offered by other bot frameworks).
In a way, the knowledge connector feature was created to solve this problem (or at least that is one of the benefits of using it).
So here is one way you could implement this for intents:
- Create a new Dialogflow agent
- Turn every training phrase from your original agent into a knowledge base question.
- The answer that you specify for the question (inside the knowledge base document) would be the name of the intent in the original agent.
- Create a knowledge connector for the agent and set the "Knowledge Results Preference" to the maximum level.
Now issue the same question (i.e. the same user utterance) to the new agent. You will be able to get the top N results.
Obviously, it would make a lot more sense to write a script to help you do all these things instead of doing it manually.
There are actually a lot of limitations to this approach, which is why this is an experiment.
For one, there isn't really a one-to-one mapping between how the knowledge connector works and how intent matching works. For example, you cannot use entities in the knowledge connector, nor does it support explicit contexts.
If you have multiple training phrases in each intent (which is almost always true), then you could very well have a situation where this approach will have top N answers all from the same intent.
Even if you get lucky and get top three answers from the knowledge connector which are actually from different intents, the confidence scores don't work in the same way for the knowledge connector and the intent mapping. So you don't quite get the same kind of insight that you might from other bot frameworks which provide top N matches.
Not to mention, this is at best an "offline" strategy. You cannot use this to handle a user's query which is in transit.
A very interesting benefit from doing this experiment would be that you will get a lot of insight into how the knowledge connector feature works, especially in comparison to regular intent mapping.
Also, I would imagine it should be possible to analyze the results of such an experiment to improve the training phrases you are already using in your intents. For example, you might actually prefer that all the top N answers for a given user utterance all map to the same intent. If a different intent gets into the top N, you might be having two intents which are too similar and may want to do something about it.
What do you think about this approach? Let me know in the comments.
- Using Collect.chat for preNLU bots
- Reader Question: How to get some sample training data for Dialogflow?
- Getting the top 3 (or top N) intents in Dialogflow: An experiment
- Dialogflow Regexp (regular expression) entity
- Using Dialogflow for educational bots
- Chatbot makes $3 million in sales in 1 hour
- Reader Question: Intent based FAQ bots vs knowledge based FAQ bots
- Should you use Dialogflow from scratch?
- 3 ways Airtable can speed up your Dialogflow prototype development
- Automatically generating a rich Dialogflow website chatbot