Custom Actions Flashcards

1
Q

What are custom actions?

A

Custom Actions allows you to run any code you want, like adding an event to a calendar, calling an API, sending emails, or anything else according to your requirement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can we setup a custom action to fill slots and send emails?

A

We need to run an action server by defining action endpoint in the endpoints.yml file.
E.g.:
action_endpoint: url: 'http://localhost:5055/webhook'

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are slots?

A
  • Slots are our bot’s memory.
  • Slots act as key-value store which can be used to store useful information that users provide.
  • These information can be used later during conversation. Slots are also useful to gather information from the outside world.
  • Results of a database query
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what ways can a slots be set?

A
  1. using custom actions
  2. from NLU
  3. from buttons in the UI
    4.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are slots set in custom actions?

A
Slots can only be set by returning it in the custom action, as shown below:

class AskReason(Action):
def name(self):
return ‘action_ask_reason’
~~~

	def run(self, dispatcher, tracker, domain):
		personal = tracker.latest_message.get('text')
    		return [SlotSet('reason',personal)]

~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where should every single custom action and slots used be defined?

A

Every single custom action and slots used should be defined in our domain file i.e domain.yml.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the possible types of slots?

A
Slots can be of different types for eg: 
text — for text type value, 
boolean — for true or false values, 
Category,
List,
unfeaturized — to not influence the dialog flow, and so on.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is SMTP?

A

Simple Mail Transfer Protocol (SMTP) is a protocol, which handles sending an e-mail and routing email between mail servers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Python’s built-in module for sending emails?

A
The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon. 
The smtplib modules is useful for communicating with mail servers to send mail.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Rasa NLU do to understand information?

A

It does intent classification and entity extraction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of stories.md?

A

Stories are used to teach Rasa real conversation designs to learn from providing the basis for a scalable machine learning dialogue management.

Rasa stories are a form of training data used to train the Rasa’s dialogue management models.

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is interactive learning?

A

Interactive learning is the way of providing feedback to your bot while you talk to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the benefits of interactive learning?

A
  • To generate training stories while talking to your bot.
  • To do debuggings and see if our intents and entities are being correctly classified using interactive learning.
  • To generate new training stories by asking newer and surprising questions to the bot.
  • If the information does not fall on any of the given intents, we can also create a new intent and assign it there.
  • To teach the bot something it doesn’t know yet.

All conversations you have with your bot in an interactive learning session can later be exported as NLU and dialogue training examples and attached to your original training data sample.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is required to train the bot in an interactive training session?

A

To train your bot in interactive learning session, you should have few training stories beforehand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What labels do you need to to train the model?

A

the intents for pieces of text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the preprocessing steps for raw data?

A
  1. Cleaning the text by removing stopwords and stemming
    Identifying keywords
  2. Calculating term frequencies
  3. K-means clustering in the space of term frequency vectors.
17
Q

If the value of a slot is important what types to use and why?

A
  • 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 flow of the conversation, use an unfeaturized slot.
18
Q

What is the purpose of a text slot?

A
  • 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.
19
Q

How are Slots Set from NLU?

A

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

# story_01
* greet{"name": "Ali"}
  - slot{"name": "Ali"}
  - utter_greet
20
Q

How disable auto filling of slots by the nlu?

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

slots:
name:
type: text
auto_fill: False
~~~

~~~

21
Q

How are Slots Set By Clicking Buttons?

A

Rasa Core will send messages starting with a / to the RegexInterpreter, which expects NLU input in the same format as in story files, e.g. /intent{entities}.
For example, if you let users choose a color by clicking a button, the button payloads might be /choose{“color”: “blue”} and /choose{“color”: “red”}.

22
Q

What tool can we user to create training data?

A

You can install and use rasa-nlu-trainer:

npm i -g rasa-nlu-trainer

23
Q

What is the purpose of the configuration file config_spacy.json

A
  • To specify configuration parameters used in training like:
    • pipeline
    • path
    • data
24
Q

What is the purpose of the pipeline parameter in file config_spacy.json

A

It specifies

- what featurizers/ feature extractors will be used to extract information

25
Q

What are the options pipeline parameter in file config_spacy.json

A
  • spacy_sklearn

- ???

26
Q

what are the basic imports for model training?

A
from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.model import Trainer
from rasa_nlu.model import Metadata, Interpreter
27
Q

How do you set slots programmatically?

A

Slots Set by Actions

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, and you have a categorical slot called account_type. When the fetch_profile action is run, it returns a rasa.core.events.SlotSet event:

slots:
   account_type:
      type: categorical
      values:
      - premium
      - basic
from rasa_sdk.actions import Action
from rasa_sdk.events import SlotSet
import requests
class FetchProfileAction(Action):
    def name(self):
        return "fetch_profile"
    def run(self, dispatcher, tracker, domain):
        url = "http://myprofileurl.com"
        data = requests.get(url).json
        return [SlotSet("account_type", data["account_type"])]
# story_01
* greet
  - action_fetch_profile
  - slot{"account_type" : "premium"}
  - utter_welcome_premium
# story_02
* greet
  - action_fetch_profile
  - slot{"account_type" : "basic"}
  - utter_welcome_basic
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 to take (in this case, utter_welcome_premium or utter_welcome_basic).
28
Q

How to set slots by clicking buttons?

A

Slots Set By Clicking Buttons

You can use buttons as a shortcut. Rasa Core will send messages starting with a / to the RegexInterpreter, which expects NLU input in the same format as in story files, e.g. /intent{entities}. For example, if you let users choose a color by clicking a button, the button payloads might be /choose{“color”: “blue”} and /choose{“color”: “red”}.

utter_ask_color:
- text: "what color would you like?"
  buttons:
  - title: "blue"
    payload: '/choose{"color": "blue"}'
  - title: "red"
    payload: '/choose{"color": "red"}'
29
Q

What does an example of a Text Slot look like?

A
Use For:	
User preferences where you only care whether or not they’ve been specified.
Example:
"""slots:
   cuisine:
      type: text
"""
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).
30
Q

What is an example of of a boolean type slot?

Write out on paper.

A

Boolean Slot
bool
Use For:
True or False

Example:	
slots:
   is_authenticated:
      type: bool
Description:	
Checks if slot is set and if True
31
Q

What is an example of of a Categorical type slot?

Write out on paper.

A

Categorical Slot
categorical
Use For:
Slots which can take one of N values

Example:	
slots:
   risk_level:
      type: categorical
      values:
      - low
      - medium
      - high
Description:	
Creates a one-hot encoding describing which of the values matched.
32
Q

What is an example of of a Float type slot?

Write out on paper.

A

Float Slot
float
Use For:
Continuous values

Example:	
slots:
   temperature:
      type: float
      min_value: -100.0
      max_value:  100.0
Defaults:	
max_value=1.0, min_value=0.0

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

33
Q

What is an example of of a List type slot?

Write out on paper.

A

List Slot
list
Use For:
Lists of values

Example:
slots:
shopping_items:
type: list

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 length of the list stored in the slot does not influence the dialogue.

34
Q

What is an example of of a Unfeaturized type slot?

Write out on paper.

A

Unfeaturized Slot
unfeaturized
Use For:
Data you want to store which shouldn’t influence the dialogue flow

Example:
slots:
internal_user_id:
type: unfeaturized

Description:
There will not be any featurization of this slot, hence its value does not influence the dialogue flow and is ignored when predicting the next action the bot should run.

35
Q

What is an example of of a Custom type slot?

Write out on paper.

A

Custom Slot Types
Maybe your restaurant booking system can only handle bookings for up to 6 people. In this case you want the value of the slot to influence the next selected action (and not just whether it’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 vector to our machine learning model can deal with. Our slot has three possible “values”, which we can represent with a vector of length 2.

(0,0) not yet set
(1,0) between 1 and 6
(0,1) more than 6
from rasa.core.slots import Slot

class NumberOfPeopleSlot(Slot):

    def feature_dimensionality(self):
        return 2
    def as_feature(self):
        r = [0.0] * self.feature_dimensionality()
        if self.value:
            if self.value <= 6:
                r[0] = 1.0
            else:
                r[1] = 1.0
        return r
Now we also need some training stories, so that Rasa Core can learn from these how to handle the different situations:
"""
# story1
...
* inform{"people": "3"}
  - action_book_table
...
# story2
* inform{"people": "9"}
  - action_explain_table_limit
"""