Rasa Certification Workshop: Mady Mantha, Juste Petraityte, Karen White
Rasa Certification Workshop: Mady Mantha, Juste Petraityte, Karen White
Agenda
Part 1: Welcome and deep dive into Rasa
● Welcome! 👋
● Intro to Rasa
● Conversation Design
● Deep dive into NLU
● Deep dive into dialogue policies
● CDD and testing
● Demo
Part 2: Adding custom actions, forms and improving your assistant using Rasa X
Part 1 Roadmap
Level 1:
Last 10 years
Command-based
A few
examples
Level 3:
today Contextual Assistants
Level 4:
In 2-5 years
Consultative Assistants
Level 5:
In 5-10 years
Adaptive Assistants
Natural
Language
Understanding
“I want to change
my address”
Connector
ML-based
Modules
Dialogue
E.g. Live Chat, Management
“What’s your new App, Messenger Backend,
address?” database,
API, etc.
Response
Selection
Conversational AI is not easy
Real conversations don’t follow the happy path
THE APPROACH
Quality of assistant
Natural
Language
Understanding
How much did I
spend at Starbucks
last week?
ML-based
Connector Dialogue
Modules Management
Backend,
~~~ database,
API, etc.
Response
Selection
NLU Deep Dive
{...
"intent": {
"name": "search_transactions ",
"confidence": 0.96
},
How much did I spend "entities": [
at Starbucks last {
week? "entity": "vendor_name ",
"value": "Starbucks",
...
}
]
}
NLU Deep Dive
Raw Text
Text Text
Tokenizer Tokens
Featurizer Representation
Entity Intent
Extractor Classifier
Entities Intent
NLU DEEP DIVE
Entity Intent
Extractor Classifier
“Text Representation”
How do words turn into numbers?
[(0, 421) 1
(1, 48) 2
Text
Tokens Text Representation : :
Featurizer
(2, 90) 1
(2, 150) 1]
Entities Intent
NLU DEEP DIVE
Entity Intent
Extractor Classifier
search_transa
vendor_name: starbucks
ctions
NLU DEEP DIVE
“...sleep in a bed?”
sleep?
bed mattress
“...sleep on a mattress...”
Non-sequence model:
Sequence model:
○ One feature vector per token (word) & feature vector for whole message
○ Word order captured
Configuration Files
Livecoding
1. Let’s use a sandbox branch instead of the master branch you cloned yesterday. Make sure you are inside
the financial-demo folder:
cd financial-demo
Domain
Defines the “world” of your assistant - what it knows, can understand, and can do
NLU Pipeline
language: "en"
pipeline:
- name: "Whitespacetokenizer"
- name: "ConveRTFeaturizer"
- name: "RegexFeaturizer" Components
- name: "LexicalSyntacticFeaturizer"
- name: "CountVectorsFeaturizer"
NLU Deep Dive
- Tokenizers
- Word Vector Sources
- Text Featurizers
- Entity Extractors
- Intent Classifiers
- Response Selectors
- Sentiment analysis
- Spell checking
NLU DEEP DIVE
Intent search_transactions
DIETClassifier
Entities vendor name: starbucks
Dense
Features Sparse
(Pretrained Features
Embeddings)
intent
NLU DEEP DIVE
sparse features
in pipeline
BERT/GloVe/pretrained
and continuous
features
NLU DEEP DIVE
Possible Approaches:
Policies
● Decide which action to take at every step in the conversation
● Each policy predicts an action with some probability. This is called core confidence.
Interpreter
“I want to know
1
how much I spent
2
at Starbucks last Message In
week”
3
Tracker Policy
Message Out
6
“You spent $12 at 5
Starbucks”
Action 4
Core Deep Dive: Policies
Multiple Policies
Policy priorities
(higher numbers = higher priority)
Rule-based
5. FormPolicy
policies have
4. FallbackPolicy, TwoStageFallbackPolicy
higher priority 3. MemoizationPolicy, AugmentedMemoizationPolicy
than ML-based 2. MappingPolicy
policies 1. EmbeddingPolicy, KerasPolicy, TED
Conversation Design
Core Deep Dive
I just moved
I just moved
Scope Conversation
Scope Conversation
Source: Botsociety
Livecoding
● Search transactions
Core Deep Dive
Shall we mail
Context: Mailing to an address letters to the same Previous Action
address too?
Intent Action
clarification_question show_mailing_address
90.5% probability 92.5% probability
vector = (0, 11, 26, … , 1) vector =(2 , 212, 90, … , 5)
Core Deep Dive
Intent Action
clarification_question show_payment_info
90.5% probability 89.3% probability
vector = (0, 11, 26, … , 1) vector =(4 , 170, 90, … , 5)
previous
Core Deep Dive
entity: vendor_name
Natural Language value: Starbucks
Understanding …
name: search_transactions
confidence: 0.96
ML-based Dialogue
tor Modules Management
Core Deep Dive
Natural
Language
Understanding
My new address is
222 Broadway NYC.
ML-based
Connector Dialogue
Modules Management
Backend,
~~~ database,
API, etc.
Response
Selection
Training Data
Training Data for NLU and Dialogue Management
Machine learning models require training data that the models can
generalize from
NLU needs data in the form of examples for Dialogue management model needs
intents data in the form of stories
## intent:bot_challenge ## new to rasa at start
- are you a bot? * how_to_get_started{" user_type":
- are you a human? "new"}
- am I talking to a bot? - action_set_onboarding
- am I talking to a human? - slot{" onboarding": true}
- utter_getstarted_new
## intent:i_like_food - utter_built_bot_before
- I like [ apples](food) * deny
- my friend likes [ oranges](food) - utter_explain_rasa_components
- I'm a fan of [ pears](food) - utter_rasa_components_details
- do you like [ coffee](food) - utter_ask_explain_nlucorex
Rasa Deep Dive
Natural
Language
Understanding
“How much did I
spend at Starbucks
last week?”
Connector
ML-based
Modules
Dialogue
E.g. Live Chat, Management
“You spent $12 at App, Messenger Backend,
Starbucks!” database,
API, etc.
Response
Selection
Deep dive into DIET, TED, and some testing!
Core Deep Dive
Domain
Defines the “world” of your assistant - what it knows, can understand, and can do
In other words
Glue is out, SuperGlue is in
@madymantha
NLU Deep Dive
What is DIET?
● New state of the art neural network architecture for NLU
● Predicts intents and entities together
● Plug and play pretrained language models
NLU DEEP DIVE
sparse features
in pipeline
BERT/GloVe/pretrained
and continuous
@madymantha features
How to use DIET in your Rasa project
@madymantha
Experiments on the NLU-benchmark dataset
● Repo is on github
● Domain: human-robot interaction (smart home setting)
● 64 different intents
● 54 different entity types
● ~26k labelled examples
@madymantha
Result 1: DIET outperforms SotA even without any pretrained embeddings
@madymantha
Result 2: GloVe embeddings perform better than BERT
@madymantha
Result 3: ConveRT embeddings perform best on the NLU-benchmark
dataset
@madymantha
Result 4: DIET outperforms fine-tuning BERT
@madymantha
Which featurizer is best depends on your dataset, so try different
ones!
We don’t believe in “one size fits all” machine
learning
@madymantha
Transformer
Embedding Dialogue
policy (TED)
NLU Deep Dive
@madymantha
Happy paths are already solved
@madymantha
You can’t predict user behavior
@madymantha
Users will interject and loop back to
earlier topics
@madymantha
Real conversations don’t follow the
happy path
@madymantha
People typically use a recurrent neural net (RNN) to model dialogue
W h1 W
y1
W
W W
h2 y2
W
W W y3
h3
@madymantha
But not all input should be treated equally
https://ai.googleblog.com/2017/08/transformer-novel-neural-network.html
@madymantha
Transformers (AKA self-attention) are now state of the art for many
tasks
https://distill.pub/2016/augmented-rnns/
@madymantha
We found out that the Transformer Embedding Dialogue policy can
untangle sub-dialogues
paper
@madymantha
Development Stages
The challenge
When developing assistants, it’s impossible to anticipate all of the things your users might say.
The approach
A user-centric process: listening to your users and using those insights to improve your AI assistant.
te
ew
re
k
ta
st
ac
x
a
vi
no
Fi
Te
Sh
Tr
Re
An
1 2 3 4 5 6
Rasa X
RASA TOOLS AND PRODUCTS
@madymantha
THE APPROACH
● Test your model after training to make development more productive and reliable
Adding custom actions and implementing forms
RASA CERTIFICATION WORKSHOP
Agenda
Day 1: Welcome and deep dive into Rasa
● Welcome! 👋
● Intro to Rasa
● Conversation Design
● Deep dive into NLU
● Deep dive into dialogue policies
● CDD and testing
● Demo
Day 2: Adding custom actions, forms and improving your assistant using Rasa X
Part 1:
Part 2:
Natural
Language
Understanding
“I want to change
my address”
Connector
ML-based
Modules
Dialogue
E.g. Live Chat, Management
“What’s your new App, Messenger Backend,
address?” database,
API, etc.
Response
Selection
LIVE CODING: MINIMUM VIABLE ASSISTANT
Events
Events Story
Tracker
● Trackers maintain the state of a dialogue between the assistant and the user.
● It keeps track of events, slots, session info etc.
{
"sender_id": "default", Session info
"slots": {
"user_type": "new",
"onboarding": true}, Slots
"latest_message": {...},
"events": [
...
{"event": "action", Events:
"name": "action_set_onboarding",
"policy": "MemoizationPolicy",
...
"confidence": 0.92}, SlotSet
... ...
{"event": "user", UserUttered
"text": "\/restart",...},
...
...
]
}
Core Deep Dive
Slots
Your bot’s memory
Slots
● Can store:
○ user-provided info
○ info from the outside world
● Can be set by:
○ NLU (from extracted entities, or buttons)
○ Custom Actions
● Can be configured to affect or not affect the dialogue progression
Core Deep Dive
Slots types
Text and List slots influence conversation path based on whether it is set or not.
Slots types
Categorical, Boolean and Float slots influence conversation path based on the value
of the slot.
Slots types
Unfeaturized slots don’t have any influence on the dialogue.
Slots
There are a few different ways how slots can be set
## intent:search_transactions
- how much did I spend at [Target](vendor_name) this week?
- what is my typical spending at [Amazon](vendor_name)?
Core Deep Dive
Slots
There are a few different ways slots can be set
utter_ask_transfer_form_confirm:
Would you like to transfer $100 to Tom?
- text: “Would you like to transfer $100 to Tom?”
buttons: No, cancel the
Yes
- title: Yes transaction
payload: /affirm
- title: No, cancel the transaction
payload: /deny
Core Deep Dive
Slots
There are a few different ways how slots can be set
1. Let’s use a sandbox branch for today’s exercise. First, make sure your are in a financial bot directory:
cd financial-demo
Natural
Language
Understanding
My new address is
222 Broadway NYC.
ML-based
Connector Dialogue
Modules Management
Backend,
~~~ database,
Natural API, etc.
Response
Language
Selection
Generation
Core Deep Dive
Actions
Functions your bot runs in response to user input.
Four different action types:
● Utterance actions: `utter_`
○ send a specific message to the user
○ specified in `responses` section of the domain
● Retrieval actions: `respond_`
○ send a message selected by a retrieval model
● Custom actions: `action_`
○ run arbitrary code and send any number of messages (or none).
○ return events
● Default actions:
○ built-in implementations available but can be overridden
○ E.g. action_listen, action_restart, action_default_fallback
Core Deep Dive
class ActionCheckAddress(Action):
def name(self) -> Text:
“Should I also
return "action_check_address"
update your
mailing address?”
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
idnum = tracker.get_slot('person_id')
“What do you have q = "SELECT Address FROM Customers \
on file?” \WHERE CustomerID=1;'{0}'".format(idnum)
result = db.query(q)
return [SlotSet(
"address",
result if result is not None else "NotOnFile")]
Let’s Code
We will implement a custom action which will allow users to check their account
balance:
Hello
Forms
Rasa Forms allow you to describe all happy paths with a single story
## Happy path 1:
U: I would like to make a money transfer
B: Towards which credit card would you like to make a payment?
U: Towards my justice bank credit card
B: How much do you want to pay? ## pay credit card happy path
U: $100
* pay_cc
B: The transaction has been scheduled.
- cc_payment_form
- form{"name": "cc_payment_form"}
Forms
The structure of the form
- cc_payment_form
Form action
Form activated - form{"name": "cc_payment_form"}
Forms
FormAction is a custom action which allows you to set the required slots and
determine the behaviour of the form
Forms
FormAction is a custom action which allows you to set the required slots and
determine the behaviour of the form
" " "A list of required slots to fill in" " "
return [“credit_card”, “amount_of_money”]
Core Deep Dive
Forms
FormAction is a custom action which allows you to set the required slots and
determine the behaviour of the form
● submit - defines the output of the form action once all slots are filled in
" " "Defines what the form has to do after all slots are filled in" " "
dispatcher.utter_message(“The payment is confirmed”)
return [AllSlotsReset()]
Core Deep Dive
With slot mappings you can define how certain slots can be extracted from:
- Entities
- Intents
- Support free text input
- Support yes/no inputs
" " "Defines what the form has to do after all slots are filled in" " "
return {
“confirm”: [
self.from_intent(value:True, intent=”affirm”),
self.from_intent(value:False, intent=”deny”)
]
}
Core Deep Dive
Forms
Custom Form Action
Custom Form Action allows you to add new methods to a regular FormAction.
class CustomFormAction(FormAction):
def name(self):
return “”
Forms
Handling unhappy paths
Users are not always cooperative - they can change their mind or interrupt the form.
Forms
Users are not always cooperative - they can change their mind or interrupt the form.
● Use action action_deactivate_form to handle the situation where users decide not to proceed with the form:
## chitchat
* pay_cc
- cc_payment_form
- form{"name": "cc_payment_form"}
* stop
- utter_ask_continue
* deny
- action_deactivate_form
- form{"name": null}
Core Deep Dive
Forms
How this affect domain and policy configuration?
Iron bank
$1000
Today
Yes
Part 4: Messaging Channels,
Conversation Driven Development,
and Rasa X
Agenda
● It is very hard.
● Building a prototype is not the hard part.
● The hard parts all show up when you want to go from a
prototype to something you’d want to ship.
te
ew
re
k
ta
st
ac
x
a
vi
no
Fi
Te
Sh
Tr
Re
An
1 2 3 4 5 6
Share
That’s a great start, but all of those scenarios are based on human:human conversations.
Human:bot conversations have different patterns - users talk to a bot differently than they do a human
Human + human 2
conversations
Quality
3 Manufactured data
Documentation, FAQs 4
By the time you go to production, most of your training data should
come from human:bot interactions
Human + human 2
conversations
3 Manufactured data
Documentation, FAQs 4
Test
‘Negative’ signals are useful too, e.g. users not getting back in
touch with support.
Prototype
Fix
It’s not a linear process: you’ll find yourself jumping between these
actions
�� ��
Messaging Share your
Conversations Conversations
channels
Rasa X bot
≈≈
Rasa X Local mode vs Server mode
Local Mode:
Server Mode:
● Great for serving your bot and collecting conversations from many testers or users, 24/7
● Production-ready & scalable
● Deploys Rasa X (and your assistant) using Docker Compose or Kubernetes
● Conversations get saved to a production database
● Includes a Git integration (integrated version control)
Share your bot with testers using just a link
Review conversations coming in from every channel
Annotate the messages coming in
Push new training data to git and trigger your CI pipeline
#232a2e
Track failures and successes
Use the API to automatically tag conversations, or add Turn successful conversations into new
tags manually as you read end-to-end tests
Installing Rasa X Locally
Launch Rasa X in the browser by running the following command in your project directory:
rasa x
Testing Locally: ngrok
Creates a secure, publicly accessible tunnel URL connected to a process running on localhost.
Allows you to develop as though your application were running on a server instead of locally.
Starting ngrok
Natural
Language
Understanding
“I want to change
my address”
Message
ML-based
Channels
Dialogue
E.g. Live Chat, Management
“What’s your new App, Messenger Backend,
address?” database,
API, etc.
Response
Selection
MESSAGING CHANNELS
Built in Channels
Telegram
Messaging Channels
- Go to https://web.telegram.org/#/im?p=@BotFather
- Type /newbot
- Name shows up next to the bot’s profile icon
- Username is the bot’s handle, and ends in _bot
credentials.yml
Telegram:
access_token: "your API token"
verify: "bot’s username (ends in _bot)"
webhook_url: "https://<ngrok-url>/webhooks/telegram/webhook"
Testing Telegram locally
1. Start the rasa server (this command starts the server without a chat session on the command line)
a. rasa run
2. Start ngrok on port 5005
a. ngrok http 5005
3. Add the ngrok URL to your Telegram webhook URL - save the file
4. Restart the Rasa server (so changes to credentials.yml get picked up)
a. /stop
b. rasa run
5. Make sure your action server is running!
6. Try talking to your bot on Telegram
What’s Next?
NEXT STEPS
Get people to chat with your assistant and keep improving it!
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
THE APPROACH
Quality of assistant
Rasa X (Server)
Build a minimum viable assistant with Rasa Open Source + improve it
using Rasa X
um y sing sing
minim nt ove b ove u ns ove u ns
u i l d Impr h e I m p r I m p r
B
e ass
ista ng to t t ersat
io rsatio
Talk to viabl ta l k i
tan conv t users conve l users
assis tes rea
your bot with with
Quality of assistant
um y sing sing
Share minim nt ove b ove u ns ove u ns
u i l d Impr h e I m p r I m p r
your bot B
e ass
ista ng to t t ersat
io rsatio
viabl ta l k i
tan conv t users conve l users
assis tes rea
with with
Quality of assistant
Quality of assistant
● Set up
● Deep dive of NLU and dialogue management
● Build an MVP assistant
● Share your assistant with the outside world
● Make iterative improvements and take your assistant to the next level
RASA OPEN SOURCE
Natural
Language
Understanding
“How much did I
spend at Starbucks
last week?”
Connector
ML-based
Modules
Dialogue
E.g. Live Chat, Management
“You spent $12 at App, Messenger Backend,
Starbucks!” database,
API, etc.
Response
Selection
NLU Deep Dive
Policies
Interpreter
“I want to know
1
how much I spent
2
at Starbucks last Message In
week”
3
Tracker Policy
Message Out
6
“You spent $12 at 5
Starbucks”
Action 4
Core Deep Dive
Domain
Defines the “world” of your assistant - what it knows, can understand, and can do
Multiple Policies
Policy priorities
(higher numbers = higher priority)
Rule-based
5. FormPolicy
policies have
4. FallbackPolicy, TwoStageFallbackPolicy
higher priority 3. MemoizationPolicy, AugmentedMemoizationPolicy
than ML-based 2. MappingPolicy
policies 1. EmbeddingPolicy, TEDPolicy
NLU Deep Dive
What is DIET?
● New state of the art neural network architecture for NLU
● Predicts intents and entities together
● Plug and play pretrained language models
We found out that the Transformer Embedding Dialogue policy can
untangle sub-dialogues
paper
@madymantha
Conversation Design
Scope Conversation
How to get started with conversation design
Machine learning models require training data that the models can
generalize from
NLU needs data in the form of examples for Dialogue management model needs
intents data in the form of stories
## intent:bot_challenge ## new to rasa at start
- are you a bot? * how_to_get_started{" user_type":
- are you a human? "new"}
- am I talking to a bot? - action_set_onboarding
- am I talking to a human? - slot{" onboarding": true}
- utter_getstarted_new
## intent:i_like_food - utter_built_bot_before
- I like [ apples](food) * deny
- my friend likes [ oranges](food) - utter_explain_rasa_components
- I'm a fan of [ pears](food) - utter_rasa_components_details
- do you like [ coffee](food) - utter_ask_explain_nlucorex
LIVE CODING: MINIMUM VIABLE ASSISTANT
● A basic assistant that can handle the most important happy path stories.
○ Happy path: If your assistant asks a user for some information and the user
provides it, we call that a happy path.
○ Unhappy path: All the possible edge cases of the bot
Testing
Natural
Language
Understanding
My new address is
222 Broadway NYC.
ML-based
Connector Dialogue
Modules Management
Backend,
~~~ database,
Natural API, etc.
Language
Generation
Core Deep Dive
Events
● Internally, all conversations are represented as a sequence of events.
● Some events are automatically tracked
Events Story
Tracker
● Trackers maintain the state of a dialogue between the assistant and the user.
● It keeps track of events, slots, session info etc.
{
"sender_id": "default", Session info
"slots": {
"user_type": "new",
"onboarding": true}, Slots
"latest_message": {...},
"events": [
...
{"event": "action", Events:
"name": "action_set_onboarding",
"policy": "MemoizationPolicy",
...
"confidence": 0.92}, SlotSet
... ...
{"event": "user", UserUttered
"text": "\/restart",...},
...
...
]
}
Core Deep Dive
Slots
Your bot’s memory
● Can store:
○ user-provided info
○ info from the outside world
● Can be set by:
○ NLU (from extracted entities, or buttons)
○ Custom Actions
● Can be configured to affect or not affect the dialogue progression
Core Deep Dive
Actions
Things your bot runs in response to user input.
Four different action types:
● Utterance actions: `utter_`
○ send a specific message to the user
○ specified in `responses` section of the domain
● Retrieval actions: `respond_`
○ send a message selected by a retrieval model
● Custom actions: `action_`
○ run arbitrary code and send any number of messages (or none).
○ return events
● Default actions:
○ built-in implementations available but can be overridden
○ E.g. action_listen, action_restart, action_default_fallback
Core Deep Dive
Forms
The structure of the form
- cc_payment_form
Form action
Form activated - form{"name": "cc_payment_form"}
Forms
Handling unhappy paths
Users are not always cooperative - they can change their mind or interrupt the form.
● Use action action_deactivate_form to handle the situation where users decide not to proceed with the form:
## chitchat
* request_restaurant
- restaurant_form
- form{"name": "restaurant_form"}
* stop
- utter_ask_continue
* deny
- action_deactivate_form
- form{"name": null}
Rasa X Tour
�� ��
Messaging Share your
Conversations Conversations
channels
Rasa X bot
That’s a great start, but all of those scenarios are based on human:human conversations.
Human:bot conversations have different patterns - users say different things when they are talking to a bot.
te
ew
re
k
ta
st
ac
x
a
vi
no
Fi
Te
Sh
Tr
Re
An
1 2 3 4 5 6
Build a minimum viable assistant with Rasa Open Source + improve it
using Rasa X
um y sing sing
minim nt ove b ove u ns ove u ns
u i l d Impr h e I m p r I m p r
B
e ass
ista ng to t t ersat
io rsatio
viabl ta l k i
tan conv t users conve l users
Talk to assis tes rea
with with
your bot
Quality of assistant
Quality of assistant
Quality of assistant