• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Integrating Rasa with a knowledge base to encode domain knowledge and resolve entities

Tutorial Knowledge Base

This repository contains the code that is referred to in the tutorial Integrating Rasa with knowledge bases.

UPDATE: We added Knowledge Base Actions to Rasa. Knowledge Base Actions help you to connect your knowledge base to Rasa more quickly. Try it out and share your feedback on the Rasa Community Forum.

Outline

  1. Requirements
  2. Chat with the Bot
  3. Limitations of Knowledge Bases
  4. Feedback

Requirements

Install requirements:

pip install -r requirements.txt

Setting up the Graph Database

Our knowledge base is represented by a graph database. In this repository Grakn is used as a graph database. However, you can also use any other graph database or use an alternative (see below).

In order to use this code example, you need to install Grakn. To be able to run this bot, you need version 1.5.7. Please check the installation instruction of Grakn in order to install it. Once you installed Grakn, you need to start the Grakn server by executing

grakn server start

You can stop the server by running grakn server stop.

In order to get some data into the graph database you need to execute the following steps:

  1. Create the schema by executing
    grakn console --keyspace banking --file <absolute-path-to-knowledge_base/schema.gql>
    This will create a keyspace banking in your Grakn graph database with the schema defined in knowledge_base/schema.gql.
  2. Load data into your schema by running
    python knowledge_base/migrate.py
    Grakn recommends you to write a migrate.py script (see migration-python) to load data from csv files into your graph database. Our migration script loads the data located in knowledge_base/data into the keyspace banking.

The graph database is set up and ready to be used.

Alternative to Graph Databases

If you just have a small knowledge base and you don't want to install and set up a graph database, such as Grakn, you can also encode your domain knowledge in a data structure, such as a python dictionary. You can find an example in the file graph_database.py. The file contains an implementation that uses a graph database (class GraphDatabase) and an implementation that simply uses a python dictionary as domain knowledge (class InMemoryGraph). If you want to use the InMemoryGraph instead of the GraphDatabase in the bot, you need to exchange the initialization of the graph database in actions.py. But be aware of the fact, that the InMemoryGraph does not cover the same knowledge as the GraphDatabase. It just knows about banks and their attributes.

Chat with the Bot

Make sure you installed all requirements and your grakn server is running.

If you want to chat with the bot, execute the following steps:

  1. Train the bot using rasa train.
  2. Start the action server with rasa run actions in a separate terminal.
  3. Chat with the bot on the command line by executing rasa shell.

If you want to see what slots are set and how confident the bot is in predicting the next action, you should run the bot in debug mode: rasa shell --debug.

Here are some example questions you can ask the bot:

  • โ€œWhat are my bank options?โ€
  • โ€œWhat is the headquarter of the first bank?โ€
  • โ€œWhat accounts do I have?โ€
  • โ€œWhat is my balance on the second account?โ€
  • โ€œWhat are my recent transactions?โ€

Limitations of Knowledge Bases

Before we look at the limitations of knowledge bases, let's first take a look, in what way an entity can be referenced:

Type Example Description
direct mention Rasa is located in Berlin. An entity was mentioned by its name in the text, such as Rasa or Berlin.
ordinal mention Where is the headquarters of the third company? The user was confronted to a list of entities. The user refers to an entity of that list by its position.
mention by synonym What's my balance? vs. How much cash do I have? The user refers to the same entity with different names.
ambiguous mention I want to transfer money to John? The bot can find multiple entities with the referenced name (e.g. John). The entity needs to be specified.
mention by pronoun Rasa is located in Berlin. It is an open source company. Reference to a previous mentioned entity by its pronoun, such as it.
mention by hypernyms & hyponyms Here are some recent transactions: Raynair 99.95โ‚ฌ, Spotify 9.99โ‚ฌ. Which do you want to dispute? The user can answer many things, such as "the subscription", or "the plane ticket". The bot needs to understand what entity the user refers to by those answers.
mention by attribute(s) Where is the headquarters of the open source company that builds chatbots? Find an entity in the knowledge base that fits the mentioned criteria.
mention by attribute comparison Your last transactions: Amazon 99.95โ‚ฌ, Netflix 4.99โ‚ฌ. Which do you want to dispute? If the user says, for example, "the bigger one", the bot needs to first resolve the comparison before he can detect the entity the user is referring to.

The bot in this repo can handle some but not all of the cases above. Let's go over them one by one and take a closer look at what is possible and what are current limitations:

direct mention

The direct mention is handled by the NER of Rasa. No knowledge base is needed to recognize an entity in a text. However, your knowledge base can be used to create lookup tables, that can then be used to improve the NER.

mention by pronoun

If an entity is referred to by its pronoun, the bot cannot detect it. Let's look at the example "My sister has a dog. She loves him." In the example "him" is referring to "dog" and "she" refers to "sister". However, for the bot it is hard to figure that out. Typically, coreference resolution models are used to solve this kind of mention. Here are some links to repositories:

ordinal mention

With the smart use of slots, your bot is able to resolve an ordinal mention to its real-world entity (see code snippet). As soon as multiple entities from the knowledge base are listed, the bot stores those in a specific slot (listed_items). The recognized ordinal mention needs to be mapped to an index and the entity can be picked up from the list of entities using the identified index.

mention by attribute(s)

Theoretically, your bot can find any entity by its attributes in its knowledge base. However, if you requested, for example, to name the transaction you did last month to Max, multiple nodes and relations in your graph database are involved. The query to fetch the requested entity becomes quite complex. The bot is currently not able to handle such complex requests. But, if you simply ask for a specific entity that just involves a node and its attributes in the graph database, the bot can answer your request.

ambiguous mention

Your bot should be able to help you resolve an ambiguous mention. For example, if you want to transfer money to John, but you have transferred money to John Doe and John Mustermann in the past, the bot needs you to confirm which exact John you meant. In order to archive that, the bot looks up the ambiguous entity in the knowledge base. If multiple entities are found, you will be confronted with the list of entities. You can then specify the entity you meant by, for example, using an ordinal mention.

mention by synonym

The bot uses mapping tables in the knowledge base to resolve synonyms, e.g. mapping cash and balance to the same entity. However, this is limited to the names you defined in those mapping tables.

mention by hypernyms & hyponyms

The bot cannot handle mentions by hypernyms & hyponyms at the moment. Knowledge about, for example, Rynair selling plane tickets is missing. If such knowledge can be encoded in your knowledge base, more complex queries could be used to retrieve the information of interest.

mention by attribute comparison

If you say something like "Please, dispute the biggest of the just listed transactions.", the bot first needs to compare multiple entities by certain attributes before it can pick the entity of interest. As the bot currently cannot perform a comparison, this kind of mention cannot be handled by the bot at the moment.

Apart from the limitation already listed per mention type, the bot has some further limitations:

  • Comparing entities is still limited: The bot is not able to detect the comparison operator and can therefore not compare multiple entities in a proper way. For example, if the bot listed your accounts and you are asking "On what account do I currently have more money?". The bot needs to recognize not only that you are interested in the balance of the listed accounts, but also that "more money" means that the accounts need to be compared by their balance and you only want to know about the account with the highest balance. So far, the bot just lists the requested attribute for all entities and you have to "compare" yourself.

  • Executing complex queries: The bot tries to handle requests in a generic way. However, some user requests, such as "How much money did I transfer to Max from my N26 account in the last month.", require complex queries. The example request involves the nodes "person", "bank", and "account" as well as the relations "transaction" and "contract". As those requests are very specific and the resulting query is complex, the bot needs to handle them separately. However, this special treatment is currently not implemented, so that the bot is not able to answer complex queries that involve multiple nodes and relations.

Feedback

If you have any questions about the tutorial or this repository, feel free to share them on Rasa Community Forum.

More Repositories

1

rasa

๐Ÿ’ฌ Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
Python
18,586
star
2

rasa_core

Rasa Core is now part of the Rasa repo: An open source machine learning framework to automate text-and voice-based conversations
Python
2,329
star
3

rasa-demo

๐Ÿฏ Sara - the Rasa Demo Bot: An example of a contextual AI assistant built with the open source Rasa Stack
Python
929
star
4

financial-demo

A demo for a financial services bot
Python
308
star
5

rasalit

Visualizations and helpers to improve and debug machine learning models for Rasa Open Source
Jupyter Notebook
305
star
6

rasa-sdk

SDK for the development of custom actions for Rasa
Python
291
star
7

NLU-training-data

Crowd sourced training data for Rasa NLU models
Python
196
star
8

rasa-nlu-examples

This repository contains examples of custom components for educational purposes.
Python
190
star
9

helpdesk-assistant

Python
185
star
10

rasa-voice-interface

๐ŸŽค A simple web interface for building voice assistants with Rasa
Vue
168
star
11

algorithm-whiteboard-resources

this is where we share notebooks/projects used in your youtube channel
Jupyter Notebook
146
star
12

rasa-masterclass

Data and code files for specific Rasa Masterclass episodes
Jupyter Notebook
139
star
13

medicare_locator

๐ŸฅMedicare Locator - Open source starter pack for developers to build contextual chatbots and AI assistants in healthcare
Python
138
star
14

rasa-x-helm

Rasa Enterprise Helm chart for deploying on Kubernetes (K8s) and OpenShift.
Go
77
star
15

paraphraser

Tool to generate paraphrases of sentences in many languages.
Python
74
star
16

rasa-x-demo

Demo app for running a bot with Rasa Enterprise
Python
69
star
17

conversational-ai-workshop-18

Example showing generalisation
Jupyter Notebook
69
star
18

DIET-paper

Source code to reproduce results of our paper "DIET: Lightweight Language Understanding for Dialogue Systems"
Python
60
star
19

rasa-for-beginners

Rasa for Beginners
Python
57
star
20

STAR

Python
55
star
21

rasa_lookup_demo

Improving entity extraction from text using the lookup table feature in rasa_nlu
Python
52
star
22

tutorial-tf-pipeline

Handling multiple intents using Rasa NLU Tensorflow pipeline
51
star
23

rasa-2.x-form-examples

This repository contains a few simple projects with forms.
Python
48
star
24

kb-demo-chatgpt

Python
46
star
25

nlu-hyperopt

Find the best hyperparameters for your Rasa NLU model
Python
46
star
26

rasa-calm-demo

Python
43
star
27

carbon-bot

Python
42
star
28

breakoutbot

A text based adventure game built with Rasa.
Python
41
star
29

TED-paper

Python
39
star
30

rasa-action-server-gha

A GitHub Action that simplifies using Rasa Actions and helps to prepare a Docker image with custom actions.
Dockerfile
39
star
31

retail-demo

Rasa's retail starter pack
Python
38
star
32

pokedex-demo

Rasa Demo for a digital assistant for pokemon
Python
35
star
33

tutorial-rasa-google-assistant

This repository contains the code of the tutorial 'Going beyond โ€˜Hey Googleโ€™: building a Rasa-powered Google Assistant'
Python
35
star
34

rasa-train-test-gha

A GitHub action to run easily rasa train and rasa test in the CIs.
Python
34
star
35

taipo

Experiments for data quality in Rasa.
Python
34
star
36

rasa-workshop-pydata-berlin

Jupyter Notebook
33
star
37

helm-charts

Helm charts for Rasa products
Smarty
32
star
38

conversational-ai-course-3.x

Containers code for the learning center course.
Python
29
star
39

rasa-workshop

A repository which contains the material for Rasa workshops
Jupyter Notebook
27
star
40

rasa-3.x-form-examples

This repository contains a few simple projects with forms.
Python
27
star
41

insurance-demo

Building a bot to handle general tasks for insurance.
Python
22
star
42

wellness-check-bot

A simple Rasa assistant that uses forms to conduct a daily health survey
Python
21
star
43

tutorial-rasa-alexa

Sample code for a Rasa virtual assistant with an Alexa connector.
Python
19
star
44

workshop-rasax

Python
18
star
45

rasactl

rasactl deploys Rasa X / Enterprise on your local or remote Kubernetes cluster and manages Rasa X / Enterprise deployments.
Go
15
star
46

tod-in-context-learning

Python
15
star
47

rasa-action-examples

A place to host demos for custom actions.
Python
14
star
48

forms_bot

bot which uses forms to do hotel and restaurant booking task
Python
13
star
49

how-to-rasa

Python
13
star
50

live-gdrive-demo

Starter pack for the Rasa Stack
Python
13
star
51

starter-pack-intentless-policy

Python
13
star
52

REI

Rasa Ephermal Installer
Shell
12
star
53

rasa-workshop-pydata-dc

This repository contains the code of the Rasa workshop at PyData DC 2018
Jupyter Notebook
12
star
54

rasa-workshop-pydata-nyc

This repository contains the code of the Rasa workshop at PyData NYC 2018
Jupyter Notebook
12
star
55

awesome-rasa

A list of Rasa resources curated by Rasa and the community.
11
star
56

rasa-custom-spelling-featurizer

This repo contains a tutorial on how to write your own spelling featurizer.
Python
11
star
57

tutorial-migrating-dialogflow-to-rasa

This repository contains the code of the assistant used to demonstrate the migration from DialogFlow to Rasa
Python
11
star
58

spaCy-integration-demo

Python
10
star
59

rasa-3.x-component-examples

A basic Rasa project with Custom Components
Python
10
star
60

livestream-tf-pipeline

Code of the Rasa Twitch livestream on building bots with multi-intents using Rasa NLU TensorFlow pipeline
Python
9
star
61

rasa_stack

A PyPI package which includes Rasa Core and Rasa NLU
Python
8
star
62

rasa-examples

Repository with small Rasa examples.
Python
8
star
63

rasa-custom-fasttext

This repo contains a tutorial on how to make a fasttext featurizer
Python
5
star
64

nlu-and-jupyter

Demonstration of Rasa NLU from Jupyter Lab
Jupyter Notebook
5
star
65

stroopbot

A demonstration of a custom action
Python
4
star
66

rasa-ted-demo

This repo contains a project shows why TED works.
Python
4
star
67

botsociety-py-client

A python client to connect to the Botsociety API
Python
4
star
68

OpenAI_func_calling

4
star
69

workshop-adv-actions

Java
3
star
70

pizza-rule-demo

A demo of rules, stories, actions and forms
Python
3
star
71

benchmark-lookup-ee

This repository contains code to benchmark lookup table entity extraction.
Python
3
star
72

rasa-custom-printer-component

part of a lesson on how to build custom components
Python
3
star
73

multiwoz-paper

Code to analyse MultiWOz and Google Taskmaster-1 dialogue datasets
Python
3
star
74

rei-vm-terraform-example

Example terraform code for creating a VM that is ready for REI installation
Shell
3
star
75

deployment-workshop-bot-2

Python
2
star
76

HandsOn_with_rasa

Python
2
star
77

frontend-coding-test

JavaScript
2
star
78

Hands-on-with-Rasa-2

Python
2
star
79

time-taken-experiment

Some experiments that track how long training might take.
Python
2
star
80

contributors

2
star
81

deploy-tags

TypeScript
2
star
82

deployment-workshop-bot-1

Python
2
star
83

rasa-nlu-eval-compare-gha

A GitHub Action that compares results of multiple Rasa NLU evaluation results and writes the output to an HTML table
Python
2
star
84

calm-guide-code

Python
2
star
85

golastmile.github.io

1
star
86

test-bot

Basic bot used as part of testing Rasa X
Python
1
star
87

rasa-2.0-user-tests-rules

Task for the user tests for rules as part of Rasa Open Source 2.0.
Python
1
star
88

frontend-test

Example Entity annotator (Mock repository)
JavaScript
1
star
89

workshop-rasax-short

Short version of Rasa X workshop
Python
1
star
90

financial-spaces-bot

Python
1
star
91

bart-examples

Repo with example bots on different branches
1
star
92

chatbotsummit-workshop

Python
1
star
93

deployment-workshop-bot-3

Bot for the exam project of the deployment workshop
Python
1
star
94

csm-onboarding

Repo to manage gitpod instances for CSM onboarding
Python
1
star
95

homebrew-rasactl

Homebrew Formula for rasactl
Ruby
1
star
96

webkit-voice-demo

This is a project that shows how to integrate webkit voice with Rasa.
HTML
1
star
97

tourist-agency-calm

Tourist agency example with CALM approach
Python
1
star