diff --git a/changelog/5788.misc.rst b/changelog/5788.misc.rst new file mode 100644 index 000000000000..a1df43e35e51 --- /dev/null +++ b/changelog/5788.misc.rst @@ -0,0 +1 @@ +Don't set roles and groups to ``O`` (nothing found) when constructing entities from model predictions. \ No newline at end of file diff --git a/rasa/nlu/extractors/extractor.py b/rasa/nlu/extractors/extractor.py index 983fd99e6669..b1f4a74ee89e 100644 --- a/rasa/nlu/extractors/extractor.py +++ b/rasa/nlu/extractors/extractor.py @@ -507,13 +507,13 @@ def _create_new_entity( ENTITY_ATTRIBUTE_TYPE ][idx] - if ENTITY_ATTRIBUTE_ROLE in tag_names: + if ENTITY_ATTRIBUTE_ROLE in tag_names and role_tag != NO_ENTITY_TAG: entity[ENTITY_ATTRIBUTE_ROLE] = role_tag if confidences is not None: entity[ENTITY_ATTRIBUTE_CONFIDENCE_ROLE] = confidences[ ENTITY_ATTRIBUTE_ROLE ][idx] - if ENTITY_ATTRIBUTE_GROUP in tag_names: + if ENTITY_ATTRIBUTE_GROUP in tag_names and group_tag != NO_ENTITY_TAG: entity[ENTITY_ATTRIBUTE_GROUP] = group_tag if confidences is not None: entity[ENTITY_ATTRIBUTE_CONFIDENCE_GROUP] = confidences[ diff --git a/tests/nlu/extractors/test_extractor.py b/tests/nlu/extractors/test_extractor.py index 119f569b4b56..f2f2baaf7d7e 100644 --- a/tests/nlu/extractors/test_extractor.py +++ b/tests/nlu/extractors/test_extractor.py @@ -308,6 +308,12 @@ def test_clean_up_entities( }, ], ), + ( + "Amsterdam", + {"entity": ["city"], "role": ["O"], "group": ["O"]}, + None, + [{"entity": "city", "start": 0, "end": 9, "value": "Amsterdam"}], + ), ], ) def test_convert_tags_to_entities(