Rasa 2 Lookup Table file syntax

Hello, what is the correct syntax to add a Lookup Table file to nlu.yml in Rasa 2 ?

For example, in Rasa 1 the syntax is the following:

lookup:person

data/lookup_tables/person.txt

3 Likes

I have same question

Hi @t3ch9 and @chriswangweb! You should just include the lookup table file in your data folder (the one you specify in the --data argument). If you like, you can create a sub-directory for lookup tables like here. Note that the lookup table file needs to be in the new yaml format.

2 Likes

hey @fkoerner …i wanted to do a lookup table for extracting a name entity …how can we do that…if we have a name of all possible names written in one file and want to lookup on that file so that when a user enters a name then rasa will take that slot as a person name

Hi Felicia,

I checked the repository you mentioned, but the lookup table file in this demo is in txt format. I tried to use a yaml format lookup table but here is what I got:

YamlValidationException: Failed to validate 'data\nlu.yml'. Please make sure the file is correct and all mandatory parameters are specified. Here are the errors found during validation:
  in data\nlu.yml:109:
      Key 'lookup' was not defined. Path: '/nlu/10'
  in data\nlu.yml:109:
      Key 'files' was not defined. Path: '/nlu/10'

I also found someone else having this issue in the forum. Any suggestions? Thanks in advance :smiley:

Hi @Esther-Guo, welcome to the forum!

Could you share your nlu.yml file? I’m guessing you’ve already seen the example we have in our docs?

Can you also direct me to the other person with this issue? Thank you :slight_smile:

Thx for the quick reply, Felicia!

Here is my nlu.yml (6.2 KB) and my lookup table filestory_keyword.yml (4.4 KB) (Training data is in Chinese)

The other lost guys are here :smile:

Thanks again!

That’s very odd, the nlu.yml file looks just fine, and I wasn’t able to reproduce your error. Could you let me know what version you’re on?

Hmm that’s weird…

I’m on the following version:

Rasa Version     : 2.2.2
Rasa SDK Version : 2.2.0
Rasa X Version   : None
Python Version   : 3.7.9

Is it parsing the rest of the file correctly? As in, when you run train do you get something like:

2021-01-10 10:30:27 INFO     rasa.shared.nlu.training_data.training_data  - Number of intent examples: 86 (10 distinct intents)
2021-01-10 10:30:27 INFO     rasa.shared.nlu.training_data.training_data  -   Found intents: 'inform_keyword', 'bot_challenge', 'deny', 'inform', 'mood_unhappy', 'greet', 'goodbye', 'ask_story', 'mood_great', 'affirm'
2021-01-10 10:30:27 INFO     rasa.shared.nlu.training_data.training_data  - Number of response examples: 0 (0 distinct responses)
2021-01-10 10:30:27 INFO     rasa.shared.nlu.training_data.training_data  - Number of entity examples: 18 (2 distinct entities)
2021-01-10 10:30:27 INFO     rasa.shared.nlu.training_data.training_data  -   Found entity types: 'story_genre', 'story_keyword'

Oh my apology! The nlu file I uploaded is the original one before I move the lookup table into a file. You might need to comment the data in the nlu.yml file and uncomment these two lines:

files: |
- lookups\story_keyword.yml

Sorry for the misleading file and here is the one that really went wrong nlu.yml (6.7 KB)

Ah okay! In that case you no longer need to point to the file in nlu.yml.

Instead, you can just include the yaml file in the same directory as your nlu.yml (default is data) and rasa should pick it up. It will also look inside subdirectories of data recursively. So for example:

data/lookups/story_keyword.yml
data/nlu.yml

I think this recursive sub-directory searching may be a bit confusing. It was meant to make things easier, but internally we’ve had some discussion about how to make it clearer. If you have an idea or preference for how we can improve this, (for example: better docs, or changing the way we look for files), please let me know, or feel free to make an issue on github!

1 Like

Awesome! Thank you so much :hugs:

During training, I got the following warning:

UserWarning: Issue found while processing ‘data\nlu.yml’: ‘lookup: story_keyword’ doesn’t have any examples. It will be skipped.

I’m thinking the warning might be a bit confusing cuz it actually finds the lookup table outside the nlu.yml file under data directory.

Again, thanks for your help!!

1 Like

You’re welcome! Glad it’s working :slight_smile:

Actually, that warning looks like you’re still listing the lookup in nlu.yml, is that possible?

Hi, I have looked into the link you posted and have a question regarding that. You referred to the lookup table in the nlu.yml with a .txt file, but you write lookup table in .yml, is that a typo? I tried the way you did but returned me issue.

Hi @jhzape, I’m not sure which link you’re referring to, can you let me know?

As for your particular setup, you no longer need to point to the lookup files in the nlu.yml file. You should remove the lines:

 - lookup: first_name
  files: |
  - data/lookups/first_name.yml
 - lookup: last_name
  files: |
  - data/lookups/first_name.yml

By default, rasa will look for lookups in the directory (and any sub-directories) in data. This directory also contains your nlu.yml file. Since your lookup files are already in data, you should be good to go!

Let me know if you have any other issues with this

1 Like

Thank you for your reply, and here is the Line. Now I know why you commented out in nlu.yml. However, from my case, I am not sure if rasa really looks up the table, since when I typed one of the examples in lookup tables, the entity is not extracted. Is there another way to know if the lookup function works?

Gotcha, yes, this is why that line is commented out.

You might be having trouble extracting the entities from the lookup table because you need a few training examples that include the entities. So, for example, if your lookup included food entities, like apples and bananas, you should have some nlu examples like:

 - intent: inform_food
   examples: |
        - I love to eat [apples](food)
        - [bananas](food) are my favourite!

If you’re still stuck, please share your nlu.yml file.

1 Like

Really appreciate your help. The issue is fixed and never thought the lookup table can be so tricky.

1 Like

Glad it worked @jhzape. If you have any suggestions for how the docs can be made clearer, please feel free to create an issue on github, or let us know here.