# Problem with synonyms

**URL:** <https://forum.rasa.com/t/problem-with-synonyms/29531>\
**Category:** Getting Started with Rasa\
**Created:** [May 30, 2020, 11:09am UTC](https://forum.rasa.com/t/problem-with-synonyms/29531 "2020-05-30T11:09:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrieleRomeo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/gabrieleromeo/32/9257_2.png) [@GabrieleRomeo](https://forum.rasa.com/u/GabrieleRomeo)\
**Post date:** [May 30, 2020, 11:09am UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/1 "2020-05-30T11:09:22Z")

</div>

Hi all,

I’m new to rasa and I’m trying to define a mapping between departments’ code and words (description) which may refer them.

for example:

```
## synonym:LA014
- Data Management
- DataManagement
- Storage Management

```

Then I defined an intent and I listed all codes with some training data:

```
## intent:find_available
- Can you give me the available for [Data Management](code)?
- [LA014](code)
- ... list of all codes ...

```

Synonym works only if I provide an example in the training data

Since the codes list is quite long and the description length varies greatly how can I extract entities codes without specifying each of them in the training data?

Thanks

---

<div class="post-metadata">

**Author:** ![zezutom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zezutom/32/6447_2.png) [@zezutom](https://forum.rasa.com/u/zezutom)\
**Post date:** [May 31, 2020, 5:59pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/2 "2020-05-31T17:59:27Z")

</div>

Hi Gabriel, have you added [EntitySynonymMapper](https://rasa.com/docs/rasa/nlu/components/#entitysynonymmapper) to your pipeline?

---

<div class="post-metadata">

**Author:** ![GabrieleRomeo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/gabrieleromeo/32/9257_2.png) [@GabrieleRomeo](https://forum.rasa.com/u/GabrieleRomeo)\
**Post date:** [June 1, 2020, 12:44pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/3 "2020-06-01T12:44:37Z")

</div>

Hi @zezutom,

Thanks for your reply.

Yes, of course. This is my pipeline:

```
pipeline:
  - name: WhitespaceTokenizer
    case_sensitive: False
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: "char_wb"
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
```

---

<div class="post-metadata">

**Author:** ![zezutom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zezutom/32/6447_2.png) [@zezutom](https://forum.rasa.com/u/zezutom)\
**Post date:** [June 1, 2020, 8:25pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/4 "2020-06-01T20:25:59Z")

</div>

hi @GabrieleRomeo, okay, I’ve played with your example for a bit… I defined the pipeline in the same way you did, except I added “CRFEntityExtractor” in front of the synonym mapper:

```
- name: CRFEntityExtractor
- name: EntitySynonymMapper

```

And in my _nlu.md_ I’ve added:

```
## intent:find_available
- Can you give me the available for [Data Management](code)?
- Data for [LA014](code)
- Can I get input for [LA014](code)?

## synonym:LA014
- Data Management
- DataManagement

```

Then, both _Data Management_ and _DataManagement_ get correctly interpreted as the code _LA014_

---

<div class="post-metadata">

**Author:** ![GabrieleRomeo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/gabrieleromeo/32/9257_2.png) [@GabrieleRomeo](https://forum.rasa.com/u/GabrieleRomeo)\
**Post date:** [June 4, 2020, 7:03pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/5 "2020-06-04T19:03:27Z")

</div>

Hi @zezutom

It works

Thank you 😉

---

<div class="post-metadata">

**Author:** ![zezutom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zezutom/32/6447_2.png) [@zezutom](https://forum.rasa.com/u/zezutom)\
**Post date:** [June 5, 2020, 7:25pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/6 "2020-06-05T19:25:17Z")

</div>

Cool, glad I could help 🙂

---

<div class="post-metadata">

**Author:** ![GabrieleRomeo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/gabrieleromeo/32/9257_2.png) [@GabrieleRomeo](https://forum.rasa.com/u/GabrieleRomeo)\
**Post date:** [June 9, 2020, 1:31pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/7 "2020-06-09T13:31:03Z")

</div>

Hi @zezutom

I’ve encountered another strange behaviour with code extraction

If a synonym list contains **just one word** the code extraction fails and the system returns the actual name (i.e `DataManagement` and not `LA014`)

```
## synonym:LA014
- DataManagement

```

is there a minimum threshold for synonyms in Rasa?

---

<div class="post-metadata">

**Author:** ![zezutom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zezutom/32/6447_2.png) [@zezutom](https://forum.rasa.com/u/zezutom)\
**Post date:** [June 10, 2020, 6:21am UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/8 "2020-06-10T06:21:27Z")

</div>

Hi @GabrieleRomeo, I don’t think there is a minimum threshold for synonyms. Have you tried using them inline?

```
- Can you give me the available for [DataManagement]{"entity": "code", "value": "LA014")

```

I know it’s more repetitive, but it’s worth a try.

---

<div class="post-metadata">

**Author:** ![GabrieleRomeo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/gabrieleromeo/32/9257_2.png) [@GabrieleRomeo](https://forum.rasa.com/u/GabrieleRomeo)\
**Post date:** [June 25, 2020, 1:30pm UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/9 "2020-06-25T13:30:56Z")

</div>

Hi @zezutom

thanks for your suggestion.

I have another problem now

As I said, I have a long list of department names and descriptions which are use to fill a specific form. For example:

```
## synonym:N0280
- Disaster Recovery
- DR

## synonym:LA014
- Data Management
- DataManagement

```

And the intent description is as follow:

```
## intent:find_available
- Can you give me the available for [Data Management](code)?
- Can you give me the available for [DR](code)?
- Data for [LA014](code)
- Data for [N0280](code)
- Can I get input for [LA014](code)?
- Can I get input for [N0280](code)?

```

This work well however I need to define another intent which (in some cases) contains entities (synonyms) with the same value as before. For example:

```
## synonym:1
  - DR

## intent:find_status
- Can you give me the status of the [DR](informative_system) system?
- Can you give me the status of system number [1](informative_system) ?

```

This fact creates name collisions and entity extraction turns out to be mistaken ( **informative\_system** is mapped to **N0280** instead of **1** )

How can I structure my NLU so that different intents refer to different synonyms?

Thanks

---

<div class="post-metadata">

**Author:** ![zezutom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zezutom/32/6447_2.png) [@zezutom](https://forum.rasa.com/u/zezutom)\
**Post date:** [June 29, 2020, 5:12am UTC](https://forum.rasa.com/t/problem-with-synonyms/29531/10 "2020-06-29T05:12:41Z")

</div>

Hi @GabrieleRomeo, Ok, are you sure the two intents (find\_available, find\_status) are correctly distinguished from each other? If not, I would try to add more examples of find\_status.

Another option that comes to my mind is splitting the model into two separate models. One for departments and the other one for informative systems. In that case you’d have two different Rasa agents on the backend, each handling a dedicated model - see [my blog post](https://www.langnerd.com/first-steps-with-rasa-for-busy-developers/#multiple-models) on how to do it.

Whether you can split the model or not also depends on your UI. For example, does the user identify the domain they want to ask about (departments vs informative systems) before they interact with the chatbot?
