Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ted training e2e entities when none are given #8194

Merged
merged 7 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/8194.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix `TEDPolicy` training e2e entities when no entities are present in the stories
but there are entities in the domain.
14 changes: 13 additions & 1 deletion rasa/core/policies/ted_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,26 @@ def _create_label_data(

return label_data, encoded_all_labels

@staticmethod
def _should_extract_entities(
entity_tags: List[List[Dict[Text, List["Features"]]]]
) -> bool:
for turns_tags in entity_tags:
for turn_tags in turns_tags:
# if turn_tags are empty or all entity tag indices are `0`
# it means that all the inputs only contain NO_ENTITY_TAG
if turn_tags and np.any(turn_tags[ENTITY_TAGS][0].features):
return True
return False

def _create_data_for_entities(
self, entity_tags: Optional[List[List[Dict[Text, List["Features"]]]]]
) -> Optional[Data]:
if not self.config[ENTITY_RECOGNITION]:
return

# check that there are real entity tags
if entity_tags and any([any(turn_tags) for turn_tags in entity_tags]):
if entity_tags and self._should_extract_entities(entity_tags):
entity_tags_data, _ = convert_to_data_format(entity_tags)
return entity_tags_data

Expand Down
3 changes: 1 addition & 2 deletions tests/core/policies/test_ted_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
VALUE_RELATIVE_ATTENTION,
MODEL_CONFIDENCE,
COSINE,
INNER,
AUTO,
LINEAR_NORM,
)
Expand Down Expand Up @@ -93,7 +92,7 @@ def test_train_model_checkpointing(self, tmp_path: Path):

def create_policy(
self, featurizer: Optional[TrackerFeaturizer], priority: int
) -> Policy:
) -> TEDPolicy:
return TEDPolicy(featurizer=featurizer, priority=priority)

def test_similarity_type(self, trained_policy: TEDPolicy):
Expand Down