Return to site

Slot List Rasa

broken image


Contents

Currentslotvalues source ¶ Return the currently set values of the slots. Currentstate (eventverbosity: rasacore.trackers.EventVerbosity = ) → Dictstr, Any source ¶ Return the current tracker state as an object. Eventsafterlatestrestart source ¶ Return a list of events after the most recent restart.

  • Slot Filling
  • Rasa is an open source machine learning framework for building AI assistants and chatbots.Mostly you don't need any programming language experience to work in Rasa. Although there is something called 'Rasa Action Server' where you need to write code in Python, that mainly used to trigger External actions like Calling Google API or REST AP.
  • You can find all the links here: Ngrok: Imports used: import email import smtplib, ssl from email import encoders from smtplib imp.
  • A text slot only tells Rasa Core whether the slot has a value. The specific value of a text slot (e.g. Bangalore or New York or Hong Kong) doesn't make any difference. If the value itself is important, use a categorical or a bool slot. There are also float, and list slots.

One of the most common conversation patterns is to collect a few pieces ofinformation from a user in order to do something (book a restaurant, call anAPI, search a database, etc.). This is also called slot filling.

If you need to collect multiple pieces of information in a row, we recommendedthat you create a FormAction. This is a single action which contains thelogic to loop over the required slots and ask the user for this information.There is a full example using forms in the examples/formbot directory ofRasa Core.

You can take a look at the FormAction base class by clicking this link:

class rasa_core_sdk.forms.FormAction[source]

To add your forms to the domain file, reference their nameunder forms: section:

Using a FormAction, you can describe all of the happy paths with a singlestory. By 'happy path', we mean that whenever you ask a user for some information,they respond with what you asked for.

If we take the example of the restaurant bot, this single story describes all of thehappy paths.

In this story the user intent is request_restaurant, which is followed bythe form action restaurant_form. With form{'name':'restaurant_form'} theform is activated and with form{'name':null} the form is deactivated again.As shown in the section Handling unhappy paths the the bot can execute any kind ofactions outside the form while the form is still active. On the 'happy path',where the user is cooperating well and the system understands the user input correctly,the form is filling all requested slots without interruption.

The FormAction will only requests slots which haven't already been set.If a user says'I'd like a vegetarian Chinese restaurant for 8 people', they won't beasked about the cuisine and num_people slots.

Note that for this story to work, your slots should be unfeaturized.If they're not, you should add all the slots that have been set by the form.

The restaurant_form in the story above is the name of our form action.Here is an example of what it looks like.You need to define three methods:

  • name: the name of this action
  • required_slots: a list of slots that need to be filled for the submit method to work.
  • submit: what to do at the end of the form, when all the slots have been filled.

Once the form action gets called for the first time,the form gets activated and the FormPolicy jumps in.The FormPolicy is extremely simple and just always predicts the form action.See Handling unhappy paths for how to work with unexpected user input.

Every time the form action gets called, it will ask the user for the next slot inrequired_slots which is not already set.It does this by looking for a template called utter_ask_{slot_name},so you need to define these in your domain file for each required slot.

Once all the slots are filled, the submit() method is called, where you canuse the information you've collected to do something for the user, for examplequerying a restaurant API.If you don't want your form to do anything at the end, just use return[]as your submit method.After the submit method is called, the form is deactivated,and other policies in your Core model will be used to predict the next action.

Some slots (like cuisine) can be picked up using a single entity, but aFormAction can also support yes/no questions and free-text input.The slot_mappings method defines how to extract slot values from user responses.

Here's an example for the restaurant bot:

The predefined functions work as follows:

  • self.from_entity(entity=entity_name,intent=intent_name)will look for an entity called entity_name to fill a slotslot_name regardless of user intent if intent_name is Noneelse only if the users intent is intent_name.
  • self.from_intent(intent=intent_name,value=value)will fill slot slot_name with value if user intent is intent_name.To make a boolean slot, take a look at the definition of outdoor_seatingabove. Note: Slot will not be filled with user intent of message triggeringthe form action. Use self.from_trigger_intent below.
  • self.from_trigger_intent(intent=intent_name,value=value)will fill slot slot_name with value if form was triggered with userintent intent_name.
  • self.from_text(intent=intent_name) will use the nextuser utterance to fill the text slot slot_name regardless of user intentif intent_name is None else only if user intent is intent_name.
  • If you want to allow a combination of these, provide them as a list as in theexample above

After extracting a slot value from user input, the form will try to validate thevalue of the slot. By default, this only checks if the requested slot was extracted.If you want to add custom validation, for example to check a value against a database,you can do this by writing validate_{slot}() method.Here is an example which checks if the extracted cuisine slot belongs to alist of supported cuisines.

You can also deactivate the form directly during this validation step (in case theslot is filled with something that you are certain can't be handled) by returningself.deactivate()

You can also deactivate the form directly during this validation step (in case theslot is filled with something that you are certain can't be handled) by returningself.deactivate()

If nothing is extracted from the user's utterance for any of the required slots, anActionExecutionRejection error will be raised, meaning the action executionwas rejected and therefore Core will fall back onto a different policy topredict another action.

Of course your users will not always respond with the information you ask of them.Typically, users will ask questions, make chitchat, change their mind, or otherwisestray from the happy path. The way this works with forms is that a form will raisean ActionExecutionRejection if the user didn't provide the requested information.You need to handle events that might cause ActionExecutionRejection errorsin your stories. For example, if you expect your users to chitchat with your bot,you could add a story like this:

In some situations, users may change their mind in the middle of form actionand decide not to go forward with their initial request. In cases like this, theassistant should stop asking for the requested slots. You can handle such situationsgracefully using a default action action_deactivate_form which will deactivatethe form and reset the requested slot. An example story of such conversation couldlook as follows:

It is strongly recommended that you build these stories using interactive learning.If you write these stories by hand you will likely miss important things.Please read Interactive Learning with Formson how to use interactive learning with forms.

Slot list rasa movie

The slot requested_slot is automatically added to the domain as anunfeaturized slot. If you want to make it featurized, you need to add itto your domain file as a categorical slot. You might want to do this if youwant to handle your unhappy paths differently depending on what slot iscurrently being asked from the user. For example, say your users respondto one of the bot's questions with another question, like why do you need to know that?The response to this explain intent depends on where we are in the story.In the restaurant case, your stories would look something like this:

Again, is is strongly recommended that you use interactivelearning to build these stories.Please read Interactive Learning with Formson how to use interactive learning with forms.

Many forms require more logic than just requesting a list of fields.For example, if someone requests greek as their cuisine, you may want toask if they are looking for somewhere with outside seating.

You can achieve this by writing some logic into the required_slots() method,for example:

This mechanism is quite general and you can use it to build many differentkinds of logic into your forms.

To use forms, make sure to include the FormPolicy in your policyconfiguration file. For example:

The first thing to try is to run your bot with the debug flag, see Debugging for details.If you are just getting started, you probably only have a few hand-written stories.This is a great starting point, butyou should give your bot to people to test as soon as possible. One of the guiding principlesbehind Rasa Core is:

Learning from real conversations is more important than designing hypothetical ones

So don't try to cover every possibility in your hand-written stories before giving it to testers.Real user behavior will always surprise you!

We have a very active support community on Rasa Community Forumthat is happy to help you with your questions. If you have any feedback for us or a specificsuggestion for improving the docs, feel free to share it by creating an issue on Rasa CoreGitHub repository.

Rasa is an open-source machine learning framework for building AI assistants and chatbots. In Rasa, you can write the code only if you want to use Google API, REST APIs, or custom logic processing. For these, you can create an Action Server. The details of the Action Server described later.

Rasa Components

Rasa X

Rasa X is a tool designed to make it easier to deploy and improve Rasa-powered assistants by learning from real conversations. It's a Browser-based GUI tool that will allow you to train Machine learning models by using GUI based interactive mode.

Rasa Open Source

This includes two parts: one is Rasa NLU and the other is Rasa Core.

Rasa NLU

Rasa NLU is an open-source natural language processing tool for intent classification, response retrieval, and entity extraction in chatbots. The NLU part contains two properties one is Intent, and another is Entity. This is categorized by the help of two components.

Pretrained Embeddings
Intent_classifier_sklearn This classifier uses the spaCy library to load pre-trained language models which then are used to represent each word in the user message as word embedding.

Supervised Embeddings
Intent_classifier_tensorflow_embedding The intent classifier intent_classifier_tensorflow_embeddingwas developed by Rasa and is inspired by Facebook's StarSpace paper. Instead of using pre-trained embeddings and training a classifier on top of that, it trains word embeddings from scratch.

Rasa Core

Rasa Core is a dialogue engine for building AI assistants. Based on User message, it can predict dialogue as a reply and can trigger Rasa Action Server.

We can install the rasa using

or

For installing Rasa we need Python version 3.6+

Create a bot in Rasa

In this section, we are going to build a bot with the help of Rasa. First, we create a new project using the command

Using the ‘rasa init' command, you get a directory with a minimal sample project in RASA, named ‘moodbot'. We can modify this project as we like.The structure of rasa project is like:

Here we are going to build a Feedback bot using Rasa. First, run the Rasa init command and modify the project. In the data folder contain two files one is nlu.md and another one is stories.md. The NLU part contains the intents. First, we create intents for the feedback bot in 'nlu.md' file.

The domain.yml specifies the intents, entities, slots, and actions your bot should know about. Optionally, it can also include responses for the things your bot can say. In our bot, the domain.yml includes

In this domain file, we can see different fields like intent, slots, forms, responses. In the domain file, there is also one field named actions. In actions, we provided the name of the action defined in actions.py.

The intents field in the domain file contains the name of the intents that are provided in the NLU file, slots fields contain the slot names, Slots are your bot's memory.

They act as a key-value store that 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 a database query)[slots definition from rasa official document ].

Response fields contain the bot responses, the bot responses are defined under the utter_[add proper tag]. In this bot, we want to declare a form, which is defined in action.py. If we want to collect more information from the user we use FormAction, these forms are defined in the domain file, these are defined under the forms field.

In this project, we use forms for collecting feedback from users and these forms are defined under the forms field. In this, we use forms for collecting ratings, feedback, and influence details from users.

After defining the domain.yml we can set up the configuration file config.yml, configuration of your NLU and Core models

Free casino slots no download no registration with bonus rounds. Then we want to set up the file credentials.yml. In credentials.yml we can specify which platform we can use to connect the bot. Some of the supported platforms of rasa are

  1. Facebook
  2. Your own website
  3. Slack
  4. Telegram
  5. Twilio
Slot list rasa movie

This can be defined in credentials.yml. In this, we can connect the bot with Facebook by providing verify token, app secret and page access token

After setting up the messaging platform now we want to set up the endpoints. In the endpoints file, you can set up the Action server connection. Sometimes we want to write a code for bot's responses that are written in actions.py.

List

This actions.py runs in a separate server, for supporting action servers we provide an action server endpoint in endpoints.yml. The default action server endpoint URL: 'http://localhost:5055/webhook'. This is provided only if there is any action needed. In endpoints.yml also we can set up the tracker for storage.

Then we can set up the action.py, in this project we want to declare the forms for collecting information from users. In this bot defines four forms for collecting information form_get_rating, form_get_rating_quick, form_get_influence and form_get_support_feedback.

This code is provided in action.py. In this, we focus on declaring functions for getting information from the user. For form creation, we want to import 'FormAction' from rasa_sdk. Using 'FormAction' we can declare the forms. Below provides an example for 'FormAction',

This is the example defining a form for collecting ratings from users. The name function in the class defines the name of the form. In the function, required_slot defines the list of slot-names that want to be filled from the user side.

The slot_mappings method defines how to extract slot values from user responses. Once all the slots are filled, the submit() method is called, where you can use the information you've collected to do something for the user after the submit method is called, the form is deactivated, and other policies in your Core model will be used to predict the next action.

In this, we provide the name ‘form_get_rating' for FormAction. For this, provide a slot named by ‘rating'.The query for getting information from users provided under ‘utter_ask_[slotname]' in the domain file.

Then we want to define stories.md in the data folder. A story is a representation of a conversation between a user and an AI assistant, converted into a specific format where user inputs are expressed as corresponding intents (and entities where necessary) while the responses of an assistant are expressed as corresponding action names. A training example for the Rasa Core dialogue system is called a story.

A story starts with a name preceded by two hashes ## story_[name]. You can call the story anything you like, but it can be very useful for debugging to give them descriptive names.

In this example, we provide long feedback as a story name. Then we provide an intent name, and under the intent, name provides the corresponding response for the intent.

If the user enters something in the bot, with the help of rasa features recognize the corresponding intent, after recognizing the intent bot will respond with appropriate responses.

If a user enters ‘hi' the intent is recognized as ‘greet' intent and bot will respond with responses defined under the utter_greet and utter_menu templates.

After all this, we can collect feedback from users and this information is stored on Google spreadsheets. For these, we want to install two libraries ‘gspread' and ‘oauth2client', for installing

After installing these libraries, import these in actions.py. And set up the connection with Google spreadsheet,

In this, take a slot value using ‘tracker.get_slot(slot_name)' . We can get the JSON file from Google API dashboard (connecting Google spreadsheet with python youtube link: https://www.youtube.com/watch?v=4at0BuA6Zck).

After connecting Google spreadsheet we can store the collected information into it. This action is provided as the response of long_feedback, replacing the ‘utter_finish' into ‘action_data_update' in the story file and also adding the action into the Domain file.

Rasa bot training

After all set up we can train our bot using the command

After the training, the terminal output will be like,

To run the bot, you can use the following command.

To run your action server, run the following command

Now, let's connect our bot to Facebook Messenger. Make sure you have ngrok installed and run the following command.

After running the ngrok we get a URL. This URL is used in webhook creation for the Rasa message platform connection.‘https://yyyyyy.ngrok.io/webhooks/CHANNEL/webhook',

For connecting with Facebook provide the webhook ‘https://yyyyyy.ngrok.io/webhooks/facebook/webhook' in corresponding Facebook app's page.

Slot list rasa tv

The slot requested_slot is automatically added to the domain as anunfeaturized slot. If you want to make it featurized, you need to add itto your domain file as a categorical slot. You might want to do this if youwant to handle your unhappy paths differently depending on what slot iscurrently being asked from the user. For example, say your users respondto one of the bot's questions with another question, like why do you need to know that?The response to this explain intent depends on where we are in the story.In the restaurant case, your stories would look something like this:

Again, is is strongly recommended that you use interactivelearning to build these stories.Please read Interactive Learning with Formson how to use interactive learning with forms.

Many forms require more logic than just requesting a list of fields.For example, if someone requests greek as their cuisine, you may want toask if they are looking for somewhere with outside seating.

You can achieve this by writing some logic into the required_slots() method,for example:

This mechanism is quite general and you can use it to build many differentkinds of logic into your forms.

To use forms, make sure to include the FormPolicy in your policyconfiguration file. For example:

The first thing to try is to run your bot with the debug flag, see Debugging for details.If you are just getting started, you probably only have a few hand-written stories.This is a great starting point, butyou should give your bot to people to test as soon as possible. One of the guiding principlesbehind Rasa Core is:

Learning from real conversations is more important than designing hypothetical ones

So don't try to cover every possibility in your hand-written stories before giving it to testers.Real user behavior will always surprise you!

We have a very active support community on Rasa Community Forumthat is happy to help you with your questions. If you have any feedback for us or a specificsuggestion for improving the docs, feel free to share it by creating an issue on Rasa CoreGitHub repository.

Rasa is an open-source machine learning framework for building AI assistants and chatbots. In Rasa, you can write the code only if you want to use Google API, REST APIs, or custom logic processing. For these, you can create an Action Server. The details of the Action Server described later.

Rasa Components

Rasa X

Rasa X is a tool designed to make it easier to deploy and improve Rasa-powered assistants by learning from real conversations. It's a Browser-based GUI tool that will allow you to train Machine learning models by using GUI based interactive mode.

Rasa Open Source

This includes two parts: one is Rasa NLU and the other is Rasa Core.

Rasa NLU

Rasa NLU is an open-source natural language processing tool for intent classification, response retrieval, and entity extraction in chatbots. The NLU part contains two properties one is Intent, and another is Entity. This is categorized by the help of two components.

Pretrained Embeddings
Intent_classifier_sklearn This classifier uses the spaCy library to load pre-trained language models which then are used to represent each word in the user message as word embedding.

Supervised Embeddings
Intent_classifier_tensorflow_embedding The intent classifier intent_classifier_tensorflow_embeddingwas developed by Rasa and is inspired by Facebook's StarSpace paper. Instead of using pre-trained embeddings and training a classifier on top of that, it trains word embeddings from scratch.

Rasa Core

Rasa Core is a dialogue engine for building AI assistants. Based on User message, it can predict dialogue as a reply and can trigger Rasa Action Server.

We can install the rasa using

or

For installing Rasa we need Python version 3.6+

Create a bot in Rasa

In this section, we are going to build a bot with the help of Rasa. First, we create a new project using the command

Using the ‘rasa init' command, you get a directory with a minimal sample project in RASA, named ‘moodbot'. We can modify this project as we like.The structure of rasa project is like:

Here we are going to build a Feedback bot using Rasa. First, run the Rasa init command and modify the project. In the data folder contain two files one is nlu.md and another one is stories.md. The NLU part contains the intents. First, we create intents for the feedback bot in 'nlu.md' file.

The domain.yml specifies the intents, entities, slots, and actions your bot should know about. Optionally, it can also include responses for the things your bot can say. In our bot, the domain.yml includes

In this domain file, we can see different fields like intent, slots, forms, responses. In the domain file, there is also one field named actions. In actions, we provided the name of the action defined in actions.py.

The intents field in the domain file contains the name of the intents that are provided in the NLU file, slots fields contain the slot names, Slots are your bot's memory.

They act as a key-value store that 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 a database query)[slots definition from rasa official document ].

Response fields contain the bot responses, the bot responses are defined under the utter_[add proper tag]. In this bot, we want to declare a form, which is defined in action.py. If we want to collect more information from the user we use FormAction, these forms are defined in the domain file, these are defined under the forms field.

In this project, we use forms for collecting feedback from users and these forms are defined under the forms field. In this, we use forms for collecting ratings, feedback, and influence details from users.

After defining the domain.yml we can set up the configuration file config.yml, configuration of your NLU and Core models

Free casino slots no download no registration with bonus rounds. Then we want to set up the file credentials.yml. In credentials.yml we can specify which platform we can use to connect the bot. Some of the supported platforms of rasa are

  1. Facebook
  2. Your own website
  3. Slack
  4. Telegram
  5. Twilio

This can be defined in credentials.yml. In this, we can connect the bot with Facebook by providing verify token, app secret and page access token

After setting up the messaging platform now we want to set up the endpoints. In the endpoints file, you can set up the Action server connection. Sometimes we want to write a code for bot's responses that are written in actions.py.

This actions.py runs in a separate server, for supporting action servers we provide an action server endpoint in endpoints.yml. The default action server endpoint URL: 'http://localhost:5055/webhook'. This is provided only if there is any action needed. In endpoints.yml also we can set up the tracker for storage.

Then we can set up the action.py, in this project we want to declare the forms for collecting information from users. In this bot defines four forms for collecting information form_get_rating, form_get_rating_quick, form_get_influence and form_get_support_feedback.

This code is provided in action.py. In this, we focus on declaring functions for getting information from the user. For form creation, we want to import 'FormAction' from rasa_sdk. Using 'FormAction' we can declare the forms. Below provides an example for 'FormAction',

This is the example defining a form for collecting ratings from users. The name function in the class defines the name of the form. In the function, required_slot defines the list of slot-names that want to be filled from the user side.

The slot_mappings method defines how to extract slot values from user responses. Once all the slots are filled, the submit() method is called, where you can use the information you've collected to do something for the user after the submit method is called, the form is deactivated, and other policies in your Core model will be used to predict the next action.

In this, we provide the name ‘form_get_rating' for FormAction. For this, provide a slot named by ‘rating'.The query for getting information from users provided under ‘utter_ask_[slotname]' in the domain file.

Then we want to define stories.md in the data folder. A story is a representation of a conversation between a user and an AI assistant, converted into a specific format where user inputs are expressed as corresponding intents (and entities where necessary) while the responses of an assistant are expressed as corresponding action names. A training example for the Rasa Core dialogue system is called a story.

A story starts with a name preceded by two hashes ## story_[name]. You can call the story anything you like, but it can be very useful for debugging to give them descriptive names.

In this example, we provide long feedback as a story name. Then we provide an intent name, and under the intent, name provides the corresponding response for the intent.

If the user enters something in the bot, with the help of rasa features recognize the corresponding intent, after recognizing the intent bot will respond with appropriate responses.

If a user enters ‘hi' the intent is recognized as ‘greet' intent and bot will respond with responses defined under the utter_greet and utter_menu templates.

After all this, we can collect feedback from users and this information is stored on Google spreadsheets. For these, we want to install two libraries ‘gspread' and ‘oauth2client', for installing

After installing these libraries, import these in actions.py. And set up the connection with Google spreadsheet,

In this, take a slot value using ‘tracker.get_slot(slot_name)' . We can get the JSON file from Google API dashboard (connecting Google spreadsheet with python youtube link: https://www.youtube.com/watch?v=4at0BuA6Zck).

After connecting Google spreadsheet we can store the collected information into it. This action is provided as the response of long_feedback, replacing the ‘utter_finish' into ‘action_data_update' in the story file and also adding the action into the Domain file.

Rasa bot training

After all set up we can train our bot using the command

After the training, the terminal output will be like,

To run the bot, you can use the following command.

To run your action server, run the following command

Now, let's connect our bot to Facebook Messenger. Make sure you have ngrok installed and run the following command.

After running the ngrok we get a URL. This URL is used in webhook creation for the Rasa message platform connection.‘https://yyyyyy.ngrok.io/webhooks/CHANNEL/webhook',

For connecting with Facebook provide the webhook ‘https://yyyyyy.ngrok.io/webhooks/facebook/webhook' in corresponding Facebook app's page.

Slot List Rasa Example

The Google spreadsheet output like,

You can find the Github repo from here

Slot List Rasa Movie

Have a project in mind?

Looking for a reliable partner for your next project? Get In Touch With Us Today.





broken image