Skip to content

Instantly share code, notes, and snippets.

@Horizon733
Created April 9, 2022 06:23
Show Gist options
  • Save Horizon733/bf3ea0816b88d1c34cbbdd8a273caa35 to your computer and use it in GitHub Desktop.
Save Horizon733/bf3ea0816b88d1c34cbbdd8a273caa35 to your computer and use it in GitHub Desktop.
Rasa Fallback tutorial
from rasa_sdk import Tracker, Action
from typing import Any, Text
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict
# DO NOT copy paste whole file
class ActionFallback(Action):
def name(self) -> Text:
return "action_fallback"
def run(
self,
dispatcher: "CollectingDispatcher",
tracker: Tracker,
domain: "DomainDict",
) -> List[Dict[Text, Any]]:
# add different functionalities like google search, wiki search, etc to provide more answer
latest_message = tracker.latest_message.get("text")
dispatcher.utter_message(text="sorry, can you please repharse your question and try again?")
return []
# This config.yml is based on 2.x you can still use below values of FallbackClassifier and RulePolicy in 3.x
# DO NOT copy paste this whole file
language: en
pipeline:
- name: WhitespaceTokenizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: char_wb
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
constrain_similarities: true
- name: FallbackClassifier
threshold: 0.3 # make sure to test the confidences of your intents and then specify this value
fallback_action: "action_fallback" # automatically gets triggered when fallback occurs
policies:
- name: MemoizationPolicy
- name: RulePolicy # added alternative to above fallback classifier, you can use any one or both.
core_fallback_threshold: 0.3 # make sure to test the confidences of your stories, rules and domain and then specify this value
core_fallback_action_name: action_fallback
enable_fallback_prediction: true
- name: TEDPolicy
max_history: 5
epochs: 100
constrain_similarities: true
version: "2.0" # make sure to change as per your rasa version
- rule: fallback
steps:
- intent: nlu_fallback
- action: action_fallback
@wholehope
Copy link

domain.yml also needs to be updated with the following lines.

actions:

  • action_fallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment