How does a conversational assistant understand questions like “What is the most expensive transaction on food I have made?” and where does it get the data to answer this kind of questions correctly? Or imagine a conversation with a bot that helps you manage your bank accounts. A person might ask questions like “On which of those accounts do I have more money?” or “What is the IBAN of the second account you just mentioned?”. How do we give our bot access to the relevant domain knowledge?
In this talk I will explain how I solved this by integrating a conversational assistant, built with Rasa, with a knowledge graph, built with Grakn. Together, these open source libraries help me understand what my bot’s users are talking about.
Boost Fertility New Invention Ups Success Rates.pdf
Grounding Conversational AI in a Knowledge Base
1. Confidential and proprietary.
Any use of this material without specific permission of Rasa is strictly prohibited.
Grounding Conversational AI in a
Knowledge Base
Tanja Bunk, Machine Learning Engineer @ Rasa
1
5. Conversations are easy! NOT easy!
Domain knowledge
needed to list entities.
5
Hi! How can I help you?
Can you list all my accounts please?
Sure, here is what I found:
1. N26, account number DE61500105171526138412
2. Deutsche Bank, account number DE89500105171722749148
Hi!
6. Conversations are easy! NOT easy!
6
Hi! How can I help you?
Can you list all my accounts please?
Sure, here is what I found:
1. N26, account number DE61500105171526138412
2. Deutsche Bank, account number DE89500105171722749148
On which of those accounts do I currently have more money?
Hi!
Reference to entities
listed before.
7. Conversations are easy! NOT easy!
7
Reference to N26
account.
Can you list all my accounts please?
Sure, here is what I found:
1. N26, account number DE61500105171526138412
2. Deutsche Bank, account number DE89500105171722749148
On which of those accounts do I currently have more money?
You have a balance of 2324,84€ on N26.
Your balance on Deutsche Bank is only 523,83€.
What are my recent transactions on that account?
8. Conversations are easy! NOT easy!
8
Domain knowledge
needed to answer user
questions.
On which of those accounts do I currently have more money?
You have a balance of 2324,84€ on N26.
Your balance on Deutsche Bank is only 523,83€.
What are my recent transactions on that account?
Your recent transactions on N26 are:
Zalando 43,54€
Pasta Bar 9,90€
Esprit 103,21€
Max Mustermann 200,00€
9. Conversations are easy! NOT easy!
9
Domain knowledge
needed to resolve an
unclear mention of a
real-world entity.
How much money did I spend on food?
You spent 16,89€ on food in the last month.
How much money did I transfer to Max?
You have transferred money to multiple people with the
name Max. Which Max do you mean?
1. Max Müller
2. Max Mayer
10. Conversations are easy! NOT easy!
10
Reference to Max
Müller.
How much money did I transfer to Max?
You have transferred money to multiple people with the
name Max. Which Max do you mean?
1. Max Müller
2. Max Mayer
I meant the first one.
I found the following transactions to Max Müller:
24.09.2019 Food 23,50 €
01.10.2019 Hotel Berlin 350,00 €
16.10.2019 Present Sara 10,00 €
15. INTRODUCTION: RASA
Rasa Open Source is a set of open source machine learning
tools for developers for conversational AI:
● NLU: open-source natural language processing
tool for intent classification and entity extraction
● Core: framework for machine learning-based,
contextual decision making
Rasa Open Source: Tools for developers to build text and voice assistants
in-house
15
16. Rasa’s technology can understand natural language and decide about the next best
action based on the context of the conversation using machine learning
Backend, CRM,
database, API, etc.
INTRODUCTION: RASA
ML-based
Dialogue
Management
“The Brain”
Input Modules
“The Ears”
Natural Language
Understanding
Output
Modules
“The Mouth”
Response Generator
Connector
Modules
Live Chat, App,
Messenger, Phone
SMS, etc.
“I want to change
my address”
(User Request via
text or voice)
“What’s your new
address?”
(AI response via
text or voice)
User Backend
Data Control
Companies keep
complete control of
their data and customer
interaction
Via communication channel:
16
Rasa Open Source
17. What do we need knowledge bases for?
17
RASA & GRAKN
18. The assistant only knows whatever you taught it!
18
RASA & GRAKN
● Knowledge of the bot is limited to whatever is contained in the training data
● Bots do not have access to external knowledge by default
● Knowledge is fixed, bots need to be redeployed to update knowledge
Solution: Connect Rasa Open Source to a knowledge base!
19. Store your domain knowledge in a knowledge base
19
RASA & GRAKN
Knowledge bases
● Store for domain knowledge
● Typically represented by graph databases
Using a graph database allows you to
● Store complex data structures
● Easily store relations between different entities
● Think of data in an object-oriented way (entities, attributes, relations)
● Query data fast
20. We chose Grakn as our knowledge base store
20
RASA & GRAKN
● Open source
● Easy to set-up
● Has a great documentation & support
● Implements a hyper graph data model with a schema/logical verification
● Provides a reasoning engine to do reasoning at query run time as part of the language
● Offers distributed analytical algorithms as part of the language
22. Question to be answered
22
BUILDING A BOT
What is the headquarter of N26?
23. Step 1: Set up a knowledge base
23
BUILDING A BOT
24. Knowledge base schema can get complex very fast
24
BUILDING A BOT
Think about the schema before implementing it.
● What entities do you need?
● What attributes do the entities have?
● How are the entities related to each other?
Be careful: The more complex the schema, the more complex the queries will be.
25. Knowledge base schema of our banking bot
25
BUILDING A BOT
name
bank
free-accounts
country
headquarter
contract
transaction
card
represented-
by
person
email
first-name
last-name
gender
city
sign-date
account-numberaccount-type
balance
opening-date
account
name-on-card
expiry-date
card-number
created-date
amount
category
reference
execution-date
english-website
english-customer-
service
26. Fill your knowledge base with data
26
BUILDING A BOT
insert
$b isa bank,
has name ‘N26’,
has country ‘Germany’,
has headquarter ‘Berlin’,
has free-accounts true,
has english-website true,
has english-customer-service true;
Example: Query to insert bank N26
27. Step 2: Add new training data
27
BUILDING A BOT
28. The bot needs to understand every user message
28
BUILDING A BOT
● During a conversation
○ An intent will be assigned to every user message
○ Entities will be extracted from every user message
● Define new intent(s) for messages that should result in querying the knowledge base
● Define every entity that occurs in the training data that are important for querying the knowledge
base
## intent:query_knowledge_base
- What [gender](attribute) is [Hans Maier](person)?
- What is the [headquarter](attribute) of [Deutsche Bank](bank)?
- Does [N26](bank) have an [english
website](attribute:english-website)?
- How much [money](attribute:balance) do I have on that account?
- What is my [balance](attribute) on that account?
NLU Data
29. The bot needs to know when to query the knowledge base
29
BUILDING A BOT
● Bot predicts after every message what to do next
● Define some example dialogues (stories) that interact with the knowledge base
● Bot learns from those dialogues what to do if a certain user message comes in
## Happy Path
* greet
- utter_greet
* query_knowledge_base
- action_query_knowledge_base
* goodbye
- utter_goodbye
Story
31. Use custom actions to query the knowledge base
31
BUILDING A BOT
Rasa Open Source
1. NLU
2. Core
3. Action
actions.py
Definition of some
custom actions that
interact with the
knowledge base.
knowledge
base
user’s message
bot’s message
query
32. Use custom actions to query the knowledge base
32
BUILDING A BOT
Rasa Open Source
1. NLU
2. Core
3. Action
What is the
headquarter of N26?
33. Use custom actions to query the knowledge base
33
BUILDING A BOT
intent:
query_knowledge_base 95%
entities:
attribute: headquarter 93%
bank: N26 98%
What is the
headquarter of N26?
Rasa Open Source
1. NLU
2. Core
3. Action
34. Use custom actions to query the knowledge base
34
BUILDING A BOT
next action:
action_query_knowledge_base 95%
utter_greet 1%
utter_goodbye 4%
What is the
headquarter of N26?
Rasa Open Source
1. NLU
2. Core
3. Action
35. Use custom actions to query the knowledge base
35
BUILDING A BOT
entities:
attribute: headquarter
bank: N26
schema:
schema[“bank”][“key_attribute”] =
“name”
query:
match
$bank isa bank,
has name ‘N26’,
has headquarter $a;
get $a;
result: “Berlin”
response:
“N26 has value ‘Berlin’ for
attribute ‘headquarter’.”
knowledge
base
What is the
headquarter of N26?
Rasa Open Source
1. NLU
2. Core
3. Action
36. Use custom actions to query the knowledge base
36
BUILDING A BOT
response:
“N26 has value ‘Berlin’ for
attribute ‘headquarter’.”
What is the
headquarter of N26?
N26 has value
‘Berlin’ for attribute
‘headquarter’.
Rasa Open Source
1. NLU
2. Core
3. Action
40. 40
● Constructing complex queries is hard – a lot of custom code is needed
● Users tend to refer to entities in different ways (e.g. the last one, it, the plane ticket, etc.), each way is
challenging on its own
● Answers of the bot are not very natural as we need to use templates
Some work is still left to do
REMAINING CHALLENGES
41. Key takeaways
41
● Connecting Rasa Open Source to a knowledge base allows your assistant to answer domain specific
questions
● Grakn can be used as a knowledge base store
● Custom actions allow you to construct queries and query your knowledge base
● Good training data is important to teach the bot when to query the knowledge base and to extract relevant
entities that are needed for constructing the queries
42. Read more on the topic!
42
We have two blog posts on the topic of knowledge bases:
● https://blog.rasa.com/integrating-rasa-with-knowledge-bases/
● https://blog.rasa.com/set-up-a-knowledge-base-to-encode-domain-knowledge-for-rasa/
Code of the example bot can be found here:
https://github.com/RasaHQ/tutorial-knowledge-base
We added the knowledge base feature to Rasa Open Source. It allows you to connect your assistant to any graph
database. Check it out!
https://rasa.com/docs/rasa/core/knowledge-bases/