From ee11a82cff4f4944b714cbf57b64a64fb6f07292 Mon Sep 17 00:00:00 2001 From: Daksh Date: Fri, 6 Nov 2020 11:41:40 +0100 Subject: [PATCH 1/3] fix --- changelog/7200.bugfix.md | 1 + rasa/nlu/selectors/response_selector.py | 6 ++++- tests/nlu/selectors/test_selectors.py | 30 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 changelog/7200.bugfix.md diff --git a/changelog/7200.bugfix.md b/changelog/7200.bugfix.md new file mode 100644 index 000000000000..57f7efdb641f --- /dev/null +++ b/changelog/7200.bugfix.md @@ -0,0 +1 @@ +Fix a bug because of which only one retrieval intent was present in `all_retrieval_intent` key of the output of `ResponseSelector` even if there where multiple retrieval intents present in the training data. \ No newline at end of file diff --git a/rasa/nlu/selectors/response_selector.py b/rasa/nlu/selectors/response_selector.py index c6789898e9ab..35491a6a3b2f 100644 --- a/rasa/nlu/selectors/response_selector.py +++ b/rasa/nlu/selectors/response_selector.py @@ -300,7 +300,12 @@ def preprocess_train_data(self, training_data: TrainingData) -> RasaModelData: """Prepares data for training. Performs sanity checks on training data, extracts encodings for labels. + + Args: + training_data: training data to preprocessed. """ + # Collect all retrieval intents present in the data before filtering + self.all_retrieval_intents = list(training_data.retrieval_intents) if self.retrieval_intent: training_data = training_data.filter_training_examples( @@ -321,7 +326,6 @@ def preprocess_train_data(self, training_data: TrainingData) -> RasaModelData: ) self.responses = training_data.responses - self.all_retrieval_intents = list(training_data.retrieval_intents) if not label_id_index_mapping: # no labels are present to train diff --git a/tests/nlu/selectors/test_selectors.py b/tests/nlu/selectors/test_selectors.py index 1203407686ae..406c4e5465a0 100644 --- a/tests/nlu/selectors/test_selectors.py +++ b/tests/nlu/selectors/test_selectors.py @@ -18,6 +18,8 @@ CHECKPOINT_MODEL, ) from rasa.nlu.selectors.response_selector import ResponseSelector +from rasa.shared.nlu.training_data.message import Message +from rasa.shared.nlu.training_data.training_data import TrainingData @pytest.mark.parametrize( @@ -95,6 +97,34 @@ def test_train_selector(pipeline, component_builder, tmpdir): assert rank.get("intent_response_key") is not None +def test_preprocess_selector_multiple_retrieval_intents(): + + # use some available data + training_data = rasa.shared.nlu.training_data.loading.load_data( + "data/examples/rasa/demo-rasa.md" + ) + training_data_responses = rasa.shared.nlu.training_data.loading.load_data( + "data/examples/rasa/demo-rasa-responses.md" + ) + training_data_extra_intent = TrainingData( + [ + Message.build( + text="Is it possible to detect the version?", intent="faq/q1" + ), + Message.build(text="How can I get a new virtual env", intent="faq/q2"), + ] + ) + training_data = training_data.merge(training_data_responses).merge( + training_data_extra_intent + ) + + response_selector = ResponseSelector() + + response_selector.preprocess_train_data(training_data) + + assert response_selector.all_retrieval_intents == ["chitchat", "faq"] + + @pytest.mark.parametrize( "use_text_as_label, label_values", [ From a2f0936d5c1e76ebe91a3329880d69b347e727ff Mon Sep 17 00:00:00 2001 From: Daksh Varshneya Date: Fri, 6 Nov 2020 11:47:40 +0100 Subject: [PATCH 2/3] Update changelog/7200.bugfix.md --- changelog/7200.bugfix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/7200.bugfix.md b/changelog/7200.bugfix.md index 57f7efdb641f..cd10e8aafc8c 100644 --- a/changelog/7200.bugfix.md +++ b/changelog/7200.bugfix.md @@ -1 +1 @@ -Fix a bug because of which only one retrieval intent was present in `all_retrieval_intent` key of the output of `ResponseSelector` even if there where multiple retrieval intents present in the training data. \ No newline at end of file +Fix a bug because of which only one retrieval intent was present in `all_retrieval_intent` key of the output of `ResponseSelector` even if there were multiple retrieval intents present in the training data. From 4f6cab0cdc80443e55518388efcf96bc77670872 Mon Sep 17 00:00:00 2001 From: Daksh Varshneya Date: Fri, 6 Nov 2020 12:19:19 +0100 Subject: [PATCH 3/3] Update tests/nlu/selectors/test_selectors.py --- tests/nlu/selectors/test_selectors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nlu/selectors/test_selectors.py b/tests/nlu/selectors/test_selectors.py index 406c4e5465a0..d25d28c0367e 100644 --- a/tests/nlu/selectors/test_selectors.py +++ b/tests/nlu/selectors/test_selectors.py @@ -122,7 +122,7 @@ def test_preprocess_selector_multiple_retrieval_intents(): response_selector.preprocess_train_data(training_data) - assert response_selector.all_retrieval_intents == ["chitchat", "faq"] + assert sorted(response_selector.all_retrieval_intents) == ["chitchat", "faq"] @pytest.mark.parametrize(