Hello, I am new to Rasa. I am just confuse how to create lookup table data. Should it be for entity only or could it also be for attributes? Also, is the table per entity limited to only one column? Then I also want to use my queries in Grakn here in Rasa, however I don’t know how to do that. Or should I say, I am overwhelmed with the codes for graph_database.py in the documentation available. Thank you.
You can create lookup table data for any entity (e.g. entities and/or attributes in your knowledge base). You can check the documentation on lookup tables for more details.
We recently added Knowledge Base Actions to Rasa. It should help you to get started with knowledge bases much quicker.
What exactly are you struggling with in graph_database.py
? How do your queries look like?
Is it necessary that each look-up table file to consist of only one column or can it be more than one column?
About the graph_database.py, I am struggling or confuse how to put my queries in grakn into that file, because I am just basing my work in the documentation available. Is there any tutorials available on how to do that?
A lookup table should contain only one column. Or in other words: A whole line will be considered as an entity.
We don’t have any tutorial on how to adapt the graph_database.py
file. The file should be an example on how to deal with queries. If you want to add a new query, add a new function. For example:
def _get_person_entities(self, limit: int = 5) -> List[Dict[Text, Any]]:
return self._execute_entity_query(
"match $x isa person; get $x"
)[:limit]
We have three helper function in the GraphDatabase
:
-
_execute_entity_query
: Executes a query that returns a list of entities with all their attributes. -
_execute_attribute_query
: Executes a query that returns the value(s) an entity has for a specific attribute. -
_execute_relation_query
: Execute a query that queries for a relation. All attributes of the relation and all entities participating in the relation are part of the result.
You can call any of those functions with your queries. Chose the function depending on the type you are querying for as the result dict will be different.
Thank you for your response. Very much appreciated.
Hi, I saw this codes in the documentation with the filename lookup_tables.py,
def run():
entities = get_entities("person")
people = list(map(lambda x: x["first-name"] + " " + x["last-name"], entities))
people = people + list(map(lambda x: x["first-name"], entities))
write_to_file("lookup_person.txt", set(people))
I just want to know if the first-name and the last-name are columns for person being concatenated? So is it possible that a lookup table file (.txt) can consist of several columns being concatenated into one column? I’m sorry I’m just confused.
My other question is, could it be possible to get multiple entities and attributes in one query in Rasa? Because most of my queries in my current project are like that using grakn.
The knowledge base schema has a node/entity for person. The person node has the attributes first-name, last-name, etc. To construct the lookup table we query for the first and last name of a person. As users may refer to a person by the full name or only by the first name, we want to add both variations to the lookup table. Thus, we (1) concatenate first and last name to get one string that represents the full name and we (2) just take the first name. In both cases we got strings. Lookup tables do not contain any columns. There is one line per entity, e.g. in this case name of a person.
The example method
def _get_person_entities(self, limit: int = 5) -> List[Dict[Text, Any]]:
return self._execute_entity_query(
"match $x isa person; get $x"
)[:limit]
uses the function _execute_entity_query
. This function will give you a list of all entities of type person with all their attributes as dict. E.g. something like
[
{
"first-name": "Max",
"last-name": "Mustermann",
"gender": "m",
...
},
{
"first-name": "John",
"last-name": "Doe",
"gender": "m",
...
}
]
hello thanks for this code.
I’m just trying to query : What is the email address for Guy burns. from the person.csv file.
I tried implementing the code to get person entity. But I ran into this error from rasa run actions.
Executing Graql Query: match $mapping isa entity-type-mapping, has mapping-key 'None', has mapping-value $v;get $v;
127.0.0.1 - - [2019-09-13 12:39:46] "POST /webhook HTTP/1.1" 200 198 0.079876
Executing Graql Query: match $mapping isa entity-type-mapping, has mapping-key 'None', has mapping-value $v;get $v;
127.0.0.1 - - [2019-09-13 12:39:46] "POST /webhook HTTP/1.1" 200 198 0.084229
Executing Graql Query: match $mapping isa entity-type-mapping, has mapping-key 'None', has mapping-value $v;get $v;
also in rasa --debug I am a getting
2019-09-13 13:35:57 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_query_attribute'.
2019-09-13 13:35:57 DEBUG rasa.core.processor - Action 'action_query_attribute' ended with events '['BotUttered(text: Can you please rephrase?, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})']'
2019-09-13 13:35:57 DEBUG rasa.core.processor - Current slot values:
account: None
account_number: None
account_type: None
allowed_residents: None
amount: None
attribute: email
balance: None
bank: None
card: None
card_number: None
category: None
country: None
created_date: None
date: None
email: None
english_customer_service: None
english_mobile_app: None
english_website: None
entity_type: None
execution_date: None
expiry_date: None
free_accounts: None
free_worldwide_withdrawals: None
gender: None
headquarters: None
listed_items: None
mention: None
name: None
name_on_card: None
opening_date: None
person: guy burns
phone_numb[2019-09-13 13:35:57 -0700] [28189] [DEBUG] KeepAlive Timeout. Closing connection.
er: None
reference: None
transaction: None
what should the nlu training data look like? this is mine:
- What is the [gender](attribute) of [Hans Maier](person)?
- What is the email of Jannik Jung?
Hi Tanja, my other question about graph_database.py. what is the use of _get_me_clause?
@jayarbarts It is related to the use case. The bot helps you to explore your bank accounts. Thus, we needed to define the user of the bot. We generated some data and chose Mitchell Gillis as user. So, basically you are Mitchell Gillis when interacting with the bot. This is defined by the self.me = "mitchell.gillis@t-online.de"
. The _get_me_clause
helps us to restrict for example the accounts stored in the knowledge base to the ones that actually belong to Mitchell Gillis. We don’t want to show all accounts, but only the ones that are actually owned by him. Does that clarify things?
@skylacking Your query does not work due to the _get_me_clause
. The bot is not designed to return information about other users (except Mitchell Gillis). If you remove the me_clause
here tutorial-knowledge-base/graph_database.py at master · RasaHQ/tutorial-knowledge-base · GitHub and also remove it from the query itself, it should work. Your training data looks fine. But keep in mind that you will change the behaviour of the bot due to that.
Thank you for your response. Just to be sure, did you mean REMOVE the " get_me_clause " everywhere I see it from the graph Along with every instance: From lines 170, 222, 292, 197, 249 ? def _get_me_clause(self, entity_type: Text) -> Text: “”" Construct the me clause. Needed to only list, for example, accounts that are related to me.
:param entity_type: entity type
:return: me clause as string
"""
clause = ""
# do not add the me clause to a query asking for banks or people as they are
# independent of the accounts related to me
if entity_type not in ["person", "bank"]:
clause = (
f"$person isa person, has email '{self.me}';"
f"$contract(customer: $person, offer: $account, provider: $bank) isa contract;"
)
return clause
@skylacking Depends on what you want to achieve. If you just want to explore the data in general without restricting any query to be related to Mitchell Gillis, remove it. The code is just an example on how to interact with the knowledge base. You can remove or add stuff. Just play around with it and try out different things.
Thanks, Yes, I would like to make any calls from the person.csv file.
I’m having a bit of difficulty understanding, what code I should use, and where to put it. If I wanted Rasa to respond to the query " what is the email address of guy burns?" Along with the training data / that would make those responses work.
Guy burns is a person listed in the person.csv file. The email is an attribute. But Person is an entity_type.
when I remove the _get_me_clause I get the error from rasa run actions:
Executing Graql Query: match $mapping isa entity-type-mapping, has mapping-key 'cards', has mapping-value $v;get $v;
Executing Graql Query: match $mapping isa attribute-mapping, has mapping-key 'email', has mapping-value $v;get $v;
127.0.0.1 - - [2019-09-16 04:05:57] "POST /webhook HTTP/1.1" 200 262 0.252643
@skylacking The log you shared is not an error. It just prints out the queries that are executed. If you have any other question, can you please open a new thread? As your questions are not related to the original topic anymore. Just link me in the question and I’ll help you Thanks.
Hi, how about the mention-mapping table. What does the numbers (0, 1, -1, etc) in mapping-values means? Is it important to have in my knowledge graph to create rasa chatbot?
If someone ask the bot to list banks and the bot answers with
I found the following banks:
- Bank A
- Bank B
- Bank C
The bot would save the bank options, e.g. Bank A
, Bank B
, and Bank C
, into a slot as a list. If the user now ask something like Does the first one offer free accounts?
, the bot needs to know what first one
refers to. For this scenario we need the mention mapping. The mention-mapping maps mentions like “the first one” or “the last one” to an entity in a list. The mapping values, e.g. 0
, 1
, -1
, is the list index in python the mention refers to. So, in the example first one
would be resolved to index 0
. Taking the list we stored in the slot, we can use the index to get to entity Bank A
.