Rasa Form Categorical Entity

Hi! I’m trying to build a bot which uses a form. In one of the form-slots the bot asks the user for a transportation method. I can successfully extract the correct entity but I want to generalize it.

Example 1: If the users writes “I will fly”, the bot should recognize the entity “fly” and generalize it to “plane”.

Example 2: If the users writes “I will ride my bike”, the bot should recognize the entity “bike” and generalize it to “bicycle”.

What would be the best way to do this?

Thanks!

I think you can write below synonyms snippet to your nlu.md file

Suppose you get entities like “fly”, “go on air” etc when users intention is to go by plane then you can add

synonym:plane

  • fly
  • go on air
  • aeroplane
  • chopper
  • flying
  • above the ground
  • flight

synonym:bicycle

  • bike ride
  • two wheeler
  • scooty
  • scooter
  • sports bike
  • cylce

then in your training messages add formatted messages as shown

below

intent:plane

intent:bicycle

Note: I assume you know how to tag entity to word

[word] (entity name) don’t add space here between [word] and (entity name)

then train your rasa and test I hope it gonna work.

1 Like

Okay, I will try this. My current solution is a synonym-table in the action which compare the similarity between the entity and all the synonyms. And the one with the highest string similarity-score will be set as the new entity. But your way looks better, I will get back to you once I have tried this.

Thanks!

It works very well @WilliamG

1 Like

Hi!

I have a follow up question. The thing is i only have the slot ‘travel_mode’, which should be bicycle, car etc. And I’m guessing you are using a slot for plane another one for bicycle. If i decide to do it your way with multiple slots will the assistant not ask a question to first fill the plane slot and then fill the bicycle slot since I’m using a form? Or is their a way around this?

Thanks

Just worked on the exact same case some days ago. It’s all in the docs

1 Like

Thank you! Extactly what is was looking for!

We usually recommend a single inform intent for situations like thsi and there’s also a shortcut method for synonyms that some people prefer over the separate ## synonym:plane approach:

## intent:inform
- i want to travel by [flight](travel_method:plane)
- i will travel by [chopper](travel_method:plane)
- i want to travel by [sports bike](travel_method:bicycle)
1 Like