Skip to content

Commit

Permalink
Merge pull request #5184 from RasaHQ/bug-multi-intent
Browse files Browse the repository at this point in the history
Fix bug with multi-intents
  • Loading branch information
tabergma authored Feb 7, 2020
2 parents f95c5fa + 2c7a4a5 commit a3549d1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/5162.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix problem with multi-intents.
Training with multi-intents using the ``CountVectorsFeaturizer`` together with ``EmbeddingIntentClassifier`` is
working again.
71 changes: 71 additions & 0 deletions data/examples/rasa/demo-rasa-multi-intent.md
Original file line number Diff line number Diff line change
@@ -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]*
6 changes: 3 additions & 3 deletions data/examples/rasa/demo-rasa.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"common_examples": [
{
"text": "hey",
"intent": "greet",
"intent": "greet",
"entities": []
},
{
"text": "howdy",
"intent": "greet",
"intent": "greet",
"entities": []
},
{
"text": "hey there",
"intent": "greet",
"intent": "greet",
"entities": []
},
{
Expand Down
5 changes: 3 additions & 2 deletions rasa/nlu/classifiers/embedding_intent_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions tests/core/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
Expand Down
10 changes: 7 additions & 3 deletions tests/nlu/classifiers/test_embedding_intent_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -127,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,
)

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a3549d1

Please sign in to comment.