Slot_mapping - Rasa Open Source - Rasa Community Forum
Introducing the Rasa Playground
Slot_mapping
You have selected 0 posts.
post by cswangjiawei on Jan 3, 2019
I am confused about ‘slot mapping’, in the section Slot Filling, the example for the restaurant bot:
def slot_mapping(self):
# type: () -> Dict[Text: Union[Text, Dict, List[Text, Dict]]]
"""A dictionary to map required slots to
- an extracted entity
- intent: value pairs
- a whole message
or a list of them, where the first match will be picked"""
return {"cuisine": self.from_entity(entity="cuisine",
intent="inform"),
"num_people": self.from_entity(entity="number"),
"outdoor_seating": [self.from_entity(entity="seating"),
self.from_intent(intent='affirm',
value=True),
self.from_intent(intent='deny',
value=False)],
"preferences": [self.from_text(intent='inform'),
self.from_intent(intent='deny',
value="no additional "
"preferences")],
"feedback": [self.from_entity(entity="feedback"),
self.from_text()]}
I can not understand the ‘self.from_entity’ function, the source code of ‘from_entity’ is:
def from_entity(self,
entity, # type: Text
intent=None, # type: Optional[Union[Text, List[Text]]]
not_intent=None # type: Optional[Union[Text, List[Text]]]
):
# type: (...) -> Dict[Text: Any]
"""A dictionary for slot mapping to extract slot value from
- an extracted entity
- conditioned on
- intent if it is not None
- not_intent if it is not None,
meaning user intent should not be this intent
"""
intent, not_intent = self._list_intents(intent, not_intent)
return {"type": "from_entity", "entity": entity,
"intent": intent, "not_intent": not_intent}
According to the source code, self.from_entity(entity="cuisine",intent="inform") should return "cuisine", not return the value of cuisine, such as chinese, swedish, If so, what is the role of the ‘from_entity’ function? What is the role of the ‘slot_mapping’ function?
post by Tobias_Wochinger on Jan 23, 2019
The slot mapping defines how the slots are filled. In your example, "num_people": self.from_entity(entity="number") means that the form tries to fill the slot num_people with an extracted entity number. Whenever the form action is called it checks the latest user messages and which entities Rasa NLU extracted. In case Rasa NLU extracted an entity number it will be used to fill the slot num_people.
post by lalitsomnathe on Jun 14, 2019
Hi, suppose in slot mapping I mentioned
"customer_id": self.from_entity(entity="customer_id", not_intent=[‘stop’])
In validation of this slot I mentioned that
if not self.is_int(value):
dispatcher.utter_template("utter_invalid_customer_id", tracker)
return {"customer_id": None}
else:
return {"customer_id": value}
In story
- form{"name": "bank_form"}
- form: stop
- utter_ask_continue
- form: deny
- action_deactivate_form
- form{"name": null}
So, 1. Once the form is called it will ask user to fill this slot → this is handled. 2. But when user gives input to this slot as "stop" intent, the form still validates "None" …
How Can I avoid this validation? (when stop intent is uttered)
post by JulianGerhard on Jun 14, 2019
If a slot is mapped from entity and no entity was extracted, the validate_param method won’t be executed because an Exception will be thrown:
raise ActionExecutionRejection(
self.name(),
"Failed to extract slot {0} "
"with action {1}"
" .format(slot_to_fill, self.name()),
)
You can take a look at this behaviour by commenting it out and returning an empty list. I think then you will get on the right track.
post by lalitsomnathe on Jun 17, 2019
Hi, I commented out ActionExecutionRejection. But My question is: If the input is of "stop" intent, then my bot should not validate this input against that slot.
What changes should I do to implement this behaviour?
post by JulianGerhard on Jun 17, 2019
Hi,
I am on vacation until Wednesday. If not already obsolet, I will take a look upon after returning!
Regards
post by enzechua on Jul 27, 2019
Hi @JulianGerhard do you know how to solve this problem? Same as Lalit, when the user type stop, it goes back to the slot action instead of stopping the story.