Slot Example Rasa



For example, in the above sentence, the intent is ordering and the entity is a book. Rasa NLU internally uses Bag-of-Word (BoW) algorithm to find intent and Conditional Random Field (CRF) to find entities. Although you can use other algorithms for finding intent and entities using Rasa. RASA CORE: Core is. Here you can find the full list of slot types defined by Rasa Core, along with syntax for including them in your domain file. Actions are the things your bot can actually do. For example, an action could: respond to a user, make an external API call, query a database,. Just about anything! A list of all Rasa Core slot types. Description: The feature of this slot is set to 1 if a value with a list is set, where the list is not empty. If no value is set, or the empty list is the set value, the feature will be 0.

The Domain defines the universe in which your assistant operates.It specifies the intents, entities, slots, and actionsyour bot should know about. Optionally, it can also include responsesfor the things your bot can say.

Slot Example Rasa

As an example, the domain created by rasainit has the following yaml definition:

What does this mean?

Your NLU model will define the intents and entities that youneed to include in the domain. The entities section lists all entitiesextracted by any entity extractor in yourNLU pipeline.

For example:

Slots hold information you want to keep track of during a conversation.A categorical slot called risk_level would bedefined like this:

Here you can find the full list of slot types defined byRasa Core, along with syntax for including them in your domain file.

Actions are the things your bot can actually do.For example, an action could:

  • respond to a user,

  • make an external API call,

  • query a database, or

  • just about anything!

To reference slots in your domain, you need to reference them bytheir module path. To reference custom actions, use their name.For example, if you have a module called my_actions containinga class MyAwesomeAction, and module my_slots containingMyAwesomeSlot, you would add these lines to the domain file:

The name function of MyAwesomeAction needs to returnmy_custom_action in this example (for more details,see Custom Actions).

Responses are messages the bot will send back to the user. There aretwo ways to use these responses:

  1. If the name of the response starts with utter_, the response candirectly be used as an action. You would add the responseto the domain:

    Afterwards, you can use the response as an action in thestories:

    When utter_greet is run as an action, it will send the message fromthe response back to the user.

  2. You can use the responses to generate response messages from yourcustom actions using the dispatcher:dispatcher.utter_message(template='utter_greet').This allows you to separate the logic of generatingthe messages from the actual copy. In your custom action code, you cansend a message based on the response like this:

Responses defined in a domain’s yaml file can contain images andbuttons as well:

Note

Please keep in mind that it is up to the implementation of the outputchannel on how to display the defined buttons. The command line, forexample, can’t display buttons or images, but tries to mimic them byprinting the options.

You can also send any arbitrary output to the output channel using thecustom: key. Note that since the domain is in yaml format, the jsonpayload should first be converted to yaml format.

For example, although date pickers are not a defined parameter in responsesbecause they are not supported by most channels, a Slack date pickercan be sent like so:

For each response, you can have multiple response templates (see Variations).If you have certain response templates that you would like sent only to specificchannels, you can specify this with the channel: key. The value should matchthe name defined in the name() method of the channel’s OutputChannelclass. Channel-specific responses are especially useful if creating customoutput payloads that will only work in certain channels.

Each time your bot looks for responses, it will first check to see if thereare any channel-specific response templates for the connected channel. If there are, itwill choose only from these response templates. If no channel-specific response templates arefound, it will choose from any response templates that do not have a defined channel.Therefore, it is good practice to always have at least one response template for eachresponse that has no channel specified so that your bot can respond in allenvironments, including in the shell and in interactive learning.

You can also use variables in your responses to insert informationcollected during the dialogue. You can either do that in your custom pythoncode or by using the automatic slot filling mechanism. For example, if youhave a response like this:

Rasa will automatically fill that variable with a value found in a slot calledname.

In custom code, you can retrieve a response by using:

If the response contains variables denoted with {my_variable}you can supply values for the fields by passing them as keywordarguments to utter_message:

If you want to randomly vary the response sent to the user, you can listmultiple response templates and Rasa will randomly pick one of them, e.g.:

If you want all entities to be ignored for certain intents, you canadd the use_entities:[] parameter to the intent in your domainfile like this:

To ignore some entities or explicitly take only certain entitiesinto account you can use this syntax:

This means that excluded entities for those intents will be unfeaturized and thereforewill not impact the next action predictions. This is useful when you havean intent where you don’t care about the entities being picked up. If you listyour intents as normal without this parameter, the entities will befeaturized as normal.

Note

If you really want these entities not to influence action prediction wesuggest you make the slots with the same name of type unfeaturized.

A conversation session represents the dialogue between the assistant and the user.Conversation sessions can begin in three ways:

  1. the user begins the conversation with the assistant,

  2. the user sends their first message after a configurable period of inactivity, or

  3. a manual session start is triggered with the /session_start intent message.

You can define the period of inactivity after which a new conversationsession is triggered in the domain under the session_config key.session_expiration_time defines the time of inactivity in minutes after which anew session will begin. carry_over_slots_to_new_session determines whetherexisting set slots should be carried over to new sessions.

The default session configuration looks as follows:

This means that if a user sends their first message after 60 minutes of inactivity, anew conversation session is triggered, and that any existing slots are carried overinto the new session. Setting the value of session_expiration_time to 0 meansthat sessions will not end (note that the action_session_start action will stillbe triggered at the very beginning of conversations).

Note

A session start triggers the default action action_session_start. Its defaultimplementation moves all existing slots into the new session. Note that allconversations begin with an action_session_start. Overriding this action couldfor instance be used to initialise the tracker with slots from an external APIcall, or to start the conversation with a bot message. The docs onCustomising the session start action shows you how to do that.

Slots are your bot’s memory. They act as a key-value storewhich can be used to store information the user provided (e.g their home city)as well as information gathered about the outside world (e.g. the result of adatabase query).

Most of the time, you want slots to influence how the dialogue progresses.There are different slot types for different behaviors.

For example, if your user has provided their home city, you mighthave a text slot called home_city. If the user asks for theweather, and you don’t know their home city, you will have to askthem for it. A text slot only tells Rasa Core whether the slothas a value. The specific value of a text slot (e.g. Bangaloreor New York or Hong Kong) doesn’t make any difference.

Slot example rasa al

If the value itself is important, use a categorical or a bool slot.There are also float, and list slots.If you just want to store some data, but don’t want it to affect the flowof the conversation, use an unfeaturized slot.

The Policy doesn’t have access to thevalue of your slots. It receives a featurized representation.As mentioned above, for a text slot the value is irrelevant.The policy just sees a 1 or 0 depending on whether it is set.

You should choose your slot types carefully!

You can provide an initial value for a slot in your domain file:

You can get the value of a slot using .get_slot() inside actions.py for example:

There are multiple ways that slots are set during a conversation:

If your NLU model picks up an entity, and your domain contains aslot with the same name, the slot will be set automatically. For example:

In this case, you don’t have to include the -slot{} part in thestory, because it is automatically picked up.

To disable this behavior for a particular slot, you can set theauto_fill attribute to False in the domain file:

You can use buttons as a shortcut.Rasa Core will send messages starting with a / to theRegexInterpreter, which expects NLU input in the same formatas in story files, e.g. /intent{entities}. For example, if you letusers choose a color by clicking a button, the button payloads mightbe /choose{'color':'blue'} and /choose{'color':'red'}.

You can specify this in your domain file like this:(see details in Domains)

The second option is to set slots by returning events in custom actions.In this case, your stories need to include the slots.For example, you have a custom action to fetch a user’s profile, andyou have a categorical slot called account_type.When the fetch_profile action is run, it returns arasa.core.events.SlotSet event:

In this case you do have to include the -slot{} part in your stories.Rasa Core will learn to use this information to decide on the correct action totake (in this case, utter_welcome_premium or utter_welcome_basic).

Slot Example Rasa

Note

It is very easy to forget about slots if you are writingstories by hand. We strongly recommend that you build up thesestories using Interactive Learning with Forms rather than writing them.

text
Use For

User preferences where you only care whether or not they’vebeen specified.

Example
Description

Results in the feature of the slot being set to 1 if any value is set.Otherwise the feature will be set to 0 (no value is set).

bool
Use For

True or False

Example
Description

Checks if slot is set and if True

categorical
Use For

Slots which can take one of N values

Example
Example
Description

Slot Example Rasa Mp3

Creates a one-hot encoding describing which of the values matched.A default value __other__ is automatically added to the user-definedvalues. All values encountered which are not explicitly defined in thedomain are mapped to __other__ for featurization. The value__other__ should not be used as a user-defined value; if it is, itwill still behave as the default to which all unseen values are mapped.

float
Use For

Continuous values

Example
Defaults

max_value=1.0, min_value=0.0

Slot Example Rasa Video

Description

All values below min_value will be treated as min_value, the samehappens for values above max_value. Hence, if max_value is set to1, there is no difference between the slot values 2 and 3.5 interms of featurization (e.g. both values will influence the dialogue inthe same way and the model can not learn to differentiate between them).

list
Use For

Lists of values

Example
Description

The feature of this slot is set to 1 if a value with a list is set,where the list is not empty. If no value is set, or the empty list is theset value, the feature will be 0. The length of the list stored inthe slot does not influence the dialogue.

unfeaturized
Use For

Data you want to store which shouldn’t influence the dialogue flow

Example
Description
Slot

There will not be any featurization of this slot, hence its value doesnot influence the dialogue flow and is ignored when predicting the nextaction the bot should run.

Maybe your restaurant booking system can only handle bookingsfor up to 6 people. In this case you want the value of theslot to influence the next selected action (and not just whetherit’s been specified). You can do this by defining a custom slot class.

In the code below, we define a slot class called NumberOfPeopleSlot.The featurization defines how the value of this slot gets converted to a vectorto our machine learning model can deal with.Our slot has three possible “values”, which we can represent witha vector of length 2.

Slot Example Rasa Al

(0,0)

not yet set

(1,0)

between 1 and 6

(0,1)

more than 6

Slot List Rasa Example

Now we also need some training stories, so that Rasa Corecan learn from these how to handle the different situations: