Present alternative utterance when slot is filled with "None"

Hey there!

In my use case there is the possibility that the user introduces himself with his name. The bot then tries to pick up the name with the help of a slot and presents an utterance containing this name in the following (e.g. User: “Hi, my name is Mike.” – Bot: “Mike – wow, what a nice name!”).

As it is hard to grasp the diversity of names, the bot at the moment often reproduces “None” instead of the actual name (“None - wow, what a nice name!”). Is there a possibility, that the bot utters an alternative utterance without the name in it, in case it isn’t able to recognise the name? But only as kind of a fallback – because with name is always nicer :).

Thanks in advance!

You could do this by making name a text slot (Slots):

E.g. in domain.yml:

slots:
    name:
        type: text

And then in your stories, have one for the slot being filled and one for it being empty:

## name is set
* greet{"name":"Mark"}
    - slot{"name":"Mark"}
    - utter_greet_with_name

## name is not set
* greet
    - utter_greet_no_name

And of course make sure you have responses defined for each utter_ action

1 Like

Hey Melinda,

Thanks for the quick answer. I have just implemented it the way you said and tested it. Unfortunately, the bot seems to randomly use one of the stories – no matter if it recognised the name, or not. Do you have an explanation for this?

Thanks, again! :slight_smile:

No problem - Which policies do you have in your config? And which policy does it say it is using for prediction?

Hey Melinda,

I had a problem with my policies. The MemoizationPolicy was set to 5 by default but works better with value 1 in my case. After changing it, your solution is working very well. Thank you! :slight_smile:

Edit: I have a small follow up question. In case a user types his/her name with an incorrect capitalization (e. g. john instead of John) – is it possible to automatically capitalize the first letter of my name slot when reproducing it?

1 Like

Glad you got it working. You could write a custom action that capitalizes the slot value (e.g. returns [SlotSet("name":tracker.get_slot("name").capitalize()) ), or, if you’re using a closed set of entity values (probably not since they are names?) you could map lowercased values to uppercase ones as synonyms.