Skip to content

Commit ca8c013

Browse files
authored
Merge branch 'master' into issue4896
2 parents 8bd7e52 + 3d8f4b4 commit ca8c013

21 files changed

+475
-66
lines changed

changelog/4774.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Requests to ``/model/train`` do not longer block other requests to the Rasa server.

changelog/4902.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added a new configuration parameter, ``ranking_length`` to the ``EmbeddingPolicy``, ``EmbeddingIntentClassifier``,
2+
and ``ResponseSelector`` classes.

changelog/4902.improvement.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``EmbeddingPolicy``, ``EmbeddingIntentClassifier``, and ``ResponseSelector`` now by default normalize confidence
2+
levels over the top 10 results. See :ref:`migration-to-rasa-1.7` for more details.
File renamed without changes.

data/test/many_intents.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## intent:handleinsult
2+
- you are an idiot
3+
- You lack understanding.
4+
5+
## intent:thank
6+
- Thanks
7+
- Thank you
8+
9+
## intent:telljoke
10+
- Tell me something that you think will make me laugh.
11+
- Entertain me with a joke.
12+
13+
## intent:signup_newsletter
14+
- I wanna sign up for the newsletter.
15+
- I want to sign up for the newsletter.
16+
17+
## intent:react_positive
18+
- you are funny
19+
- thats funny
20+
21+
## intent:react_negative
22+
- i am sad
23+
- bad
24+
25+
## intent:how_to_get_started
26+
- how do I get started with rasa
27+
- how do I use rasa
28+
29+
## intent:technical_question
30+
- what is duckling
31+
- where to train intents in rasa?
32+
33+
## intent:source_code
34+
- how it works?
35+
- where can i find this code
36+
37+
## intent:pipeline_recommendation
38+
- what pipeline should I start with?
39+
- what is the right pipeline to choose?
40+
41+
## intent:rasa_cost
42+
- is rasa free
43+
- are you really free
44+
45+
## intent:nicetomeeyou
46+
- It’s great connecting with you.
47+
- Hi, nice to meet you!
48+
49+
## intent:nlu_generation_tool_recommendation
50+
- which tools can I use to create nlu data
51+
- how can I get nlu data
52+
53+
## intent:install_rasa
54+
- I want to install Rasa Stack
55+
- How to install Rasa?
56+
57+
## intent:ask_which_events
58+
- Which community events do you have
59+
- Where can I meet Rasas

docs/core/policies.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ It is recommended to use
271271
``inner`` for ``softmax``, ``cosine`` for ``margin``;
272272
- ``loss_type`` sets the type of the loss function,
273273
it should be either ``softmax`` or ``margin``;
274+
- ``ranking_length`` defines the number of top confidences over
275+
which to normalize ranking results if ``loss_type: "softmax"``;
276+
to turn off normalization set it to 0
274277
- ``mu_pos`` controls how similar the algorithm should try
275278
to make embedding vectors for correct intent labels,
276279
used only if ``loss_type`` is set to ``margin``;

docs/migration-guide.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ Migration Guide
1111
This page contains information about changes between major versions and
1212
how you can migrate from one version to another.
1313

14+
.. _migration-to-rasa-1.7:
15+
16+
Rasa 1.6 to Rasa 1.7
17+
--------------------
18+
19+
General
20+
~~~~~~~
21+
- By default, the ``EmbeddingIntentClassifier``, ``EmbeddingPolicy``, and ``ResponseSelector`` will
22+
now normalize the top 10 confidence results if the ``loss_type`` is ``"softmax"`` (which has been
23+
default since 1.3, see :ref:`migration-to-rasa-1.3`). This is configurable via the ``ranking_length``
24+
configuration parameter; to turn off normalization to match the previous behavior, set ``ranking_length: 0``.
25+
1426
.. _migration-to-rasa-1.3:
1527

1628
Rasa 1.2 to Rasa 1.3
@@ -82,7 +94,7 @@ General
8294
- If you were previously importing the ``Button`` or ``Element`` classes from
8395
``rasa_core.dispatcher``, these are now to be imported from ``rasa_sdk.utils``.
8496

85-
- Rasa NLU and Core previously used `separate configuration files
97+
- Rasa NLU and Core previously used `separate configuration files
8698
<https://legacy-docs.rasa.com/docs/nlu/0.15.1/migrations/?&_ga=2.218966814.608734414.1560704810-314462423.1543594887#id1>`_.
8799
These two files should be merged into a single file either named ``config.yml``, or passed via the ``--config`` parameter.
88100

docs/nlu/components.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ EmbeddingIntentClassifier
464464
``inner`` for ``softmax``, ``cosine`` for ``margin``;
465465
- ``loss_type`` sets the type of the loss function,
466466
it should be either ``softmax`` or ``margin``;
467+
- ``ranking_length`` defines the number of top confidences over
468+
which to normalize ranking results if ``loss_type: "softmax"``;
469+
to turn off normalization set it to 0
467470
- ``mu_pos`` controls how similar the algorithm should try
468471
to make embedding vectors for correct intent labels,
469472
used only if ``loss_type`` is set to ``margin``;

rasa/core/policies/embedding_policy.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class EmbeddingPolicy(Policy):
7474
"similarity_type": "auto", # string 'auto' or 'cosine' or 'inner'
7575
# the type of the loss function
7676
"loss_type": "softmax", # string 'softmax' or 'margin'
77+
# number of top actions to normalize scores for softmax loss_type
78+
# set to 0 to turn off normalization
79+
"ranking_length": 10,
7780
# how similar the algorithm should try
7881
# to make embedding vectors for correct labels
7982
"mu_pos": 0.8, # should be 0.0 < ... < 1.0 for 'cosine'
@@ -192,6 +195,7 @@ def _load_embedding_params(self, config: Dict[Text, Any]) -> None:
192195
self.similarity_type = "inner"
193196
elif self.loss_type == "margin":
194197
self.similarity_type = "cosine"
198+
self.ranking_length = config["ranking_length"]
195199

196200
self.mu_pos = config["mu_pos"]
197201
self.mu_neg = config["mu_neg"]
@@ -567,8 +571,12 @@ def predict_action_probabilities(
567571
tf_feed_dict = self.tf_feed_dict_for_prediction(tracker, domain)
568572

569573
confidence = self.session.run(self.pred_confidence, feed_dict=tf_feed_dict)
574+
confidence = confidence[0, -1, :]
570575

571-
return confidence[0, -1, :].tolist()
576+
if self.loss_type == "softmax" and self.ranking_length > 0:
577+
confidence = train_utils.normalize(confidence, self.ranking_length)
578+
579+
return confidence.tolist()
572580

573581
def persist(self, path: Text) -> None:
574582
"""Persists the policy to a storage."""
@@ -583,7 +591,11 @@ def persist(self, path: Text) -> None:
583591

584592
self.featurizer.persist(path)
585593

586-
meta = {"priority": self.priority}
594+
meta = {
595+
"priority": self.priority,
596+
"loss_type": self.loss_type,
597+
"ranking_length": self.ranking_length,
598+
}
587599

588600
meta_file = os.path.join(path, "embedding_policy.json")
589601
rasa.utils.io.dump_obj_as_json_to_file(meta_file, meta)
@@ -665,7 +677,7 @@ def load(cls, path: Text) -> "EmbeddingPolicy":
665677

666678
return cls(
667679
featurizer=featurizer,
668-
priority=meta["priority"],
680+
priority=meta.pop("priority"),
669681
graph=graph,
670682
session=session,
671683
user_placeholder=a_in,
@@ -677,4 +689,5 @@ def load(cls, path: Text) -> "EmbeddingPolicy":
677689
bot_embed=bot_embed,
678690
all_bot_embed=all_bot_embed,
679691
attention_weights=attention_weights,
692+
**meta,
680693
)

rasa/core/processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def _warn_about_new_slots(self, tracker, action_name, events) -> None:
631631
warnings.warn(
632632
f"Action '{action_name}' set a slot type '{e.key}' that "
633633
f"it never set during the training. This "
634-
f"can throw of the prediction. Make sure to "
634+
f"can throw off the prediction. Make sure to "
635635
f"include training examples in your stories "
636636
f"for the different types of slots this "
637637
f"action can return. Remember: you need to "

0 commit comments

Comments
 (0)