From ca0eddccdf464074e9827effd06146d806657078 Mon Sep 17 00:00:00 2001 From: Tanja Bergmann Date: Tue, 4 Feb 2020 11:05:32 +0100 Subject: [PATCH 1/5] update test --- data/examples/rasa/demo-rasa.json | 6 +++--- rasa/nlu/classifiers/embedding_intent_classifier.py | 5 +++-- tests/nlu/classifiers/test_embedding_intent_classifier.py | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/data/examples/rasa/demo-rasa.json b/data/examples/rasa/demo-rasa.json index 4b86741260d6..e0399480539e 100644 --- a/data/examples/rasa/demo-rasa.json +++ b/data/examples/rasa/demo-rasa.json @@ -23,17 +23,17 @@ "common_examples": [ { "text": "hey", - "intent": "greet", + "intent": "greet+welcome", "entities": [] }, { "text": "howdy", - "intent": "greet", + "intent": "greet+welcome", "entities": [] }, { "text": "hey there", - "intent": "greet", + "intent": "greet+welcome", "entities": [] }, { diff --git a/rasa/nlu/classifiers/embedding_intent_classifier.py b/rasa/nlu/classifiers/embedding_intent_classifier.py index 35b5e2febf8b..224a32288c12 100644 --- a/rasa/nlu/classifiers/embedding_intent_classifier.py +++ b/rasa/nlu/classifiers/embedding_intent_classifier.py @@ -543,7 +543,8 @@ def _combine_sparse_dense_features( dense_features.append(f) output = tf.concat(dense_features, axis=-1) * mask - output = tf.squeeze(output, axis=1) + # reduce dimensionality of output + output = tf.reduce_sum(output, axis=1) return output @@ -985,6 +986,6 @@ def load( else: raise_warning( f"Failed to load nlu model. " - f"Maybe the path '{os.path.abspath(model_dir)}' doesn't exist?", + f"Maybe the path '{os.path.abspath(model_dir)}' doesn't exist?" ) return cls(component_config=meta) diff --git a/tests/nlu/classifiers/test_embedding_intent_classifier.py b/tests/nlu/classifiers/test_embedding_intent_classifier.py index e45dbfed1f51..c224a0c6a17e 100644 --- a/tests/nlu/classifiers/test_embedding_intent_classifier.py +++ b/tests/nlu/classifiers/test_embedding_intent_classifier.py @@ -116,7 +116,11 @@ def test_check_labels_features_exist(messages, expected): async def test_train(component_builder, tmpdir): pipeline = [ - {"name": "ConveRTTokenizer"}, + { + "name": "ConveRTTokenizer", + "intent_tokenization_flag": True, + "intent_split_symbol": "+", + }, {"name": "CountVectorsFeaturizer"}, {"name": "ConveRTFeaturizer"}, {"name": "EmbeddingIntentClassifier"}, @@ -243,7 +247,7 @@ async def test_softmax_normalization( [({"loss_type": "margin", "random_seed": 42}, LABEL_RANKING_LENGTH)], ) async def test_margin_loss_is_not_normalized( - monkeypatch, component_builder, tmpdir, classifier_params, output_length, + monkeypatch, component_builder, tmpdir, classifier_params, output_length ): pipeline = as_pipeline( "WhitespaceTokenizer", "CountVectorsFeaturizer", "EmbeddingIntentClassifier" From 06a5e695678487959afbf6099806bebb5dd1fedc Mon Sep 17 00:00:00 2001 From: Tanja Bergmann Date: Tue, 4 Feb 2020 11:07:57 +0100 Subject: [PATCH 2/5] add changelog --- changelog/5162.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/5162.bugfix.rst diff --git a/changelog/5162.bugfix.rst b/changelog/5162.bugfix.rst new file mode 100644 index 000000000000..1834c31d6712 --- /dev/null +++ b/changelog/5162.bugfix.rst @@ -0,0 +1,3 @@ +Fix problem with multi-intents. +Training with multi-intents using the ``CountVectorsFeaturizer`` together with ``EmbeddingIntentClassifier`` is +working again. \ No newline at end of file From ab5986bed4d154db31baf0dce3aefffe201ad46c Mon Sep 17 00:00:00 2001 From: Tanja Bergmann Date: Tue, 4 Feb 2020 17:41:27 +0100 Subject: [PATCH 3/5] update test --- data/examples/rasa/demo-rasa-multi-intent.md | 71 +++++++++++++++++++ data/examples/rasa/demo-rasa.json | 6 +- .../test_embedding_intent_classifier.py | 2 +- 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 data/examples/rasa/demo-rasa-multi-intent.md diff --git a/data/examples/rasa/demo-rasa-multi-intent.md b/data/examples/rasa/demo-rasa-multi-intent.md new file mode 100644 index 000000000000..e479f1581ad2 --- /dev/null +++ b/data/examples/rasa/demo-rasa-multi-intent.md @@ -0,0 +1,71 @@ +## intent:affirm +- yes +- yep +- yeah +- indeed +- that's right +- ok +- great +- right, thank you +- correct +- great choice +- sounds really good + +## intent:goodbye +- bye +- goodbye +- good bye +- stop +- end +- farewell +- Bye bye +- have a good one + +## intent:greet +- hey +- howdy +- hey there +- hello +- hi +- good morning +- good evening +- dear sir + +## intent:chitchat/ask_name +- What's your name? +- What can I call you? + +## intent:chitchat/ask_weather +- How's the weather? +- Is it too hot outside? + +## intent:restaurant_search +- i'm looking for a place to eat +- I want to grab lunch +- I am searching for a dinner spot +- i'm looking for a place in the [north](location) of town +- show me [chinese](cuisine) restaurants +- show me [chines](cuisine:chinese) restaurants in the [north](location) +- show me a [mexican](cuisine) place in the [centre](location) +- i am looking for an [indian](cuisine) spot called olaolaolaolaolaola +- search for restaurants +- anywhere in the [west](location) +- anywhere near [18328](location) +- I am looking for [asian fusion](cuisine) food +- I am looking a restaurant in [29432](location) +- I am looking for [mexican indian fusion](cuisine) +- [central](location) [indian](cuisine) restaurant + +## synonym:chinese ++ Chines +* Chinese + +## synonym:vegetarian +- vegg +- veggie + +## regex:zipcode +- [0-9]{5} + +## regex:greet +- hey[^\s]* \ No newline at end of file diff --git a/data/examples/rasa/demo-rasa.json b/data/examples/rasa/demo-rasa.json index e0399480539e..ae644add933a 100644 --- a/data/examples/rasa/demo-rasa.json +++ b/data/examples/rasa/demo-rasa.json @@ -23,17 +23,17 @@ "common_examples": [ { "text": "hey", - "intent": "greet+welcome", + "intent": "greet", "entities": [] }, { "text": "howdy", - "intent": "greet+welcome", + "intent": "greet", "entities": [] }, { "text": "hey there", - "intent": "greet+welcome", + "intent": "greet", "entities": [] }, { diff --git a/tests/nlu/classifiers/test_embedding_intent_classifier.py b/tests/nlu/classifiers/test_embedding_intent_classifier.py index c224a0c6a17e..7be75689fc47 100644 --- a/tests/nlu/classifiers/test_embedding_intent_classifier.py +++ b/tests/nlu/classifiers/test_embedding_intent_classifier.py @@ -131,7 +131,7 @@ async def test_train(component_builder, tmpdir): (trained, _, persisted_path) = await train( _config, path=tmpdir.strpath, - data=DEFAULT_DATA_PATH, + data="data/examples/rasa/demo-rasa-multi-intent.md", component_builder=component_builder, ) From 7d21cd999c9b0187784ac3345f95e043dd2d762d Mon Sep 17 00:00:00 2001 From: Tanja Bergmann Date: Thu, 6 Feb 2020 10:48:13 +0000 Subject: [PATCH 4/5] update data example file --- data/examples/rasa/demo-rasa-multi-intent.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/examples/rasa/demo-rasa-multi-intent.md b/data/examples/rasa/demo-rasa-multi-intent.md index e479f1581ad2..d94a81455335 100644 --- a/data/examples/rasa/demo-rasa-multi-intent.md +++ b/data/examples/rasa/demo-rasa-multi-intent.md @@ -31,11 +31,11 @@ - good evening - dear sir -## intent:chitchat/ask_name +## intent:chitchat+ask_name - What's your name? - What can I call you? -## intent:chitchat/ask_weather +## intent:chitchat+ask_weather - How's the weather? - Is it too hot outside? From 2c7a4a5e319c69d380dd9d17f32f997bf230a76e Mon Sep 17 00:00:00 2001 From: Tanja Bergmann Date: Fri, 7 Feb 2020 09:50:09 +0000 Subject: [PATCH 5/5] fix test --- tests/core/test_data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/test_data.py b/tests/core/test_data.py index 0dd199107801..fad56015239a 100644 --- a/tests/core/test_data.py +++ b/tests/core/test_data.py @@ -148,6 +148,7 @@ def test_same_file_names_get_resolved(tmpdir): "data/examples/rasa/demo-rasa.json", "data/examples/rasa/demo-rasa.md", "data/examples/rasa/demo-rasa-responses.md", + "data/examples/rasa/demo-rasa-multi-intent.md", }, ), ("wit", {"data/examples/wit/demo-flights.json"}),