I am experimenting with Rasa and wanted to create a minimal setup to extract person name and use it in a utterance. Kind of “Hi” → “Hi. What’s your name?” → “Paweł” → “Nice to see you, Paweł.” Sadly, looks like I lack basic knowledge because after reading whole Rasa Open Source docs I still don’t know how to do it
When I talk chat with my chatbot in shell it does not substitute {PERSON} with john:
Your input -> hi
Hi!
What's your name?
Your input -> my name is John
/Users/pawelbarszcz/Developer/Virbe/research-playground-chatbot-engine/rasa/venv/lib/python3.7/site-packages/rasa/utils/common.py:351: UserWarning: Interpreter parsed an entity 'PERSON' which is not defined in the domain. Please make sure all entities are listed in the domain.
More info at https://rasa.com/docs/rasa/core/domains/
Nice to meet you, {PERSON} 🙂
My current chatbot setup is as follows:
data/nlu.md
## intent:i_greet
- Hi
- Hey
## intent:i_my_name_is
- My name is [John](PERSON)
- I'm [John](PERSON)
data/stories.md
## greet + ask for name
* i_greet
- utter_greet
- utter_whats_your_name
* i_my_name_is
- utter_nice_to_meet_you_name
tests/conversation_tests.md
## greet + ask for name
* i_greet: Hi
- utter_greet
- utter_whats_your_name
* i_my_name_is: My name is [John](PERSON)
- utter_nice_to_meet_you_name
As I guess based on output above – entity is recognised properly (at least for passing exactly same name as in nlu.md data), but somehow it’s not injected into response utterance.
Oh, right. You need to have both, a slot, and an entity that the slot can be filled with. If the slot name and the entity name are the same, this is done automatically. See Slots .
So you should have both
With PERSON in both entities and slots tests are still failing (with new output below) and there is no answer from bot (see below too)
failed_stories.md
## greet + ask for name (/var/folders/x3/81nczz_5387b16lxy9ycsvdh0000gn/T/tmpsze_x_j1/a049d505f524449fa04bc9a57c34ca8a_conversation_tests.md)
* i_greet: Hi
- utter_greet
- utter_whats_your_name
* i_my_name_is: My name is [John](PERSON)
- slot{"PERSON": "John"}
- utter_nice_to_meet_you_name <!-- predicted: action_listen -->
conversation
Your input -> hi
Hi!
What's your name?
Your input -> my name is John
Your input ->
2. Slot defined, now with another config
With both entity and slot defined I also tried with another policies:
As the basic case (exact user message and PERSON value as in nlu.md) works now I will continue with exploration and will write down some questions to understand things better. But in a separate reply in this thread (have to go AFK for now).
Is it possible to make it work for non-english characters? My name Paweł results with Nice to meet you, human 🙂, but for Pawel it’s correctly Nice to meet you, Pawel 🙂 . I think about case where user is english-speaking but has non-english name.
How can I know more about entities provided by an extractor? For SpacyEntityExtractor I see PERSON, LOC, ORG, and PRODUCT in docs, but how can I know what they mean (apart from guessing that LOC might be kind of “location”) are what are their types (you helped me, @j.mosig, with type: text, but how did you know that PERSON is of type text?)
I see my bot works for names different than John/hohn. Is it possible test it? I tried with - slot{…} notation but tests are passing even with different value next to intent than the on in -slot{…}. See below (beware there is one extra utter_nice_to_meet_you_name in greeting comparing to my previous snippets, as I wanted to test slot initial value):
## greet John
* i_greet: Hi
- utter_greet
- utter_nice_to_meet_you_name
- utter_whats_your_name
* i_my_name_is: My name is [John](PERSON)
- slot{"PERSON": "Mike"}
- utter_nice_to_meet_you_name
I struggle to achieve slot name different than entity (I prefer to name things of different concepts differently, as it makes it easier to understand what and how and why ) See my trial below, where tests, sadly, pass even if I don’t know how to pass recognised entity to a given slot:
#
# excerpt from domain.yml
#
entities:
- PERSON
slots:
s_person:
type: text
initial_value: "human"
responses:
# …
utter_nice_to_meet_you_name:
- text: "Nice to meet you, {s_person} 🙂"
#
# excerpt from nlu.md
#
## intent:i_my_name_is
- My name is [John](PERSON)
#
# excerpt from tests
#
## greet John
* i_greet: Hi
- utter_greet
- utter_nice_to_meet_you_name
- utter_whats_your_name
* i_my_name_is: My name is [John](PERSON)
- utter_nice_to_meet_you_name
I see my bot works for names different than John / hohn . Is it possible test it?
Your training stories should only contain correct examples. You can then test generalization with test stories (see, e.g. Testing Your Assistant). I am not sure what you mean, though.
I struggle to achieve slot name different than entity
Good point, but the easiest way is indeed to give them identical names. If you name slots different from entities, then you have two options: (i) you change your stories such that whenever the user provides the corresponding entity, the next line is - slot{"s_person": ...}, or (ii) you use a Form and define how slots are extracted (see Forms).