snipsco / snips-nlu

Snips Python library to extract meaning from text
https://snips-nlu.readthedocs.io
Apache License 2.0
3.89k stars 513 forks source link

Dialog management #849

Open ptchankue opened 5 years ago

ptchankue commented 5 years ago

Question

Hi guys,

Do you have an example of dialog management using snips? Like slot filling etc

Regards,

adrienball commented 5 years ago

Hi @ptchankue , Writing a technical blogpost about how to leverage snips-nlu is on my todo list. The chatbot use case would be a perfect fit for a first article. I'll try to allocate some time soon for this, as I know such examples/articles are important for snips-nlu users.

In the meantime, here are some bits that can help you move forward with a simple slot filling dialog manager:

In the typical setup, you will have a list of top-level intents, or entrypoint intents, which correspond to the use cases you want your app to cover. Then for each top-level intent, you may have some follow-up intents that would simply help to retrieve all the missing slots of the top-level intent. We could call such intents elicitation intents. Let's illustrate what would be an elicitation intent, imagine you have an intent such as:

---
type: intent
name: BookFlight
utterances:
  - find me a flight from [departure:snips/city](Boston) to [arrival:snips/city](Paris)
  - show me flights from [departure:snips/city](Tokyo) to [arrival:snips/city](Berlin) please

In this intent, the dates are missing so you could have the following elicitation intent:

---
type: intent
name: BookFlightDate
utterances:
  - "[date:snips/datetime](this weekend)"
  - I'm planning to leave [date:snips/datetime](tomorrow)
  - this will be for [date:snips/datetime](the 3rd of july)

This elicitation intent will let you capture the missing information in the top-level intent BookFlight.

The key feature in snips-nlu that will let you work with top-level and elicitation intents is the use of intents scope in the parsing API:

intents_scope = ["BookRestaurant", "BookFlight", "GetWeather"]  # top-level intents
engine.parse("I'm looking for a flight from chicago to new york", intents=intents_scope)

This intents scope will restrict the parsing to the list of intents in the scope. When your dialog manager is in a state where it is waiting to parse a top-level intent then you should provide a top-level intents scope.

After that, your will ask your user to precise the date and then the code will go:

intents_scope = ["Cancel", "BookFlightDate"]
engine.parse("I want to leave in three days", intents=intents_scope)

The intents_scope here contains the "BookFlightDate" elicitation intent and the generic "Cancel" intent to let the user leave the dialog at any time.

Using intents scope allows to define fined grained elicitation intents while handling properly any overlapping issues that can arise from the fact that elicitation intents may be close semantically to top-level intents or close to other elicitation intents.

I hope this will help a bit, even though I am aware that this doesn't cover all the technical issues of dialog management. Cheers

ptchankue commented 5 years ago

Hi @adrienball Thank you very much for this detailed explanation. I will try it and provide feedback.