question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Impossible to pass end to end test when the same entity is extracted by different classifiers

See original GitHub issue

Rasa Open Source version

2.8.7

Rasa SDK version

No response

Rasa X version

No response

Python version

3.8

What operating system are you using?

Linux

What happened?

rasa test will fail when the same entity is extracted by different classifiers.

Steps to reproduce:

  1. Include this in config.yml
  - name: RegexEntityExtractor
  - name: DIETClassifier
    epochs: 100
    constrain_similarities: true
    entity_recognition: true
  1. Define this lookup table:
nlu:
- lookup: country
  examples: |
    - Albania
    - Algeria
    - Andorra
    - Angola
    - Antigua and Barbuda
    - Argentina
    - Armenia
    - Australia
    - Austria
    - Azerbaijan
    - Germany

i.e. list of countries

  1. Define an intent that only has this:
- intent: inform
  examples: |
    - [Germany](country)
    - [Argentina](country)
  1. Write a test story like this:
stories:
  - story: identical to training NLU example
    steps:
    - user: |
        [Germany](country)
      intent: inform
  1. Run rasa test --fail-on-prediction-errors

Command / Request

No response

Relevant log output

2021-10-01 08:45:28 INFO     rasa.core.test  - Evaluating 1 stories
Progress:
  0%|                                                                                                                                                   | 0/1 [00:00<?, ?it/s]2021-10-01 08:45:28 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-10-01 08:45:28 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
/opt/venv/lib/python3.8/site-packages/rasa/shared/utils/io.py:97: UserWarning: Parsing of message: 'Germany' lead to overlapping entities: Germany of type country extracted by RegexEntityExtractor overlaps with Germany of type country extracted by DIETClassifier. This can lead to unintended filling of slots. Please refer to the documentation section on entity extractors and entities getting extracted multiple times:https://rasa.com/docs/rasa/components#entity-extractors
2021-10-01 08:45:28 DEBUG    rasa.core.processor  - Received user message 'Germany' with intent '{'id': 113713248080627725, 'name': 'inform', 'confidence': 0.9980354905128479}' and entities '[{'entity': 'country', 'start': 0, 'end': 7, 'value': 'Germany', 'extractor': 'RegexEntityExtractor'}, {'entity': 'country', 'start': 0, 'end': 7, 'confidence_entity': 0.9988456964492798, 'value': 'Germany', 'extractor': 'DIETClassifier'}]'
  0%|                                                                                                                                                   | 0/1 [00:00<?, ?it/s]
2021-10-01 08:45:28 DEBUG    rasa.__main__  - Failed to run CLI command due to an exception.
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/rasa/__main__.py", line 117, in main
    cmdline_arguments.func(cmdline_arguments)
  File "/opt/venv/lib/python3.8/site-packages/rasa/cli/test.py", line 260, in test
    run_core_test(args)
  File "/opt/venv/lib/python3.8/site-packages/rasa/cli/test.py", line 133, in run_core_test
    test_core(
  File "/opt/venv/lib/python3.8/site-packages/rasa/model_testing.py", line 182, in test_core
    rasa.utils.common.run_in_loop(
  File "/opt/venv/lib/python3.8/site-packages/rasa/utils/common.py", line 296, in run_in_loop
    result = loop.run_until_complete(f)
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/opt/venv/lib/python3.8/site-packages/rasa/core/test.py", line 1041, in test
    story_evaluation, _, entity_results = await _collect_story_predictions(
  File "/opt/venv/lib/python3.8/site-packages/rasa/core/test.py", line 916, in _collect_story_predictions
    ) = await _predict_tracker_actions(
  File "/opt/venv/lib/python3.8/site-packages/rasa/core/test.py", line 822, in _predict_tracker_actions
    user_uttered_result = _collect_user_uttered_predictions(
  File "/opt/venv/lib/python3.8/site-packages/rasa/core/test.py", line 547, in _collect_user_uttered_predictions
    raise WrongPredictionException(
rasa.core.test.WrongPredictionException: NLU model predicted a wrong intent. Failed Story: 

version: "2.0"
stories:
- story: identical to training NLU example
  steps:
  - intent: inform
    entities:
    - country: Germany
    - country: Germany

WrongPredictionException: NLU model predicted a wrong intent. Failed Story: 

version: "2.0"
stories:
- story: identical to training NLU example
  steps:
  - intent: inform
    entities:
    - country: Germany
    - country: Germany

Definition of done

  • Issue reproduced
  • Solution identified
  • Bug fixed
  • @hsm207 notified

@JEM-Mosig is reviewer

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
samsucikcommented, Oct 14, 2021

@hsm207 I’ve created a fix in #9875. It addresses the issue with duplicated or differently ordered entity predictions. Note that it does not touch the actual attributes of a Message (i.e. the prediction data attached to it by entity extractors). It only eliminates the error that was previously raised without good reason. It’ll be the subject of a future issue to handle duplicated/overlapping entity predictions and to change the status quo where one has to include some training examples in order for RegexEntityExtractor to kick in.

@JEM-Mosig review of the code should be quick but I’d like you to also challenge the overall approach I took 😉

1reaction
samsucikcommented, Oct 14, 2021

I’ve been able to reproduce this issue and it’s worse than I thought 🙂

It boils down to us comparing expected and predicted entities in a naive and harsh way. It even insists on the entities being extracted in the same order as listed in the training story, which can get you into real trouble:

Imagine you have RegexEntityExtractor that extracts countries, DIETClassifier that extracts job names, and a test story like this:

  - story: simple
    steps:
    - intent: inform
      user: |
        I'm a [researcher](job_name) from [Germany](country)

Now, if you have RegexEntityExtractor before DIETClassifier in your pipeline, the model will fail on the test story. Just because country is extracted before job_name but the test story expects the extracted entities to be in the other order (as they occur in the user utterance – first job_name, then country).

The other thing is that the code that compares expected and predicted entities ignores roles and groups (which feels wrong).

This being said, I’ll focus on fixing the bug reported above and create followup issues for the other things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Impossible to pass end to end test when the same entity is ...
rasa test will fail when the same entity is extracted by different classifiers. Steps to reproduce: Include this in config.yml. - name: ...
Read more >
Just Say No to More End-to-End Tests - Google Testing Blog
Unit tests do have one major disadvantage: even if the units work well in isolation, you do not know if they work well...
Read more >
A Frustratingly Easy Approach for Entity and Relation Extraction
End -to-end relation extraction aims to identify named entities and extract relations between them. Most recent work models these two.
Read more >
Named Entity Recognition and Classification for Entity Extraction
Learn to use entity resolution to build context within unstructured text data around points of interest, such as people, places and organizations.
Read more >
Pipelines - Hugging Face
The pipeline abstraction is a wrapper around all the other available pipelines. It is instantiated as any other pipeline but can provide additional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found