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.
- Dialogflow Messenger Quiz Bot
- Dialogflow Zobot: Selection Triggers the next intent
- Integrating Dialogflow with Zoho live chat
- 5 things you cannot do using the Dialogflow Messenger integration
- Dialogflow Architecture
- Dialogflow Python webhook tutorial
- Dialogflow training
- Dialogflow vs Lex vs LUIS vs Watson vs Chatfuel
- Convert your WordPress website into a Dialogflow FAQ chatbot
- Dialogflow Messenger Interactive Learning Bot