Regular expressions for intent classification


I am using Rasa 2.8.13.

I wish to use a Main Bot (port 5005) whose Action Server (port 5055) would act as a messaging router to different APIs, micro-services or other Rasa Sub bots.

I have the greet and goodbye intents defined and any other text should be treated as a fallback, triggering a custom action. I am not sure if I am doing it right - the fallback doesn’t work as expected. So, I use an intent to define the kind of phrases which should trigger the custom action.


version: "2.0"
language: en
  - name: WhitespaceTokenizer
  - name: LanguageModelFeaturizer
    model_name: "bert"
    model_weights: "rasa/LaBSE"
  - name: "RegexFeaturizer"
  - name: DIETClassifier
    epochs: 100
    learning_rate: 0.001
  - name: ResponseSelector
    epochs: 100
    learning_rate: 0.001
  - name: EntitySynonymMapper
  - name: FallbackClassifier
  - name: MemoizationPolicy
  - name: TEDPolicy
    epochs: 100
  - name: RulePolicy
  - name: FormPolicy
  - name: FallbackPolicy
    nlu_threshold: 0.8
    core_threshold: 0.8
    fallback_action_name: "action_forward_message"


  - rule: say hi
      - intent: greet
      - action: action_hello_world

  - rule: say bye
      - intent: goodbye
      - action: action_goodbye

  - rule: Forward any other question to Sub-Bot
      - intent: forward_message
      - action: action_forward_message


  - intent: greet
    examples: |
      - hey
      - hello
      - hi

  - intent: goodbye
    examples: |
      - bye
      - goodbye
      - cya

 - regex: fallback_phrases
    examples: |
      - ^/(?!hi|hello|hey|bye|goodbye|cya)([a-z]+)$

  - intent: forward_message
    examples: |
      - [How does](fallback_phrases)
      - [What are the](fallback_phrases)
      - [How did](fallback_phrases)
      - [What is the](fallback_phrases)

I do have the regex for extracting any text other than the greet and goodbye phrases.

I am unsure of how to use this regex in nlu.yml or if this feature is available at all in Rasa 2.8.13. The forward_message intent gets picked up in some cases and at other times, either of the greet or goodbye intent gets triggered.

So, I’m not sure if I am doing anything wrong in the regex. Any pointers will be of great help.


can you just mention this in config.yml

    nlu_threshold: 0.4
    core_threshold: 0.4
    fallback_action_name: 'action_default_fallback'

In domain.yml

      - text: I'm sorry, I didn't quite get you? Please try again..

Commented rule for action_forward_message

Try this generic usecase first, check its working on not.

Hi @nik202,

I made the suggested changes. When I type a sentence other than greet or goodbye phrases, the bot responds with utterance for the goodbye intent as defined in action_goodbye or does nothing.

@srikanthnm can you share the screenshot for some scenarios of conversation ? Its is generic fallback, you need to check you stories too.

Hi @nik202

I have only 3 intents in the Main Bot. Anything other than the greet or goodbye should undergo a fallback. I presently do not have any story besides the defined rules. I also tried including the FallbackClassifier and wrote a rule to handle the nlu_fallback intent. That also doesn’t work.

@srikanthnm interesting, normaly a default fallback should trigger the message which you mentioned in the domain.yml.


I just noticed that the default fallback works on longer sentences. For instance, “symptoms of covid” - triggers the goodbye intent. On the other hand, if I change it to “what are the symptoms of covid”, it falls back as it should. This was the reason I decided to use a separate intent and use a regex which captures every other text other than greet and goodbye examples. Was the above regex constructed and used correctly?


Well, I never encountered such a use case. I trained the bot with the nlu training examples, and anything outside the training example should go the default fallback or out of scope. I never tried the regex for such a use case.


Please see this video tutorial hope this will help you: RASA OPEN SOURCE 2.0 | FALLBACK ACTIONS - YouTube OR Fallback actions | Rasa - YouTube

is this issue solved?

@nik202 Hi - missed updating the thread. I used the fallback options under RulePolicy and this seems to work. I also used a rule to map an out_of_scope intent to the same action. Thanks for your help.

@srikanthnm can you please close this thread as a solution for other readers. Thanks and good luck!