# Keyword based intent classification

**URL:** <https://forum.rasa.com/t/keyword-based-intent-classification/22027>\
**Category:** Rasa Open Source\
**Created:** [December 3, 2019, 1:40pm UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027 "2019-12-03T13:40:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryszardtuora](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@ryszardtuora](https://forum.rasa.com/u/ryszardtuora)\
**Post date:** [December 3, 2019, 1:40pm UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/1 "2019-12-03T13:40:30Z")

</div>

I have about 2000 examples for around 40 intents, and they are generally working fine. Additionally I want to add a separate intent (an intent for using a general search engine) which is triggered when a certain keyword appears. I.e. I want my chatbot to work as usual with its robust NLU, but to be overriden if it recognizes a certain fixed pattern, and recognize all that follows this keyword as entities. This pattern is:

- wyszukaj [keywords for the query](keywords)

I’m not sure how to proceed, because this is supposed to be a keyword, I cannot add much variation, and I am also not sure how to provide the examples of keywords, since they are supposed to be general (and thus can overlap with entities from other examples). Perhaps I should add a custom component?

---

<div class="post-metadata">

**Author:** ![imLew](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/imlew/32/3744_2.png) [@imLew](https://forum.rasa.com/u/imLew)\
**Post date:** [December 5, 2019, 1:20pm UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/2 "2019-12-05T13:20:44Z")

</div>

Is [KeywordClassifier](https://rasa.com/docs/rasa/nlu/components/#keywordintentclassifier) what you are looking for?

To use this add the `KeywordIntentClassifier` to your pipeline after your main classifier, all intent examples will then be treated as keywords for their corresponding intents and if they are found in a message will result in the message automatically being classified as having that intent.

---

<div class="post-metadata">

**Author:** ![ryszardtuora](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@ryszardtuora](https://forum.rasa.com/u/ryszardtuora)\
**Post date:** [December 6, 2019, 2:03pm UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/3 "2019-12-06T14:03:33Z")

</div>

Thanks. In the end I just wrote a custom component. Its quite a handy feature.

BTW, wouldn’t adding KeywordClassifier at the end of the pipeline be dangerous to more intricate nlu capabilities?

---

<div class="post-metadata">

**Author:** ![matias18233](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/matias18233/32/4382_2.png) [@matias18233](https://forum.rasa.com/u/matias18233)\
**Post date:** [December 6, 2019, 8:28pm UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/4 "2019-12-06T20:28:35Z")

</div>

Hi @ryszardtuora!

I think they can serve the “Forms” of Rasa.

[https://rasa.com/docs/rasa/core/forms/#id1](https://rasa.com/docs/rasa/core/forms/#id1)

---

<div class="post-metadata">

**Author:** ![imLew](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/imlew/32/3744_2.png) [@imLew](https://forum.rasa.com/u/imLew)\
**Post date:** [December 9, 2019, 11:03am UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/5 "2019-12-09T11:03:46Z")

</div>

Depends what you mean by dangerous. The KeywordIntentClassifier classifies a message if it found a keyword, putting it in the pipeline after another classifier would result in messages containing a keyword being classified based on keyword and the rest as normal.

Edit: Would you mind sharing your solution? I’d be interested to know what you did

---

<div class="post-metadata">

**Author:** ![ryszardtuora](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@ryszardtuora](https://forum.rasa.com/u/ryszardtuora)\
**Post date:** [December 10, 2019, 10:22am UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/6 "2019-12-10T10:22:58Z")

</div>

In the end this custom component works better, as it imposes more rigid constraints (working by a regex which requires a certain ordering of the words, and also does automatic extraction of the search phrase). By the feature being handy, I meant the possibility of adding custom components.

[**init**.py|attachment](https://forum.rasa.com/uploads/short-url/2pLA7CWdI66ViPUHopKRVYYaGBY.py) (3.0 KB)

---

<div class="post-metadata">

**Author:** ![zerotrope](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zerotrope/32/4937_2.png) [@zerotrope](https://forum.rasa.com/u/zerotrope)\
**Post date:** [January 8, 2020, 10:49am UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/7 "2020-01-08T10:49:35Z")

</div>

Thank you @ryszardtuora, this helped.

---

<div class="post-metadata">

**Author:** ![tomgun132](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/tomgun132/32/7462_2.png) [@tomgun132](https://forum.rasa.com/u/tomgun132)\
**Post date:** [April 3, 2020, 2:02am UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/8 "2020-04-03T02:02:29Z")

</div>

Hello @ryszardtuora, sorry to reactivate old topic, but I’m wondering since I probably need to do the same as you, having pattern classifier intent together with normal ML intent classification. How does the intent class priority go if you use pattern classification together machine learning classifier?

---

<div class="post-metadata">

**Author:** ![maxibove13](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/maxibove13/32/22299_2.png) [@maxibove13](https://forum.rasa.com/u/maxibove13)\
**Post date:** [January 19, 2023, 1:40pm UTC](https://forum.rasa.com/t/keyword-based-intent-classification/22027/9 "2023-01-19T13:40:41Z")

</div>

Thank you @ryszardtuora because this help me a lot too.

Regarding your question @tomgun132 I put this custom classifier in the pipeline (of the config.yaml) after the DietClassifier, like this:

pipeline:

- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer analyzer: char\_wb min\_ngram: 1 max\_ngram: 4
- name: DIETClassifier random\_seed: 42 epochs: 30 constrain\_similarities: true
- name: EntitySynonymMapper
- name: nlu.classifiers.\_custom\_keyword\_classifier.KeywordMatching
- name: FallbackClassifier threshold: 0.3 ambiguity\_threshold: 0.1

Where KeywordMatching is my custom pattern detector based on @ryszardtuora proposal.
