Monday, October 3, 2022

The RulePolicy of Rasa (Oct 2022)

You would come across the RulePolicy configuration of Rasa if you ever land up on this Rasa documentation page: https://rasa.com/docs/rasa/policies/

The page for Forms says:

Usage

To use forms with Rasa Open Source you need to make sure that the Rule Policy is added to your policy configuration. For example:
policies: - name: RulePolicy To find out the lack of proper logging and getting to understand the erroneous situation that this policy can land you in, do the following. Do a "$ rasa init" to initialize a project. Add the following code to the "config.yml": policies: - name: RulePolicy Next, do: $ rasa train $ rasa interactive

Next we are going to show chat logs 'with the RulePolicy configuration' and 'without the RulePolicy configuration'

Without the RulePolicy configuration (this is the default setting you get from '$ rasa init')

(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/ws/jupyter/rasa/project2$ rasa interactive 2022-10-04 00:09:02 INFO numexpr.utils - NumExpr defaulting to 4 threads. The configuration for policies and pipeline was chosen automatically. It was written into the config file at 'config.yml'. /home/ashish/.local/lib/python3.8/site-packages/matplotlib/__init__.py:169: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. if LooseVersion(module.__version__) < minver: /home/ashish/anaconda3/envs/rasa_py38/lib/python3.8/site-packages/setuptools/_distutils/version.py:346: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. other = LooseVersion(other) /home/ashish/.local/lib/python3.8/site-packages/tensorflow_addons/utils/ensure_tf_install.py:47: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. min_version = LooseVersion(INCLUSIVE_MIN_TF_VERSION) 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'CountVectorsFeaturizer' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'CountVectorsFeaturizer' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'DIETClassifier' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'EntitySynonymMapper' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'LexicalSyntacticFeaturizer' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'MemoizationPolicy' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'RegexFeaturizer' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'ResponseSelector' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'RulePolicy' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'TEDPolicy' from cache. 2022-10-04 00:09:09 INFO rasa.engine.training.hooks - Restored component 'UnexpecTEDIntentPolicy' from cache. Your Rasa model is trained and saved at 'models/20221004-000906-cream-hoops.tar.gz'. /home/ashish/.local/lib/python3.8/site-packages/colorclass/codes.py:5: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working from collections import Mapping /home/ashish/.local/lib/python3.8/site-packages/sanic_cors/extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. SANIC_VERSION = LooseVersion(sanic_version) 2022-10-04 00:09:24 INFO rasa.core.processor - Loading model models/20221004-000906-cream-hoops.tar.gz... 2022-10-04 00:09:51 WARNING rasa.shared.utils.common - The UnexpecTED Intent Policy is currently experimental and might change or be removed in the future 🔬 Please share your feedback on it in the forum (https://forum.rasa.com) to help us make this feature ready for production. 2022-10-04 00:10:04 INFO root - Rasa server is up and running. Processed story blocks: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 1446.98it/s, # trackers=1] Processed rules: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 2095.58it/s, # trackers=1] Bot loaded. Visualisation at http://localhost:5006/visualization.html . Type a message and press enter (press 'Ctrl-c' to exit). ? Your input -> hi ? Your NLU model classified 'hi' with intent 'greet' and there are no entities, is this correct? Yes ------ Chat History # Bot You ──────────────────────────────────────────── 1 action_listen ──────────────────────────────────────────── 2 hi intent: greet 1.00 Current slots: session_started_metadata: None ------ ? The bot wants to run 'utter_greet', correct? Yes /home/ashish/.local/lib/python3.8/site-packages/rasa/server.py:860: FutureWarning: The "POST /conversations/<conversation_id>/execute" endpoint is deprecated. Inserting actions to the tracker externally should be avoided. Actions should be predicted by the policies only. rasa.shared.utils.io.raise_warning( ------ Chat History # Bot You ──────────────────────────────────────────────── 1 action_listen ──────────────────────────────────────────────── 2 hi intent: greet 1.00 ──────────────────────────────────────────────── 3 utter_greet 1.00 Hey! How are you? ------ Current slots: session_started_metadata: None ? The bot wants to run 'action_listen', correct? Yes ? Your input -> great ? Your NLU model classified 'great' with intent 'mood_great' and there are no entities, is this correct? Yes ------ Chat History ------ # Bot You ────────────────────────────────────────────────────── 1 action_listen ────────────────────────────────────────────────────── 2 hi intent: greet 1.00 ────────────────────────────────────────────────────── 3 utter_greet 1.00 Hey! How are you? action_listen 1.00 ────────────────────────────────────────────────────── 4 great intent: mood_great 1.00 Current slots: session_started_metadata: None ? The bot wants to run 'utter_happy', correct? Yes ------ Chat History # Bot You ────────────────────────────────────────────────────── 1 action_listen ────────────────────────────────────────────────────── 2 hi intent: greet 1.00 ────────────────────────────────────────────────────── 3 utter_greet 1.00 Hey! How are you? action_listen 1.00 ────────────────────────────────────────────────────── 4 great intent: mood_great 1.00 ────────────────────────────────────────────────────── 5 utter_happy 1.00 Great, carry on! ------ Current slots: session_started_metadata: None ? The bot wants to run 'action_listen', correct? Yes ? Your input ->

Logs with the RulePolicy configuration

Erroneous Logs (Part 1)

(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/ws/jupyter/rasa/project2$ rasa interactive 2022-10-03 23:35:00 INFO numexpr.utils - NumExpr defaulting to 4 threads. The configuration for pipeline was chosen automatically. It was written into the config file at 'config.yml'. /home/ashish/.local/lib/python3.8/site-packages/matplotlib/__init__.py:169: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. if LooseVersion(module.__version__) < minver: /home/ashish/anaconda3/envs/rasa_py38/lib/python3.8/site-packages/setuptools/_distutils/version.py:346: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. other = LooseVersion(other) /home/ashish/.local/lib/python3.8/site-packages/tensorflow_addons/utils/ensure_tf_install.py:47: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. min_version = LooseVersion(INCLUSIVE_MIN_TF_VERSION) 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'CountVectorsFeaturizer' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'CountVectorsFeaturizer' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'DIETClassifier' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'EntitySynonymMapper' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'LexicalSyntacticFeaturizer' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'RegexFeaturizer' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'ResponseSelector' from cache. 2022-10-03 23:35:08 INFO rasa.engine.training.hooks - Restored component 'RulePolicy' from cache. Your Rasa model is trained and saved at 'models/20221003-233504-energetic-palace.tar.gz'. /home/ashish/.local/lib/python3.8/site-packages/colorclass/codes.py:5: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working from collections import Mapping /home/ashish/.local/lib/python3.8/site-packages/sanic_cors/extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. SANIC_VERSION = LooseVersion(sanic_version) 2022-10-03 23:35:20 INFO rasa.core.processor - Loading model models/20221003-233504-energetic-palace.tar.gz... 2022-10-03 23:35:33 INFO root - Rasa server is up and running. Processed story blocks: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 1607.63it/s, # trackers=1] Processed rules: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 2113.53it/s, # trackers=1] Bot loaded. Visualisation at http://localhost:5006/visualization.html . Type a message and press enter (press 'Ctrl-c' to exit). ? Your input -> hi ? Your NLU model classified 'hi' with intent 'greet' and there are no entities, is this correct? Yes ------ Chat History # Bot You ──────────────────────────────────────────── 1 action_listen ──────────────────────────────────────────── 2 hi intent: greet 1.00 ------ Current slots: session_started_metadata: None ? The bot wants to run 'action_default_fallback', correct? (Y/n) Cancelled by user ? Do you want to stop? (Use arrow keys) Cancelled by user ? Export stories to (if file exists, this will append the stories) data/stories.yml Cancelled by user 2022-10-03 23:36:09 INFO rasa.core.training.interactive - Killing Sanic server now.

Erroneous Logs (Part 2)

? Your input -> hi ? Your NLU model classified 'hi' with intent 'greet' and there are no entities, is this correct? Yes ------ Chat History # Bot You ──────────────────────────────────────────── 1 action_listen ──────────────────────────────────────────── 2 hi intent: greet 1.00 Current slots: session_started_metadata: None ------ ? The bot wants to run 'action_default_fallback', correct? Yes /home/ashish/.local/lib/python3.8/site-packages/rasa/server.py:860: FutureWarning: The "POST /conversations/<conversation_id>/execute" endpoint is deprecated. Inserting actions to the tracker externally should be avoided. Actions should be predicted by the policies only. rasa.shared.utils.io.raise_warning( ------ Chat History # Bot You ──────────────────────────────────── 1 action_listen ------ Current slots: session_started_metadata: None ? The bot wants to run 'action_default_fallback', correct? Yes ------ Chat History ------ # Bot You ──────────────────────────────────── 1 action_listen Current slots: session_started_metadata: None ? The bot wants to run 'action_default_fallback', correct? Yes ------

What is this "action_default_fallback"?

The answer comes from Rasa Documentation:

Policy Priority

In the case that two policies predict with equal confidence (for example, the Memoization and Rule Policies might both predict with confidence 1), the priority of the policies is considered. Rasa Open Source policies have default priorities that are set to ensure the expected outcome in the case of a tie. They look like this, where higher numbers have higher priority: 6 - RulePolicy 3 - MemoizationPolicy or AugmentedMemoizationPolicy 2 - UnexpecTEDIntentPolicy 1 - TEDPolicy

Rule Policy

The RulePolicy is a policy that handles conversation parts that follow a fixed behavior (e.g. business logic). It makes predictions based on any rules you have in your training data. See the Rules documentation for further information on how to define rules. The RulePolicy has the following configuration options: File: config.yml policies: - name: "RulePolicy" core_fallback_threshold: 0.3 core_fallback_action_name: action_default_fallback enable_fallback_prediction: true restrict_rules: true check_for_contradictions: true The values shown above are the default settings. Ref: https://rasa.com/docs/rasa/policies
Tags: Technology,Natural Language Processing,Rasa,

No comments:

Post a Comment