Skip to content

Commit

Permalink
make NLU fallback intent a hardcoded intent name
Browse files Browse the repository at this point in the history
It has to be hardcoded since the TwoStageFallbackPolicy relies on it's name, similar to the out of scope intent name
  • Loading branch information
wochinge committed Jun 12, 2020
1 parent 7cbb5a0 commit f6e942c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
1 change: 0 additions & 1 deletion examples/rules/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pipeline:
- name: EntitySynonymMapper
- name: FallbackClassifier
threshold: 0.5
fallback_intent_name: nlu_fallback

policies:
- name: RulePolicy
8 changes: 2 additions & 6 deletions rasa/nlu/classifiers/fallback_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from rasa.nlu.constants import INTENT_RANKING_KEY, INTENT, INTENT_CONFIDENCE_KEY

THRESHOLD_KEY = "threshold"
FALLBACK_INTENT_NAME_KEY = "fallback_intent_name"


class FallbackClassifier(Component):
Expand All @@ -18,10 +17,7 @@ class FallbackClassifier(Component):
# ## Architecture of the used neural network
# If all intent confidence scores are beyond this threshold, set the current
# intent to `FALLBACK_INTENT_NAME`
THRESHOLD_KEY: DEFAULT_NLU_FALLBACK_THRESHOLD,
# The intent which is used to signal that the NLU confidence was below the
# threshold.
FALLBACK_INTENT_NAME_KEY: DEFAULT_NLU_FALLBACK_INTENT_NAME,
THRESHOLD_KEY: DEFAULT_NLU_FALLBACK_THRESHOLD
}

@classmethod
Expand Down Expand Up @@ -59,7 +55,7 @@ def _should_fallback(self, message: Message) -> bool:

def _fallback_intent(self) -> Dict[Text, Union[Text, float]]:
return {
"name": self.component_config[FALLBACK_INTENT_NAME_KEY],
"name": DEFAULT_NLU_FALLBACK_INTENT_NAME,
# TODO: Re-consider how we represent the confidence here
INTENT_CONFIDENCE_KEY: 1.0,
}
11 changes: 2 additions & 9 deletions tests/nlu/classifiers/test_fallback_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

from rasa.constants import DEFAULT_NLU_FALLBACK_INTENT_NAME
from rasa.core.constants import DEFAULT_NLU_FALLBACK_THRESHOLD
from rasa.nlu.classifiers.fallback_classifier import (
FallbackClassifier,
FALLBACK_INTENT_NAME_KEY,
THRESHOLD_KEY,
)
from rasa.nlu.classifiers.fallback_classifier import FallbackClassifier, THRESHOLD_KEY
from rasa.nlu.training_data import Message
from rasa.nlu.constants import INTENT_RANKING_KEY, INTENT, INTENT_CONFIDENCE_KEY

Expand Down Expand Up @@ -70,8 +66,5 @@ def test_not_predict_fallback_intent():

def test_default_threshold():
classifier = FallbackClassifier({})
assert (
classifier.component_config[FALLBACK_INTENT_NAME_KEY]
== DEFAULT_NLU_FALLBACK_INTENT_NAME
)

assert classifier.component_config[THRESHOLD_KEY] == DEFAULT_NLU_FALLBACK_THRESHOLD
2 changes: 1 addition & 1 deletion tests/nlu/test_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def pipelines_for_tests():
"MitieNLP", "JiebaTokenizer", "MitieFeaturizer", "MitieEntityExtractor"
),
),
("fallback", as_pipeline("FallbackClassifier")),
("fallback", as_pipeline("KeywordIntentClassifier", "FallbackClassifier")),
]


Expand Down

0 comments on commit f6e942c

Please sign in to comment.